26.4k views
17 votes
In this exercise, you are going to use the Person and Student classes to create two objects, then print out all of the available information from each object. Your tasks Create a Person object with the following information: Name: Thomas Edison Birthday: February 11, 1847 Create a Student object with the following infromation: Name: Albert Einstein Birthday: March 14, 1879 Grade: 12 GPA: 5.0 You do not need to modify the Person or Student class.

public class PersonRunner
{
public static void main(String[] args)
{
// Start here!
}
}
public class Person {
private String name;
private String birthday;
public Person (String name, String birthday)
{
this.name = name;
this.birthday = birthday;
}
public String getBirthday(){
return birthday;
}
public String getName(){
return name;
}
}
public class Student extends Person {
private int grade;
private double gpa;
public Student(String name, String birthday, int grade, double gpa){
super(name, birthday);
this.grade = grade;
this.gpa = gpa;
}
public int getGrade(){
return grade;
}
public double getGpa(){
return gpa;
}
}

1 Answer

11 votes

Answer:

public class PersonRunner

{

public static void main(String[] args) {

//create a Person object

Person person = new Person("Thomas Edison", "February 11, 1847");

//create a Student object

Student student = new Student("Albert Einstein", "March 14, 1879", 12, 5.0);

//print out the details of the Person object

System.out.println("===========For Person==============");

System.out.println("Name : " + person.getName());

System.out.println("Birthday: " + person.getBirthday());

System.out.println();

//print out the details of the Student object

System.out.println("===========For Student==============");

System.out.println("Name : " + student.getName());

System.out.println("Birthday: " + student.getBirthday());

System.out.println("Grade: " + student.getGrade());

System.out.println("GPA: " + student.getGpa());

}

}

public class Person {

private String name;

private String birthday;

public Person (String name, String birthday) {

this.name = name;

this.birthday = birthday;

}

public String getBirthday(){

return birthday;

}

public String getName(){

return name;

}

}

public class Student extends Person {

private int grade;

private double gpa;

public Student(String name, String birthday, int grade, double gpa){

super(name, birthday);

this.grade = grade;

this.gpa = gpa;

}

public int getGrade(){

return grade;

}

public double getGpa(){

return gpa;

}

}

Step-by-step explanation:

The necessary code to accomplish the task is written in bold face. It contains comments explaining important parts of the code.

User Harry Joy
by
2.9k points