question archive Consider a class named GraduateCourse that includes Three data members i
Subject:Computer SciencePrice:6.89 Bought3
Consider a class named GraduateCourse that includes
Derive a class named ResearchCourse from Course class, which contains
Implement both classes and in the main() function, instance of ResearchCourse class. Invoke appropriate functions to display all attribute values as well as the total fee for this particular instance.
Source code:
Main.java
class GraduateCourse { String courseID; //(e.g. CEN2012) String courseName; //(e.g. OOP) int creditHours ;//(e.g. 3 or 4), and double courseFee; //(eg 10,000) public GraduateCourse(String id, String name, int hrs, double fees) { this.courseID=id; this.courseName=name; this.creditHours=hrs; this.courseFee=fees; } public void setcourseID(String id){ this.courseID=id; } public String getcourseID(){ return this.courseID; } public void setcourseName(String name){ this.courseName=name; } public String getcourseName(){ return this.courseName; } public void setcreditHours(int hrs){ this.creditHours=hrs; } public int getcreditHours(){ return this.creditHours; } public void setcourseFees(double fees){ this.courseFee=fees; } public double getcourseFees(){ return this.courseFee; } } class ResearchCourse extends GraduateCourse { double experimentFee; public ResearchCourse (String id, String name, int hrs, double fees,double expfees) { super(id,name,hrs,fees); this.experimentFee=expfees; } public void setexperimentFee(double expfees){ this.experimentFee=expfees; } public double getexperimentFee(){ return this.experimentFee; } public void totalFee() { double totalfee=this.getexperimentFee()+this.getcourseFees(); System.out.println("Total amount of fees to be paid is: "+totalfee); } public void display() { System.out.println("courseID: "+this.getcourseID()); System.out.println("courseName: "+this.getcourseName()); System.out.println("creditHours: "+this.getcreditHours()); System.out.println("courseFee: "+this.getcourseFees()); System.out.println("experimentFee: "+this.getexperimentFee()); this.totalFee(); } } public class Main { public static void main (String[] args) { ResearchCourse rcourse1=new ResearchCourse("CEN2012","OOP",4,10000,5000); rcourse1.display(); System.out.println(); ResearchCourse rcourse2=new ResearchCourse("CEN2016","Java Programming",6,15000,7000); rcourse2.display(); } }
Output:
courseID: CEN2012 courseName: OOP creditHours: 4 courseFee: 10000.0 experimentFee: 5000.0 Total amount of fees to be paid is: 15000.0 courseID: CEN2016 courseName: Java Programming creditHours: 6 courseFee: 15000.0 experimentFee: 7000.0 Total amount of fees to be paid is: 22000.0
I have done this code using an online compiler .
So If you want to execute this code in your browser then just paste "https://onlinegdb.com/rJy79VseD" and click run.