1718 2018 Question 2 Design a console application that will print the final resu
ID: 3743069 • Letter: 1
Question
1718 2018 Question 2 Design a console application that will print the final result obtained by a student with the each student number, test result, assignment result and exam. Create a constructor that student number, test result, assigniment result and the exam result as parameters methods for the variables. The Student class must implement an iReport interface that contains the following: weighting of module. Make use of an abstract class named Student that contains variables to store the accepts the public interface iReport public void print report0: Create a subclass called Student_ Report that extends the Student class. The Student Report class must contain a constructor to accept the student number, test, assignment and exam results as parameters. Write code for the print report method which calculates each assessment wieighting as follows: Assessment Test Assignment Exam Weighting 25% 25% 50% Finally write a useStudent class to instantiate the Student_Report class. Sample output is shown below and you may hard code the same values to test your application.Explanation / Answer
/*The following program prints the report of a student. The object oriented concepts like
* inheritance, abstract classes, interfaces, etc are used.
*/
interface iReport
{//the interface with print_report() method. This method is abstract by default.
public void print_report();
}
abstract class Student implements iReport
{//this class implements iReport interface
long st_no;
float test_res, ass_res, exam_res;
Student(long st_no, float test_res, float ass_res, float exam_res)
{
this.st_no=st_no;
this.test_res=test_res;
this.ass_res=ass_res;
this.exam_res=exam_res;
}
//Getter methods.
public long getst_no()
{
return st_no;
}
public double gettest_res()
{
return test_res;
}
public double getass_res()
{
return ass_res;
}
public double getexam_res()
{
return exam_res;
}
public abstract void print_report();//Any class must implement all the functions of an interface it is implementing. If we do not want to implement some methods
//then those must be declared abstract. Any class having one or more abstract methods has to be an abstract class. The onus to implement those abstract methods
//then lies on the class extending the abstract class.
}
class Student_Report extends Student{//this is the subclass of Student, hence it must have implementation of print_report()
Student_Report(long st_no, float test_res, float ass_res, float exam_res)
{
super(st_no,test_res,ass_res, exam_res);//call to parent class constructor with required parameters
}
public void print_report(){//
//assuming the total course out of 100 marks thus the test_res, ass_res and exam_res are out of 25,25,50 respectively i.e. the marks are themselves
//the weighting. Since the question does not mention anything about the course total and what the input is(i.e. percntage or marks), I have assumed
//course total as 100 and the inputs to be the marks(actually they will be percentages i.e. weights too in this particular case as the course total
//is 100)
System.out.println("STUDENT REPORT");
System.out.println(" ********************************************");
System.out.println("STUDENT NUMBER: "+ this.getst_no());//get methods are used to retrieve the value of required variables
System.out.println("TEST WEIGHTING: "+ this.gettest_res());
System.out.println("ASSIGNMENT WEIGHTING: "+ this.getass_res());
System.out.println("EXAM WEIGHTING: " +this.getexam_res());
System.out.println("FINAL RESULT: " +(this.gettest_res()+this.getass_res()+this.getexam_res()));
System.out.println("********************************************");
}
}
public class useStudent
{//Driver class
public static void main(String args[])
{
Student_Report ob=new Student_Report(11007, 20.0f,18.75f, 32.5f);//instantiating Student_Report
ob.print_report();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.