JAVE基础实验 Experiment3

时间:2025-05-12

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!见

…… 此处隐藏:171字,全部文档内容请下载后查看。喜欢就下载吧 ……
JAVE基础实验 Experiment3.doc 将本文的Word文档下载到电脑

    精彩图片

    热门精选

    大家正在看

    × 游客快捷下载通道(下载后可以自由复制和排版)

    限时特价:7 元/份 原价:20元

    支付方式:

    开通VIP包月会员 特价:29元/月

    注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
    微信:fanwen365 QQ:370150219