教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 资格考试 >

JAVE基础实验 Experiment3

来源:网络收集 时间:2026-02-24
导读: Experimental Class 3Java, Ludong University Exercise 1Make an executable class called Exercise1, with main method write necessary code to display the following:How Day Day Day Day Day many day’s temperatures? 1’s temperature: 78 2’s tem

Experimental Class 3Java, Ludong University

Exercise 1Make an executable class called Exercise1, with main method write necessary code to display the following:How Day Day Day Day Day many day’s temperatures? 1’s temperature: 78 2’s temperature: 81 3’s temperature: 75 4’s temperature: 79 5’s temperature: 71 76.8 81 71 5

User input Scanner(System.in)

Average temperature: Maximum temperature: Minimum temperature:

Use: Scanner(System.in)& for loop Use an array to store the values

Exercise 2Make a class called Student, with the following elds& methods: age of type integer, private name of type String, private id of type integer, private grade of type double, private one constructor that sets age, name, id, and grade setters and getters for all the private elds Make an executable class called Exercise2, with main method De ne an array of three students:“Zhang”, 21 years old, id 13579, grade of 68.5“Wang”, 19 years old, id 13784, grade of 89.2“Chang”, 20 years old, id 24680, grade of 76.7 display which student is oldest display which student is best in school

Exercise 3 (page 1)Create necessary classes to describe this inheritance“Dog”,“Cat” (to be set by children classes) class Animal int age String type Animal() Animal(int age) void setAge(int age) int getAge() int compareTo(Animal o) void talk() class Dog extends Animal Dog() Dog(int age) void talk() class Cat extends Animal Cat() Cat(int age) void talk() Dog says“WUF-WUF” Cat says“MIEW-MIEW”

use“super”

use“super”

Display the type and age of animal

Exercise 3 (page 2)Make an executable class called Exercise3, with main method create 3 objects of type Animal called animal1, animal2, animal3 assign animal1 type Dog, age 3; increment age using set/get; ask to talk assign animal2 type Cat, age 4; decrement age using set/get; ask to talk ask animal3 to talk display true/false for: 1) animal1 of type Animal; 2) animal2 of type Dog display who is oldest, animal1 or animal2

Dog at age 4 says... WUF-WUF! Cat at age 3 says... MIEW-MIEW! unknown type at age 0 says... animal1 of same type as Animal: true animal2 of same type as Dog: false Comparing animal1 and animal2: 1

The End See you next time!见

…… 此处隐藏:172字,全部文档内容请下载后查看。喜欢就下载吧 ……
JAVE基础实验 Experiment3.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/89915.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)