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

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...
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
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...
Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files....
Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files. Use include guard in class header files to avoid multiple inclusion of a header. Tasks: In our lecture, we wrote a program that defines and implements a class Rectangle. The source code can be found on Blackboard > Course Content > Classes and Objects > Demo Program 2: class Rectangle in three files. In this lab, we will use class inheritance to write a...
Give example of company using ABC costing I need an example
Give example of company using ABC costing I need an example
I am working on an assignment using SQL Server Management and I need to print an...
I am working on an assignment using SQL Server Management and I need to print an ERD to a single page as a PDF file. I am not sure how to do this especially because the diagram is rather large... I am using SQL Server Management Studio I have created an Entity relationship diagram for AdventureWorks that includes all product tables. There are many tables.How do I print it to a single page?
i NEED TO FIND AN ARTICLE ABOUT USING OF ENERGY IN SUCH AS WORKING, EXERCISE, OR...
i NEED TO FIND AN ARTICLE ABOUT USING OF ENERGY IN SUCH AS WORKING, EXERCISE, OR BEING SEDENTRY THEN SUMMERIZE IT please help me to find an article and summarize it t( the using of energy such as working, being sedentary etc) Please find an article in the news related specifically to the use of energy (working, exercise, being sedentary, etc.) and summarize it in your own words for the class! Include the name of the article and the source...
Describe the major social classes in Canada: upper class, middle class, working-class, and lower class. Consider...
Describe the major social classes in Canada: upper class, middle class, working-class, and lower class. Consider the size of each class, as well as the income levels, typical schooling, and type of work that characterize people at each level.
**Only need the bold answered Implement the Athlete, Swimmer, Runner, and AthleteRoster classes below. Each class...
**Only need the bold answered Implement the Athlete, Swimmer, Runner, and AthleteRoster classes below. Each class must be in separate file. Draw an UML diagram with the inheritance relationship of the classes. 1. The Athlete class a. All class variables of the Athlete class must be private. b.is a class with a single constructor: Athlete(String lName, String fName, int birthYear, int birthMonth, int birthDay, char gender). All arguments of the constructor should be stored as class variables. There should only...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT