ne Work Details: * Create a class named CollegeCourse that includes data fields
ID: 3737440 • Letter: N
Question
ne Work Details: * Create a class named CollegeCourse that includes data fields that hold the department (example ENG), the course number (example 101), the credits (example 3) and a fee for the course (example $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display() method that displays the course data. Create a subclass named LabCourse that adds $50 to the course fee. Override the parent class display) method to indicate that the course is a lab course and to display all the data. Write an application named UseCourse that prompts the user for course information. It may be better if you provide with choices for the user. * If the user enters a class in any of the following departments, create a * If the user enters any other department, create a CollegeCourse that does & Display the course data in a readable format. LabCourse: BIO, CHM, CIS, or PHY not include the lab fee. * Submit a minimum of 3 .java files (CollegeCourseXXX.java, LabCourseXXX.java, UseCourseXXX.java where XXX denotes your last name followed by first initial)Explanation / Answer
LabCourse.java
public class LabCourse extends CollegeCourse{
public LabCourse(String department, int courseNo, int credits){
super(department, courseNo, credits);
super.setFee(50);
}
public void display(){
System.out.println("Lab Course Department "+getDepartment()+" Course Number : "+getCourseNo()+" Credits :"+getCredits()+" Fee :$"+getFee());
}
}
CollegeCourse.java
public class CollegeCourse {
private String department;
private int courseNo;
private int credits;
private int fee = 120;
public CollegeCourse(String department, int courseNo, int credits){
this.department = department;
this.courseNo = courseNo;
this.credits = credits;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public int getCourseNo() {
return courseNo;
}
public void setCourseNo(int courseNo) {
this.courseNo = courseNo;
}
public int getCredits() {
return credits;
}
public void setCredits(int credits) {
this.credits = credits;
}
public int getFee() {
return fee * getCredits();
}
public void setFee(int fee) {
this.fee = fee;
}
public void display(){
System.out.println("Department : "+getDepartment()+" Course Number : "+getCourseNo()+" Credits :"+getCredits()+" Fee :$"+getFee());
}
}
UseCourse.java
import java.util.Scanner;
public class UseCourse {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter Department :");
String department = scan.next();
System.out.println("Enter Course Number :");
int courseNo = scan.nextInt();
System.out.println("Enter Credits :");
int credits = scan.nextInt();
if(department.equalsIgnoreCase("BIO") || department.equalsIgnoreCase("CHM") || department.equalsIgnoreCase("CIS") ||department.equalsIgnoreCase("PHY")){
LabCourse lab = new LabCourse(department, courseNo, credits);
lab.display();
}
else{
CollegeCourse col = new CollegeCourse(department, courseNo, credits);
col.display();
}
}
}
Output:
Enter Department :
BIO
Enter Course Number :
1111
Enter Credits :
5
Lab Course Department BIO Course Number : 1111 Credits :5 Fee :$250
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.