Question

In: Computer Science

I need to see a working example using inheritance and the classes (below) The person class...

I need to see a working example using inheritance and the classes (below)

  • The person class has
    • first name
    • last name
    • age
    • hometown
    • a method called getInfo() that returns all attributes from person as a String
  • The student class is a person with
    • an id and
    • a major and
    • a GPA
    • student has to call super passing the parameters for the super class constructor
    • a method called getInfo() that returns all attributes from student as a String
      • this methods has to override the method getInfo() in person
  • The student-athlete class is a student with
    • a sports (football, or track, or soccer, volleyball, etc.)and
    • a ranking (a random number between 0 and 100)
    • student-athlete has to call super passing the parameters for the super class constructor
    • a method called getInfo() that returns all attributes from student-athlete as a String
    • this methods has to override the method getInfo() in student

Create an application (app) that:

  • Creates one student-athlete object.
  • Displays all information about the student-athlete object
  • Does it in the most efficient way possible (avoids unnecessary duplication of attributes and methods)
  • Uses the classes
    • app
    • person
    • student inheriting from person
    • student-athlete inheriting from student

Solutions

Expert Solution

This code is written in java language.

Please find it.

class Person

{

String firstname;

String lastname;

byte age;

String hometown;

Person(firstname,lastname,age,hometown)

{

this.firstname=firstname;

this.lastname=lastname;

this.age=age;

this.hometown=hometown;

}

String getInfo()

{

return this.firstname+this.lastname+this.age+this.hometown;

}

}

class Student extends Person

{

byte id;

String major;

float GPA;

Student(firstname,lastname,age,hometown,id,major,GPA)

{

super(firstname,lastname,age,hometown);

this.id=id;

this.major=major;

this.GPA=GPA;

}

String getInfo()

{

return super.getInfo()+this.id+this.major+this.GPA;

}

}

class Student_athlete extends Student

{

String sport;

byte rank;

Student_athlete(firstname,lastname,age,hometown,id,major,GPA,sport,rank)

{

super(firstname,lastname,age,hometown,id,major,GPA);

this.sport=sport;

this.rank=rank;

}

String getInfo()

{

return super.getInfo()+ this.sport+this.rank;

}

}

class App

{

public static void main(String [] args)

{

Student_athlete student_athlete = new Student_athlete("robin","marshal",25,"Maryland",23,"CS",9.0,"football",23);

System.out.println(student_athlete.getInfo());

}

}


Related Solutions

Need to design a program in C++ that plays hangman using classes (polymorphism and inheritance) Below...
Need to design a program in C++ that plays hangman using classes (polymorphism and inheritance) Below is the code only need to add the classes and make the program run with at least one class of Polymorphism and Inheritance. CODE: #include <iostream> #include <cstdlib> #include<ctime> #include <string> using namespace std; int NUM_TRY=8; //A classic Hangman game has 8 tries. You can change if you want. int checkGuess (char, string, string&); //function to check the guessed letter void main_menu(); string message...
Using Classes This problem relates to the pre-loaded class Person. Using the Person class, write a...
Using Classes This problem relates to the pre-loaded class Person. Using the Person class, write a function print_friend_info(person) which accepts a single argument, of type Person, and: prints out their name prints out their age if the person has any friends, prints 'Friends with {name}' Write a function create_fry() which returns a Person instance representing Fry. Fry is 25 and his full name is 'Philip J. Fry' Write a function make_friends(person_one, person_two) which sets each argument as the friend of...
#Below is a class representing a person. You'll see the #Person class has three instance variables:...
#Below is a class representing a person. You'll see the #Person class has three instance variables: name, age, #and GTID. The constructor currently sets these values #via a calls to the setters. # #Create a new function called same_person. same_person #should take two instances of Person as arguments, and #returns True if they are the same Person, False otherwise. #Two instances of Person are considered to be the same if #and only if they have the same GTID. It does...
Developing a set of classes demonstrating inheritance - in class work
Developing a set of classes demonstrating inheritance - in class work
write Java program has two classes ,( using Inheritance ) first class set ( id ,...
write Java program has two classes ,( using Inheritance ) first class set ( id , name ) and method output second class ( id , name , Mark 1 , Mark 2 , Mark 3 ) method total , average , grade , results ( if the student pass or not ) , and output method
The purpose of this lab is to practice using inheritance and polymorphism. We need a set of classes for an Insurance company.
The purpose of this lab is to practice using inheritance and polymorphism.    We need a set of classes for an Insurance company.   Insurance companies offer many different types of policies: car, homeowners, flood, earthquake, health, etc.    Insurance policies have a lot of data and behavior in common.   But they also have differences.   You want to build each insurance policy class so that you can reuse as much code as possible.   Avoid duplicating code.   You’ll save time, have less code to...
explain the principle of the inheritance give an example( CS related) of class inheritance
explain the principle of the inheritance give an example( CS related) of class inheritance
This assignment tests your understanding of abstract classes, inheritance, and requirements modeling using class-based methods. The...
This assignment tests your understanding of abstract classes, inheritance, and requirements modeling using class-based methods. The assignment scenario involves an abstract vehicle class and concrete subclasses Jeep and Ford. The vehicle class has the following variables (manufacturer, language), and methods (getManufacturer( ), and getLanguage( )). The manufacturer builds a specific vehicle (a Jeep and a Ford). The manufacturer will notify the consumer class that a Jeep and a Ford are available for purchase. The consumer class purchases the Jeep. Your...
Chapter 9 Programming Project (Inheritance, Abstract Class/Methods, Overriding Methods) -For all classes, you need to provide...
Chapter 9 Programming Project (Inheritance, Abstract Class/Methods, Overriding Methods) -For all classes, you need to provide the accessor and mutator methods for all instance variables, and provide/override the toString methods. -Create a Customer class that has the attributes of name and age. Provide a method named importanceLevel. Based on the requirements below, I would make this method abstract. -Extend Customer to two subclasses: FlightCustomer, and RetailCustomer -FlightCustomer attributes: ticketPrice, seatNumber (The seat number should be a randomly generated number between...
Give example of company using ABC costing I need an example
Give example of company using ABC costing I need an example
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT