Person Height in Person is also a class In order to fill in the Height attribute
ID: 3749128 • Letter: P
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 FootballPlayer's 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 getlnfoExplanation / Answer
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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.