JAVA PROGRAMMING: Create an abstract class called Student which includes the fol
ID: 3917811 • Letter: J
Question
JAVA PROGRAMMING:
Create an abstract class called Student which includes the following for each student:
Name
Status (full time, part time)
Telephone
Then implement an abstract method which determines the amount paid by the student which varies between full time and part time students.
Create two child classes and call them FullTimeStudent and PartTimeStudent.
Show how your code works by creating objects of the two child classes and display the data fields for each object.
You should have four files:
Student.java
FullTimeStudent.java
PartTimeStudent.java
TestStudent.java
Add extra methods if you feel it is necessary and provide a screenshot of the output of your code.
Explanation / Answer
abstract class Student // base class
{
private String name,status,telephone;
public Student(String name,String status,String telephone)// constructor
{
this.name = name;
this.status = status;
this.telephone = telephone;
}
public abstract double amountPaid();// abstract method
public String toString()
{
return " Name of Student : "+name +" Status : "+status +" Telephone : "+telephone;
}
}
class FullTimeStudent extends Student
{
public FullTimeStudent(String name,String status,String telephone)
{
super(name,status,telephone);// call to base class constructor
}
public double amountPaid() // implement abstract method of base class
{
return 6000.75;
}
public String toString()
{
return super.toString() + " Amount Paid : $"+amountPaid();
}
}
class PartTimeStudent extends Student
{
public PartTimeStudent(String name,String status,String telephone)
{
super(name,status,telephone);// call to base class constructor
}
public double amountPaid()// implement abstract method of base class
{
return 2000.00;
}
public String toString()
{
return super.toString() + " Amount Paid : $"+amountPaid();
}
}
class TestStudent
{
public static void main (String[] args)
{
PartTimeStudent s1 = new PartTimeStudent("James Johnson","Part Time","0879-87878");
System.out.println(s1);// call to toString() method
FullTimeStudent s2 = new FullTimeStudent("Henry Hudson","Full Time","0878-788775");
System.out.println(s2);
}
}
Output:
Name of Student : James Johnson Status : Part Time Telephone : 0879-87878 Amount Paid : $2000.0
Name of Student : Henry Hudson Status : Full Time Telephone : 0878-788775 Amount Paid : $6000.75
Do ask if any doubt. Please upvote.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.