Question

College of Winston and Charlotte This program will calculate the amount for a semester bill at...

College of Winston and Charlotte

This program will calculate the amount for a semester bill at The College of Winston and Charlotte.

Part 1:

Create a class Course.java:

The class has non-static instance variables:

  • private String department
  • private int courseNumber
  • private int courseCredits
  • private double courseCost

The class must have a default constructor which will set values as follows:

  • department = “unknown”
  • courseNumber = 0
  • courseCost = 0
  • courseCredits = 0

The class must have a non-default constructor which will set values as follows (use the setters):

  • department = value passed to constructor
  • courseNumber = value passed to constructor
  • courseCredits = value passed to constructor
  • courseCost = no value will be passed to the constructor, courseCost will be calculated as courseCredits/2 * $500, see setter below (if the course is a Lab Course add $100 to the cost)

The class must have the appropriate getter and setter methods. The setter methods must trap the user to enter valid information as follows:

  • courseNumbers must be 001 - 399 (inclusive)
  • courseCredits must be 3, 4 or 6
  • department must be ENGL, MATH, COMP, HIST, HUMN, SCIE, LANG, PHYS
  • courseCost = courseCredits/2 * $500, if the course is a Lab Course add $100 to the cost

The class must have a toString method and an equals method.

Part 2:

Create a LabCourse.java which is a subclass of Course.java.

LabCourse.java adds $100 to the courseCost.

The class must have the appropriate default and non-default constructors.

Getter and setter methods are not needed.

The class must have a toString method and an equals method. Both of those methods must override the inherited toString and equals methods.

A course is a lab course if the department is COMP, SCIE, PHYS

Part 3:

Develop a program (DemoWinstonAndCharlotte_yourInitials.java, where yourInitialsrepresents your initials) that asks the user for the number of courses they will take,  creates an array of Courses, gets the information for each course (department, courseNumber, courseCredits), creates instances of the appropriate class, populates the array with the instances, calculates the cost of each course and the total bill and then prints the information for each course and the total of the bill to the user.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question, The whole assignment is too big. Given the limited time, I have coded the Part 1 and Part 2, I could not finish off the Part 3. Please post Part 3 as a separate post and I will help you with it. Sorry for the incovenience caused here.

Here are the two classes for Part 1 and Part 2

===========================================================================

import java.util.Objects;

public class Course {

    private String department;
    private int courseNumber;
    private int courseCredits;
    private double courseCost;

    public Course() {
        department = "unknown";
        courseNumber = 0;
        courseCost = 0;
        courseCredits = 0;
    }

    public Course(String department, int courseNumber, int courseCredits) {
        setDepartment(department);
        this.courseNumber = courseNumber;
        this.courseCredits = courseCredits * 500 / 2;
        this.courseCost = courseCost;
    }

    public String getDepartment() {
        return department;
    }

    public int getCourseNumber() {
        return courseNumber;
    }

    public int getCourseCredits() {
        return courseCredits;
    }

    public double getCourseCost() {
        return courseCost;
    }

    public void setCourseNumber(int courseNumber) {
        if (1 <= courseNumber && courseNumber <= 399)
            this.courseNumber = courseNumber;
    }

    public void setCourseCredits(int courseCredits) {
        if (3 <= courseCredits && courseCredits <= 6) {
            this.courseCredits = courseCredits;
            courseCost = courseCredits * 500 / 2;
            if (department.equals("COMP") || department.equals("SCIE") || department.equals("PHYS")) {
                this.department = department;
                courseCost += 100;
            }
        }

    }

    public void setDepartment(String department) {
        if (department.equals("ENGL") || department.equals("MATH") ||
                department.equals("HIST") ||
                department.equals("HUMN") ||
                department.equals("LANG"))
            this.department = department;
        else if (department.equals("COMP") || department.equals("SCIE") || department.equals("PHYS")) {
            this.department = department;
            courseCost += 100;
        }
    }

    @Override
    public String toString() {
        return
                "Department: " + department +
                        ", Course Number: " + courseNumber +
                        ", Credits: " + courseCredits +
                        ", Cost $" + courseCost;

    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Course course = (Course) o;
        return courseNumber == course.courseNumber &&
                courseCredits == course.courseCredits &&
                Double.compare(course.courseCost, courseCost) == 0 &&
                Objects.equals(department, course.department);
    }


}

