Question
Using the abstract class demo (below) create an additional abstract method called: public abstract int getRemainingTests(); in the superclass In the ComputerScienceStudent class you will
Using the abstract class demo (below) create an additional abstract method called: public abstract int getRemainingTests(); in the superclass In the ComputerScienceStudent class you will have the following variable private final int TESTS=3;and private int numT; You will have a mutator for itpublic void setTests( int t) {
You will have the following as well
public int getRemainingTests()
{//WRITE CODE THAT WILL RETURN THE NUMBER OF TEST REMAINING FROM THE 3 RQUIRED TO GRADUATE
In the demo class output how many tests are left to take in order to graduate along with the remaining hours left to take to graduate. YOU MUST upload the entire code of each question with the output for full credit as a word document AFTER running in eclipse.If your code does not run you will upload the full code for each with the error message as a word document AFTER running it in eclipse.
public abstract class Student
{
private String name;
private String idNumber;
private int yrAdmitted;
public Student(String n, String i, int y)
{
name=n;
idNumber=i;
yrAdmitted=y;
}
public String toString()
{
String str;
str = "Name: "+name+" ID Number: "+idNumber+" Year Admitted: "+yrAdmitted;
return str;
}
/*NOTE here the next method is abstract... It MUST be overridden in a subclass
It returns the hours remaining for the student
NOTE there is NO definition for the method in THIS class
*/
public abstract int getRemainingHours();
}
public class CompSciStudent extends Student
{
private final int MATH_HRS=20;
private final int CS_HRS=40;
private final int CORE_HRS=60;
private int mHours;
private int csHours;
private int cHours;
public CompSciStudent(String n, String id, int y)
{
super(n,id,y);//inherits from the Abstract Student Class
}
public void setMathHours(int m)
{
mHours=m;
}
public void setCSHours(int cs)
{
csHours=cs;
}
public void setCoreHours(int c)
{
cHours=c;
}
/*
The getRemaining Hours method returns the number of hours remaining to be taken. NOTE the definition is in this subclass
*/
public int getRemainingHours()
{
int reqHours, remainingHours;
reqHours=MATH_HRS+CS_HRS+CORE_HRS;
remainingHours=reqHours-(mHours+csHours+cHours);
return remainingHours;
}
public String toString()
{
String str;
str=super.toString()+" Major: Computer Science Math Hours Taken: "+mHours+" Computer Science Hours Taken: "+csHours+" Core Hours Taken: "+cHours;
return str;
}
}
public class CompSciStudentDemo
{
public static void main(String[] args)
{
CompSciStudent csS=new CompSciStudent("Mary Smith","X0011233",2010);
csS.setMathHours(12);
csS.setCSHours(20);
csS.setCoreHours(40);
System.out.println(csS);
System.out.println("HOURS REMAINING: "+csS.getRemainingHours());
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started