Question: Code 1: import java.util.Scanner; public class CollegeCourse { public static void main(String[] args) { } private String department; private int courseNo; private int credits; private
Code 1:
import java.util.Scanner;
public class CollegeCourse {
public static void main(String[] args) {
}
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());
}
}
Code 2:
import java.util.Scanner;
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());
}
}
Code 3:
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();
}
}
}
This code is correct but Can someone please state what each of these lines mean/does? Im going to add it as comment next to the lines on my java so I remember it when I look back at the project. Thank you.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
