Question

In: Computer Science

Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG),...

Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG), the course number (for example, 101), the credits (for example, 3), and the fee for the course (for 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. If the user enters a class in any of the following departments, create a LabCourse: BIO, CHM, CIS, or PHY. If the user enters any other department, create a CollegeCourse that does not include the lab fee. Then display the course data. Save the files as CollegeCourse.java, LabCourse.java, and UseCourse.java.

PLEASE CODE IN JAVA!!

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// CollegeCourse.java

public class CollegeCourse {

      // attributes

      private String department;

      private int courseNum;

      private int credits;

      protected int courseFee; // made protected, because it needs to be accessed

                                                 // in LabCourse

      // constant for storing fee per credit hour

      private static final int FEE_PER_CREDIT_HOUR = 120;

      // constructor taking all values except course fee

      public CollegeCourse(String department, int courseNum, int credits) {

            this.department = department;

            this.courseNum = courseNum;

            this.credits = credits;

            // finding course fee and assigning

            this.courseFee = credits * FEE_PER_CREDIT_HOUR;

      }

     

      //method to display all data

      public void display() {

            System.out.println("Course Details:");

            System.out.println("Department: " + department);

            System.out.println("Course Number: " + courseNum);

            System.out.println("Credits: " + credits);

            System.out.println("Course Fee: $" + courseFee);

      }

}

// LabCourse.java

public class LabCourse extends CollegeCourse {

      // constant for storing lab fee

      private static final int LAB_FEE = 50;

      // constructor taking all values except course fee

      public LabCourse(String department, int courseNum, int credits) {

            // passing values to super class constructor

            super(department, courseNum, credits);

            // adding 50 to course fee as lab fee

            courseFee += LAB_FEE;

      }

      @Override

      public void display() {

            // displaying 'This is a Lab Course'

            System.out.println("This is a Lab Course");

            // invoking super class display() method to display all data

            super.display();

      }

}

// UseCourse.java

import java.util.Scanner;

public class UseCourse {

      public static void main(String[] args) {

            // scanner for input

            Scanner scanner = new Scanner(System.in);

            // initializing a CollegeCourse (super class reference) to null

            CollegeCourse course = null;

            // prompting and reading inputs

            System.out.print("Enter course department: ");

            String dept = scanner.next();

            System.out.print("Enter course number: ");

            int courseNum = scanner.nextInt();

            System.out.print("Enter credits: ");

            int credits = scanner.nextInt();

            // finding category of department

            if (dept.equalsIgnoreCase("BIO") || dept.equalsIgnoreCase("CHM")

                        || dept.equalsIgnoreCase("CIS") || dept.equalsIgnoreCase("PHY")) {

                  // creating a LabCourse and assigning to course

                  course = new LabCourse(dept, courseNum, credits);

            } else {

                  // creating a CollegeCourse and assigning to course

                  course = new CollegeCourse(dept, courseNum, credits);

            }

            // displaying info

            course.display();

      }

}

/*OUTPUT (two runs)*/

Enter course department: PHY

Enter course number: 101

Enter credits: 3

This is a Lab Course

Course Details:

Department: PHY

Course Number: 101

Credits: 3

Course Fee: $410

Enter course department: HUI

Enter course number: 187

Enter credits: 2

Course Details:

Department: HUI

Course Number: 187

Credits: 2

Course Fee: $240


Related Solutions

Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly...
Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name to “XXX”, the apartment number to 0, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a nonstatic method named addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy()...
Implement an Employee class that includes data fields to hold the Employee’s ID number, first name,...
Implement an Employee class that includes data fields to hold the Employee’s ID number, first name, last name, and hourly pay rate (use of string datatype is not allowed). Create an array of five Employee objects. Input the data in the employee array. Write a searchById() function, that ask the user to enter an employee id, if its present, your program should display the employee record, if it isn’t there, simply print the message ”Employee with this ID doesn’t exist”....
Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a...
Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a doubleannual sales amount. Methods include a constructor that requires values for both data fields, as well as get and set methods for each of the data fields. Write an application named DemoSalesperson that declares an array of 10 Salesperson objects. Set each ID number to 9999 and each sales value to zero. Display the 10 Salesperson objects. public class DemoSalesperson { public static void...
Create a class named Horse that contains the following data fields: name - of type String...
Create a class named Horse that contains the following data fields: name - of type String color - of type String birthYear - of type int Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field, races (of type int), that holds the number of races in which the horse has competed and additional methods to get and set the new field. ------------------------------------ DemoHorses.java public class DemoHorses {     public static void...
Create a class named Sandwich that contains the following data fields: MainIngredient - of type String...
Create a class named Sandwich that contains the following data fields: MainIngredient - of type String Bread - of type String Price - of type Double Include get and set methods for these fields. The methods should be prefixed with 'get' or 'set' respectively, followed by the field name using camel case. For example, setMainIngredient. Use the application named TestSandwich that instantiates one Sandwich object and demonstrates the use of the set and get methods to test your class. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------...
Java program Create a constructor for a class named Signal that will hold digitized acceleration data....
Java program Create a constructor for a class named Signal that will hold digitized acceleration data. Signal has the following field declarations private     double timeStep;               // time between each data point     int numberOfPoints;          // number of data samples in array     double [] acceleration = new double [1000];          // acceleration data     double [] velocity = new double [1000];        // calculated velocity data     double [] displacement = new double [1000];        // calculated disp data The constructor...
Create a class named “Car” which has the following fields. The fields correspond to the columns...
Create a class named “Car” which has the following fields. The fields correspond to the columns in the text file except the last one. i. Vehicle_Name : String ii. Engine_Number : String iii. Vehicle_Price : double iv. Profit : double v. Total_Price : double (Total_Price = Vehicle_Price + Vehicle_Price* Profit/100) 2. Write a Java program to read the content of the text file. Each row has the attributes of one Car Object (except Total_Price). 3. After reading the instances of...
Java program Create a public method named saveData for a class named Signal that will hold...
Java program Create a public method named saveData for a class named Signal that will hold digitized acceleration data. Signal has the following field declarations private     double timeStep;               // time between each data point     int numberOfPoints;          // number of data samples in array     double [] acceleration = new double [1000];          // acceleration data     double [] velocity = new double [1000];        // calculated velocity data     double [] displacement = new double [1000];        // calculated disp...
write program in java Create a class named PersonalDetails with the fields name and address. The...
write program in java Create a class named PersonalDetails with the fields name and address. The class should have a parameterized constructor and get method for each field.  Create a class named Student with the fields ID, PersonalDetails object, major and GPA. The class should have a parameterized constructor and get method for each field. Create an application/class named StudentApp that declare Student object. Prompts (GUI input) the user for student details including ID, name, address, major and GPA....
c++ Create a class named EvolutionTree which will hold a list of species and their expected...
c++ Create a class named EvolutionTree which will hold a list of species and their expected age, and allow a user to search for a particular species or an age. EvolutionTree should have private data members: species (a string array of size 400 with all the species) speciesAges (an int array of size 400 for all the species' ages). EvolutionTree should have a default constructor which should initialize the species array to empty strings ("") and initialize the speciesAges array...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT