Define an abstract class Person that describes a typical person. Include methods
ID: 3692154 • Letter: D
Question
Define an abstract class Person that describes a typical person. Include methods to retrieve the person’s name, and to get or change his or her address. Next, define a subclass Student that describes a typical student. Include methods to retrieve his or her ID number, number of credits completed, and grade point average. Also, include methods to get or change his or her campus address. Finally, derive from Student a class UgradStudent for a typical undergraduate student. Include methods for retrieving his or her degree and major.
Explanation / Answer
public abstract class person
{
private String name;
private String address;
private int number;
public Employee(String name, String address, int number)
{
System.out.println("Constructing an person");
this.name = name;
this.address = address;
this.number = number;
}
}
public String toString()
{
return name + " " + address + " " + number;
}
public String getDetails()
{
return name;
return address;
return number;
}
public void setAddress(String newAddress)
{
address = newAddress;
}
}
public class student extends person
{
private int stuid;
private double average; //average score
private int credit;
public studentdet(int stuid,String name, String address, int credit, double
average)
{
super(stuid, name, address, number);
setAverage(average);
}
public double getDetails()
{
return stuid;
return name;
return credits;
return average;
}
public void setAddress(string address)
{
address = new address;
}
public class Ugraduate extends student
{
private int graid;
private double average; //average score
private int credit;
public studentdet(int graid,String name, String address, int credit, double
average)
{
super(grastuid, name, address, number);
setAverage(average);
}
public double getDetails()
{
return stuid;
return name;
return credits;
return average;
}
public void setAverage(double newAverage)
{
if(newAverage >= 0.0)
{
salary = newAverage;
}
}
}
public class AbstractDemo
{
public static void main(String [] args)
{
student s = new student("Mohd Mohtashim", "Ambehta, UP", 3, 36);
person e = new student("John Adams", "Boston, MA", 2, 24);
Ugraduate u = new student("mia jones", Houston, 5, 12);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.