Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) The class diagram with four classes Mammal, Human, Student and Doctor is given. The Mammal class is given as well. Write down the remaining

1) The class diagram with four classes Mammal, Human, Student and Doctor is given. The Mammal class is given as well. Write down the remaining classes as described in the class diagram. The fields and methods for each class is given below.

Human: Fields: height (double)

Methods: getHeight : returns height

Student: Fields: major (String)

gpa (double)

creditHours (int) Methods:

getMajor: returns major getGpa: returns gpa

getYear: returns freshman, sophomore, junior or senior as determined by earned credit hours:

  • Freshman: Less than 32 credit hours

  • Sophomore: At least 32 credit hours but less than 64 credit hours

  • Junior: At least credit hours SH but less than 96 credit hours

  • Senior: At least 96 credit hours

Doctor: Fields: years (int)

Speciality (String) Methods: getYears: returns years

getSpecialty: returns speciality getSalary: calculates salary. The base salary is 40,000 for the 1st year and for each additional year gets 5000 more. So, in second year the doctor gets 45,000, in third year he gets 50,000 and so on.

//In Mammal.java class Mammal {

private int age; private double weight;

Mammal(float weight, int age) {

this.age = age;

this.weight = weight; }

public float getWeight() {

return weight; }

public int getAge() {

return age; }

}

  • Write another client class.

  • Create an object of class Student called alex whose major is CS, gpa is 3.4, credit hours = 54,

    height is 170 cm, weight is 150 pounds and age is 18.

  • Create an object of class Doctor called jack whose specialty is Dermatology, years = 4, height

    is 173 cm, weight is 179 pounds and age is 40.

  • Print out the students major, gpa, year and age.

  • Print out the doctors specialty, height, weight and salary.

  • What will be the output of the following statement? (you can write the answers in

    notepad/word and submit it to the lab instructor) Mammal mam1=jack;

    System.out.println(Mam1.getSalary());

  • What will be the output of the following statement?

    Human hum1=alex;

    System.out.println (Hum1.getHeight());

  • What will be the output of the following statement;

    Mammal mam1=jack; System.out.println (Mam1.getWeight());

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

d. How were you expected to contribute to family life?

Answered: 1 week ago