Question

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 String[100];
   private int numberOfStudents;

   public Course(String courseName) {
       this.setCourseName(courseName);
   }

   public void addStudent(String student) {
       students[numberOfStudents] = student;
       numberOfStudents++;
   }

   public String[] getStudents() {
       return students;
   }

   public int getNumberOfStudents() {
       return numberOfStudents;
   }

   public void dropStudent(String student) {
   }

   public String getCourseName() {
       return courseName;
   }
}

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Rewrite the Course class in Listing 10.6 to implement the comparable and the cloneable interfaces. The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • I asked this a little bit ago but didn't clarify exactly what I needed, so I'm...

    I asked this a little bit ago but didn't clarify exactly what I needed, so I'm asking again...I've attached my code below the question. Thanks! Do not change the original contract of the Course class. Instead, ONLY change the implementation of property students, from an array to and ArrayList, and update any methods in class Course that access students to reflect ArrayList. The methods are overridden. That means that you do not need to change the header for methods, only...

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

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

  • Writing 3 Java Classes for Student registration /** * A class which maintains basic information about...

    Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course {    /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name 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...

  • Language Java Step 1: Design a class called Student. The Student class should contain the following...

    Language Java Step 1: Design a class called Student. The Student class should contain the following data: firstName lastName studentID totalCredits gpa Your class should implement the “sets” and “gets” for the class. Include methods: equals, compareTo, toString. Change the toString method (from class) to put each member variable on a new line. Step 2: Write a driver program to test that Student works correctly. Test is with 3 students as given in class. Step 3: Write a “registration” program...

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

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

  • Design a JAVA class called Course. The class should contain: ○ The data fields courseName (String),...

    Design a JAVA class called Course. The class should contain: ○ The data fields courseName (String), numberOfStudents (int) and courseLecturer (String). ○ A constructor that constructs a Course object with the specified courseName, numberOfStudents and courseLecturer. ○ The relevant get and set methods for the data fields. ○ A toString() method that formats that returns a string that represents a course object in the following format: (courseName, courseLecturer, numberOfStudents) ● Create a new ArrayList called courses1, add 5 courses to...

  • I need help in converting this into pseudo-code Student.java public class Student implements Comparable<Student>{ private String...

    I need help in converting this into pseudo-code Student.java public class Student implements Comparable<Student>{ private String name, major, status; private int rank;    public Student() { this.name = this.major = this.status = ""; this.rank = 0; }    public Student(String name, String major, String status) { this.name = name; this.major = major; this.status = status; } public String getName() { return name; } public String getMajor() { return major; } public String getStatus() { return status; }    public int...

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