Question

Person Height in Person is also a class In order to fill in the Height attribute, a Height object needs to be created . int number * String name . String position .Height height App int weight String hometowrn Creates one FootballPlayer object Use the method getlnfo() to display the FootballPlayers complete information String highSchool Height int feet int inches . String getlnfo() extends String getlnfo() FootballPlayer int number String position . FootballPlayer is a Person with two extra attributes Number and position String getlnfo

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

class Height
{
private int feet;
private int inches;

public Height(int feet,int inches)
{
this.feet = feet;
this.inches = inches;
}
public String getInfo()
{
return feet+"Feet "+inches+"inches";
}

}
class Person
{

private String name;
private Height height;
private int weight;
private String hometown;
private String highSchool;

public Person(String name,Height height,int weight,String hometown,String highSchool)
{

this.name = name;
this.height = height;
this.weight = weight;
this.hometown = hometown;
this.highSchool = highSchool;
}
public String getInfo()
{
return " Name : "+name +" Height : "+height.getInfo()+
" Weight : "+weight + " Hometown : "+hometown + " High School : "+highSchool;
}


}
class FootballPlayer extends Person
{

private int number;
private String position;

public FootballPlayer(int number,String name,String position,Height height,int weight,String hometown,String highSchool)
{
super(name,height,weight,hometown,highSchool);
this.number = number;
this.position = position;

}


public String getInfo()
{
return super.getInfo() + " Number : "+number + " Position : "+position;
}

}
class App
{
public static void main (String[] args)
{
Height height = new Height(6,1);
FootballPlayer fp1 = new FootballPlayer(10,"Cristiano Ronaldo","Forward",height,150,"Maderai","highSchool");
System.out.println(fp1.getInfo());
}
}

Output:

Name : Cristiano Ronaldo Height : 6Feet 1inches Weight : 150 Hometown : Maderai High School : highSchool Number : 10 Position : Forward

Do ask if any doubt. Please upvote.

Add a comment
Know the answer?
Add Answer to:
Person Height in Person is also a class In order to fill in the Height attribute,...
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
  • python code? 1. Create a class called Person that has 4 attributes, the name, the age,...

    python code? 1. Create a class called Person that has 4 attributes, the name, the age, the weight and the height [5 points] 2. Write 3 methods for this class with the following specifications. a. A constructor for the class which initializes the attributes [2.5 points] b. Displays information about the Person (attributes) [2.5 points] c. Takes a parameter Xage and returns true if the age of the person is older than Xage, false otherwise [5 points] 3. Create another...

  • 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...

  • Please help with a source code for C++ and also need screenshot of output: Step 1:...

    Please help with a source code for C++ and also need screenshot of output: Step 1: Create a Glasses class using a separate header file and implementation file. Add the following attributes. Color (string data type) Prescription (float data type) Create a default constructor that sets default attributes. Color should be set to unknown because it is not given. Prescription should be set to 0.0 because it is not given. Create a parameterized constructor that sets the attributes to the...

  • C++ help : Write a class Person with an Attribute for Name. Write a Student class...

    C++ help : Write a class Person with an Attribute for Name. Write a Student class that extends Person and has an attribute for NumberOfCreditsEarned and NumberOfCreditsRequiredToGraduate. Add a function Print() to Student that displays their name and the number of credits they still have to complete before graduating.

  • Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring;...

    Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring; public Person() {    this.numOffspring = 0; } public Person (int numOffspring) {    this.numOffspring = numOffspring; } public Person(String name, int birthYear, double weight, double height, char gender, int numCarryOn, int numOffspring) {    super(name, birthYear, weight, height, gender, numCarryOn);       if(numOffspring < 0) {        this.numOffspring = 0;    }    this.numOffspring = numOffspring; } public int getNumOffspring() {   ...

  • For C++ This is the information about the meal class 2-1. (24 marks) Define and implement...

    For C++ This is the information about the meal class 2-1. (24 marks) Define and implement a class named Dessert, which represents a special kind of Meal. It is to be defined by inheriting from the Meal class. The Dessert class has the following constructor: Dessert (string n, int co) // creates a meal with name n, whose type // is "dessert" and cost is co The class must have a private static attribute static int nextID ; which is...

  • Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super...

    Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super class. The class includes four private String instance variables: first name, last name, social security number, and state. Write a constructor and get methods for each instance variable. Also, add a toString method to print the details of the person. After that create a class Teacher which extends the class, Person. Add a private instance variable to store number of courses. Write a constructor...

  • **Using NetBeans** Lesson Using inheritance to reuse classes. Deliverables person.java student.java studentAthlete.java app.java Using inheritance and...

    **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...

  • 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...

  • Language: C++ Create an abstract base class person. The person class must be an abstract base...

    Language: C++ Create an abstract base class person. The person class must be an abstract base class where the following functions are abstracted (to be implemented in Salesman and Warehouse): • set Position • get Position • get TotalSalary .printDetails The person class shall store the following data as either private or protected (i.e., not public; need to be accessible to the derived classes): . a person's name: std::string . a person's age: int . a person's height: float The...

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