===================================================================

public class LabCourse extends Course {

    public LabCourse() {
        super();
    }

    public LabCourse(String department, int courseNumber, int courseCredits) {
        super(department, courseNumber, courseCredits);
    }

    @Override
    public String toString() {
        return "Lab Course: " + super.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (o != null && o instanceof LabCourse) {
            return super.equals(o);
        } else {
            return false;
        }

    }
}

===================================================================

Add a comment
Know the answer?
Add Answer to:
College of Winston and Charlotte This program will calculate the amount for a semester bill at...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You are to create a class Appointment.java that will have the following: 5 Instance variables: private...

    You are to create a class Appointment.java that will have the following: 5 Instance variables: private String month private int day private int year private int hour private int minute 1 default constructor public Appointment() 1 non-default constructor that accepts arguments for all instance variables, your constructor must call the setter methods below to set the values of the instance variables public Appointment(String monthPassed, int dayPassed, int yearPassed, int hourPassed, int minutePassed) 5 setter methods (one for each instance variable)...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • In Java* Please implement a class called "MyPet". It is designed as shown in the following...

    In Java* Please implement a class called "MyPet". It is designed as shown in the following class diagram. Four private instance variables: name (of the type String), color (of the type String), gender (of the type char) and weight(of the type double). Three overloaded constructors: a default constructor with no argument a constructor which takes a string argument for name, and a constructor with take two strings, a char and a double for name, color, gender and weight respectively. public...

  • Help with this coding assignment for C++! Add any comments for better understanding. Create a class...

    Help with this coding assignment for C++! Add any comments for better understanding. Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The constructor will initial all member variable to a default value 0. • One public pure virtual function showingredients() that returns void....

  • Java Eclipse Coding question: Use data abstraction (real-world modeling) to come up with 3 instance variables...

    Java Eclipse Coding question: Use data abstraction (real-world modeling) to come up with 3 instance variables and 2 effectors for a new data type – the class HospitalPatient. You have the freedom to design the instance variables and effectors. instance variables effectors 1. 1. 2. 2. 3. Write the code for class HospitalPatient, according to the requirement above. Include the default constructors with no argument, and the constructor with all arguments. Provide a getter and setter for each individual instance...

  • Please submit a .cpp file or upload zip if you have more than one file before...

    Please submit a .cpp file or upload zip if you have more than one file before the time up. No library function is allowed. ***The code must contain your name and has proper format. Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The...

  • JAVA programing Question 1 (Date Class):                                   &nbsp

    JAVA programing Question 1 (Date Class):                                                                                                     5 Points Create a class Date with the day, month and year fields (attributes). Provide constructors that: A constructor that takes three input arguments to initialize the day, month and year fields. Note 1: Make sure that the initialization values for the day, month and year fields are valid where the day must be between 1 and 31 inclusive, the month between 1 and 12 inclusive and the year a positive number. Note 2:...

  • Given a class called Student and a class called Course that contains an ArrayList of Student....

    Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called getDeansList() as described below. Refer to Student.java below to learn what methods are available. I will paste both of the simple .JAVA codes below COURSE.JAVA import java.util.*; import java.io.*; /****************************************************** * A list of students in a course *****************************************************/ public class Course{     /** collection of Students */     private ArrayList<Student> roster; /***************************************************** Constructor for objects of class Course *****************************************************/...

  • SaffSpring 2019 Professor Question 1: Answer ALL of the following questions based on this provide...

    I need sub-questions e, f, g, h. SaffSpring 2019 Professor Question 1: Answer ALL of the following questions based on this provided int daya int montha Date int dnt int y day-d year class Event ring locatson eventbat Event (5tring , Dated ocatlon- event Date-d pubiie String toStringt String detalla-Locatlons"LocatlonDatesevent Date.day return detalia eventDate-year publie statie weld mai arg Event 2ew EventCBayan" hew Date1.3,20191 Systen.out peintil The event n (11.201,as scheduled-ee . 내 1 eentDate.yeari ystem.st-printeinte yatem.ost-printcin(e2) a) What is...

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT