Using the abstract class demo (below) create an additional abstract method calle
ID: 3823934 • Letter: U
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 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());
}
}
Explanation / Answer
HI, Please find my implementation.
#########
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 abstract int getRemainingTests();
}
######################
public class CompSciStudent extends Student
{
private final int MATH_HRS=20;
private final int CS_HRS=40;
private final int CORE_HRS=60;
private final int TESTS=3;
private int mHours;
private int csHours;
private int cHours;
private int numT;
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;
}
public void setTests( int t) {
numT = t;
}
/*
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+" Test Taken: "+numT;;
return str;
}
@Override
public int getRemainingTests() {
return (TESTS - numT);
}
}
###############
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);
csS.setTests(1);
System.out.println(csS);
System.out.println("HOURS REMAINING: "+csS.getRemainingHours());
System.out.println("TEST REMAINING: "+csS.getRemainingTests());
}
}
/*
Sample run:
Name: Mary Smith
ID Number: X0011233
Year Admitted: 2010
Major: Computer Science
Math Hours Taken: 12
Computer Science Hours Taken: 20
Core Hours Taken: 40
Test Taken: 1
HOURS REMAINING: 48
TEST REMAINING: 2
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.