Question

**Using NetBeans**

Lesson

Using inheritance to reuse classes.

Deliverables

  • person.java
  • student.java
  • studentAthlete.java
  • app.java

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

person First name Last name аpp Age Hometown Creates 1 student-athlete object getlnfo() 1-Displays the complete information a

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class person
{
   private String firstName,lastName,hometown;
   private int age;
  
   public person(String firstName,String lastName,int age,String hometown)
   {
       this.firstName = firstName;
       this.lastName = lastName;
       this.age = age;
       this.hometown = hometown;
   }
   public String getInfo()
   {
       return "Name : "+firstName+" "+lastName+" Age : "+age +" Hometown : "+hometown;
   }
}

class student extends person
{
   private int id;
   private String major;
   private double gpa;
  
   public student(String firstName,String lastName,int age,String hometown,int id,String major,double gpa)
   {
       super(firstName,lastName,age,hometown);// call to base class person constructor
       this.id = id;
       this.major = major;
       this.gpa = gpa;
   }
   public String getInfo()
   {
       return super.getInfo() +" ID : "+id +" Major : "+major +" GPA : "+gpa;
   }
}

class studentAthlete extends student
{
   private String sports;
   private int ranking;
  
   public studentAthlete(String firstName,String lastName,int age,String hometown,int id,String major,double gpa,String sports,int ranking)
   {
       super(firstName,lastName,age,hometown,id,major,gpa);// call to base class student constructor
       this.sports = sports;
       this.ranking = ranking;
   }
   public String getInfo()
   {
       return super.getInfo() +" Sports : "+sports +" Ranking : "+ranking;
   }
}

class app
{
   public static void main (String[] args)
   {
       studentAthlete sa = new studentAthlete("Jim","Haward",21,"New Jersey",1006,"Finance Accounting",3.75,"football",25);
      
       System.out.println(sa.getInfo());
   }
}

Output:

Name : Jim Haward Age : 21 Hometown : New Jersey ID : 1006 Major : Finance Accounting GPA : 3.75 Sports : football  Ranking : 25

Do ask if any doubt. Please upvote.

Add a comment
Know the answer?
Add Answer to:
**Using NetBeans** Lesson Using inheritance to reuse classes. Deliverables person.java student.java studentAthlete.java app.java Using inheritance and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How do I start this Java: Inheritance problem? • person.java • student.java • studentAthlete.java • app.java...

    How do I start this Java: Inheritance problem? • person.java • student.java • studentAthlete.java • app.java • Students should apply consistent indenting in all submissions. This can be done via the NetBeans Source menu. Contents person First name Last name app Creates 1 student-athlete object Hometown Retinfo) 1-Displays the complete information about the student-athlete object student New attributes Maior attributes getinfo) method from the superlas person Student-athlete student's rankine Overrides the method from the superclass student Video from Professor Fisher...

  • Deliverable A zipped NetBeans project with 2 classes app ZipCode Address Classes Suggestion: Use Netbeans to...

    Deliverable A zipped NetBeans project with 2 classes app ZipCode Address Classes Suggestion: Use Netbeans to copy your last lab (Lab 03) to a new project called Lab04. Close Lab03. Work on the new Lab04 project then. The Address Class Attributes int number String name String type ZipCode zip String state Constructors one constructor with no input parameters since it doesn't receive any input values, you need to use the default values below: number - 0 name - "N/A" type...

  • I need help for part B and C 1) Create a new project in NetBeans called...

    I need help for part B and C 1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...

  • QUESTION 5 (15 Marks) Inheritance and Polymorphism Design a Ship class that has the following members:...

    QUESTION 5 (15 Marks) Inheritance and Polymorphism Design a Ship class that has the following members: • A private String data field named name for the name of the ship. • A private String data field named yearBuilt for the year that the ship was built. • A constructor that creates a ship with the specified name and the specified year that the ship was built. • Appropriate getter and setter methods. A toString method that overrides the toString method...

  • Deliverables app.java, myJFrame.java, myJPanel.java and student.java as requested below. (Use the student.java class that you already...

    Deliverables app.java, myJFrame.java, myJPanel.java and student.java as requested below. (Use the student.java class that you already have from previous labs) Contents Based on the graphics you learned this week Create an instance (an object, i.e., st1) of student in myJPanel Display his/her basic information Display for 10 times what he/she is up to (using the method whatIsUp() that your student class already has) -------------------------------------------------------------------------------------------------- \\app.java public class app { public static void main(String args[]) { myJFrame mjf = new myJFrame();...

  • In Java Which of the following statements declares Salaried as a subclass of payType? Public class...

    In Java Which of the following statements declares Salaried as a subclass of payType? Public class Salaried implements PayType Public class Salaried derivedFrom(payType) Public class PayType derives Salaried Public class Salaried extends PayType If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method. False True When a subclass overloads a superclass method………. Only the subclass method may be called with a subclass object Only the superclass method...

  • The method m() of class B overrides the m() method of class A, true or false?...

    The method m() of class B overrides the m() method of class A, true or false? class A int i; public void maint i) { this.is } } class B extends A{ public void m(Strings) { 1 Select one: True False For the following code, which statement is correct? public class Test { public static void main(String[] args) { Object al = new AC: Object a2 = new Object(); System.out.println(al); System.out.println(a): } } class A intx @Override public String toString()...

  • PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is...

    PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** *           Program:          PRG/421 Week 1 Analyze Assignment *           Purpose:         Analyze the coding for...

  • JAVA - Abstraction and Encapsulation are one pillar of OOP (Object Oriented Programming). Another is inheritance...

    JAVA - Abstraction and Encapsulation are one pillar of OOP (Object Oriented Programming). Another is inheritance and polymorphism. In this assignment we will use inheritance and polymorphism to solve a problem. Part (a) of the figure below shows a symbolic representation of an electric circuit called an amplifier. The input to the amplifier is the voltage vi and the output is the voltage vo. The output of an amplifier is proportional to the input. The constant of proportionality is called...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT