Respuesta :
Answer:
File: clgCourse.java
public class clgCourse
{
private final double CREDIT_HOUR_FEE = 120.00;
private String dpt;
private int courseNo;
private int credits;
private double courseFee;
public clgCourse(String newdpt, int newcourseNo, int newCredits)
{
dpt = newdpt.toUpperCase();
courseNo = newcourseNo;
credits = newCredits;
courseFee = CREDIT_HOUR_FEE * credits;
}
public String getdpt()
{
return dpt;
}
public int getcourseNo()
{
return courseNo;
}
public int getCredits()
{
return credits;
}
public double getcourseFee()
{
return courseFee;
}
public void display()
{
System.out.println("\n Course Data");
System.out.println("Course: " + "College Course");
System.out.println("dpt: " + this.getdpt());
System.out.println("Course Number: " + this.getcourseNo());
System.out.println("Credit Hours: " + this.getCredits());
System.out.println("Course Fee: $" + this.getcourseFee());
}
}
File: LabCourse.java
public class LabCourse extends clgCourse
{
private final double LAB_FEE = 50.00;
private double labCourseFee;
public LabCourse(String newdpt, int newcourseNo, int newCredits)
{
super(newdpt, newcourseNo, newCredits);
labCourseFee = super.getcourseFee() + LAB_FEE;
}
public double getLabCourseFee()
{
return labCourseFee;
}
public void display()
{
System.out.println("\n Course Data");
System.out.println("Course: " + "Lab Course");
System.out.println("dpt: " + super.getdpt());
System.out.println("Course Number: " + super.getcourseNo());
System.out.println("Credit Hours: " + super.getCredits());
System.out.println("Course Fee: $" + this.getLabCourseFee());
}
}
File: UseCourse.java
import java.util.Scanner;
public class UseCourse
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the dpt of the course: ");
String dept = keyboard.nextLine();
System.out.print("Enter the number of the course: ");
int number = keyboard.nextInt();
System.out.print("Enter the credit hours of the course: ");
int hours = keyboard.nextInt();
if(dept.equalsIgnoreCase("BIO") || dept.equalsIgnoreCase("CHM")
|| dept.equalsIgnoreCase("CIS") || dept.equalsIgnoreCase("PHY"))
{
LabCourse labCourse = new LabCourse(dept, number, hours);
labCourse.display();
}
else
{
clgCourse clgCourse = new clgCourse(dept, number, hours);
clgCourse.display();
}
keyboard.close();
}
}
Explanation:
- Create a getdpt method that returns the dpt of the course .
- Create a getcourseNo method that returns the number of the course.
- Create a display method that displays all the data of college course .
- Check if the user enters any of the lab dpts (BIO, CHM, CIS, or PHY), then create a LabCourse and then display the course data .
- Check if the user does not enter any of the lab dpts (BIO, CHM, CIS, or PHY), then create a clgCourse and then display the course data .