Question

Write a program that implements a Course class. Write a demo class that implements two instances...

Write a program that implements a Course class. Write a demo class that implements two instances of the Course class.

The Course class shall have the following member properties and methods:

Course

- courseName: String - courseAbbr: String - courseNumber: int - courseSection: int

- maxNumOfStudents: int
+ numberOfCourseInstances: int

+ Course (courseName: String, courseAbbr: String, courseNumber: int, courseSection: int) : void + setCourseName(courseName: String) : void
+ setCourseAbbr (courseAbbr : String): void
+ setCourseNumber (courseNumber : int): void

+ setCourseSection (courseSection : int): void
+ setMaxNumOfStudents(maxNumOfStudents: int) : void + getCourseName(): String
+ getCourseAbbr(): String
+ getCourseNumber(): int
+ getCourseSection(): int
+ getMaxNumOfStudents(): int

+ toString(): void
+ clone(): Course
+ equals(): boolean

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;



class Course implements Cloneable{
    String courseName,courseAbbr;
    int courseNumber,courseSection,maxNumOfStudents,numberOfCourseInstances;

    Course(String courseName, String courseAbbr, int courseNumber, int courseSection){
        this.courseName = courseName;
        this.courseAbbr = courseAbbr;
        this.courseNumber = courseNumber;
        this.courseSection = courseSection;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    public void setCourseAbbr(String courseAbbr) {
        this.courseAbbr = courseAbbr;
    }

    public void setCourseNumber(int courseNumber) {
        this.courseNumber = courseNumber;
    }

    public void setCourseSection(int courseSection) {
        this.courseSection = courseSection;
    }

    public void setMaxNumOfStudents(int maxNumOfStudents) {
        this.maxNumOfStudents = maxNumOfStudents;
    }

    public void setNumberOfCourseInstances(int numberOfCourseInstances) {
        this.numberOfCourseInstances = numberOfCourseInstances;
    }

    public String getCourseName() {
        return courseName;
    }

    public String getCourseAbbr() {
        return courseAbbr;
    }

    public int getCourseNumber() {
        return courseNumber;
    }

    public int getCourseSection() {
        return courseSection;
    }

    public int getMaxNumOfStudents() {
        return maxNumOfStudents;
    }

    public int getNumberOfCourseInstances() {
        return numberOfCourseInstances;
    }

    @Override
    public String toString() {
        return "Course{" +
                "courseName='" + courseName + '\'' +
                ", courseAbbr='" + courseAbbr + '\'' +
                ", courseNumber=" + courseNumber +
                ", courseSection=" + courseSection +
                ", maxNumOfStudents=" + maxNumOfStudents +
                ", numberOfCourseInstances=" + numberOfCourseInstances +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Course)) return false;
        Course course = (Course) o;
        return courseNumber == course.courseNumber &&
                courseSection == course.courseSection &&
                maxNumOfStudents == course.maxNumOfStudents &&
                numberOfCourseInstances == course.numberOfCourseInstances &&
                Objects.equals(courseName, course.courseName) &&
                Objects.equals(courseAbbr, course.courseAbbr);
    }

    public Course clone(){
        return new Course( courseName, courseAbbr, courseNumber, courseSection);
    }

}

class Main{
    public static void main(String[] args) {
        Course a = new Course("Computer Science","CSE",2,50);
        Course b  = new Course("Machine Learning","ML",4,75);
        System.out.println(a);
        System.out.println(b);
        Course cl = a.clone();
        System.out.println(cl);
    }
}

OUTPUT :

Add a comment
Know the answer?
Add Answer to:
Write a program that implements a Course class. Write a demo class that implements two instances...
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
  • Rewrite the Course class in Listing 10.6 to implement the comparable and the cloneable interfaces. The...

    Rewrite the Course class in Listing 10.6 to implement the comparable and the cloneable interfaces. The clone method must allow a deep copy on the students field. In addition, add the equals(Object o) and the toString() methods. Write a test program to invoke the compareTo, clone, equals, and toString methods in a meaningful way. Below is the Listing from the book that needs to be rewritten public class Course {    private String courseName;    private String[] students = new...

  • 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...

  • Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use impl...

    Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable<Book> in the class definition. Now, all book objects are instances of the java.lang.Comparable interface. Write a test program that creates an array of ten books. 1. Use Arrays.sort( Book[]l books) from the java.util package to sort the array. The order of objects in the array is determined using compareTo...) method. 2. Write a method that returns the most expensive book in the...

  • 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...

  • JAVA Implement a MyQueue class which implements a queue using two stacks. private int maxCapacity...

    JAVA Implement a MyQueue class which implements a queue using two stacks. private int maxCapacity = 4; private Stack stack1; private Stack stack2; Note: You can use library Stack but you are not allowed to use library Queue and any of its methods Your Queue should not accept null or empty String or space as an input You need to implement the following methods using two stacks (stack1 & stack2) and also you can add more methods as well: public...

  • Write a class named Octagon (Octagon.java) that extends the following abstract GeometricObject class and implements the...

    Write a class named Octagon (Octagon.java) that extends the following abstract GeometricObject class and implements the Comparable and Cloneable interfaces. //GeometricObject.java: The abstract GeometricObject class public abstract class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated; /** Construct a default geometric object */ protected GeometricObject() { dateCreated = new java.util.Date(); } /** Construct a geometric object with color and filled value */ protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color;...

  • I have a little problem about my code. when i'm working on "toString method" in "Course"...

    I have a little problem about my code. when i'm working on "toString method" in "Course" class, it always say there is a mistake, but i can not fix it: Student class: public class Student {    private String firstName;    private String lastName;    private String id;    private boolean tuitionPaid;       public Student(String firstName, String lastName, String id, boolean tuitionPaid)    {        this.firstName=firstName;        this.lastName=lastName;        this.id=id;        this.tuitionPaid=tuitionPaid;    }   ...

  • answer the questions throughout this program public class Day implements Comparable {    Private Boolean atWork;...

    answer the questions throughout this program public class Day implements Comparable {    Private Boolean atWork;    Private String Weather;    Private int fuNumber; } public Day ( boolean Atwork, String Weather, int funNumber) {    Atwork = Atwork;    Weather = Weather;    funNumber = funNumber; } //question 1: implement the getter and setter (mutatto of the funNumber data member. if the number is outside the range 0-10 make the fuNumebr=5; public boolean equals (Day rhs) {    //...

  • Task 3: Main Program Create a main program class that: Creates three or more Nurse instances...

    Task 3: Main Program Create a main program class that: Creates three or more Nurse instances assigned to different shifts. Creates three or more Doctor instances. Creates three or more Patient instances with pre-determined names and manually assigned physicians chosen from the pool of Doctor instances previously created. Generates another 20 Patient instances using randomly generated names and randomly assigns them physicians chosen from the pool of Doctor instances previously created. Prints the toString() values for all employees. Prints the...

  • Course,java import java.util.ArrayList; import java.util.Arrays; /* * To change this license header, choose License Headers in...

    Course,java import java.util.ArrayList; import java.util.Arrays; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author fenghui */ public class Course {     private String cName;     private ArrayList<Subject> cores;     private ArrayList<Major> majors;     private ArrayList<Subject> electives;     private int cCredit;          public Course(String n, int cc){         cName = n;         cCredit = cc;         cores = new ArrayList<Subject>(0);         majors =...

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