Question

Short Answer Questions Q4. [10 marks] The following UML class diagram describes the structure of a Java program for managing

[Continued] Your Course class should have:

1)a getter for the course 'code', so that it is read-only;

2)a getter and setter for the lecturer attribute, so that it is readable and writable;

3)a constructor that creates the associations shown in the UML diagram;

4)an enrolStudent method that adds a given Student object into the 'enrolled' set;

5)a withdrawStudent method that removes a given Student object from the 'enrolled' set and returns true if the student was successfully found and removed, false otherwise.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// 1)a getter for the course 'code', so that it is read-only;

public String getCode() {

return code;

}

// 2)a getter for the lecturer attribute, so that it is readable

public Staff getLecturer() {

return lecturer;

}

// 2)a setter for the lecturer attribute, so that it is writable;

public void setLecturer(Staff lecturer) {

this.lecturer = lecturer;

}

// 4)an enrolStudent method that adds a given Student object into the

// 'enrolled' set;

public void enrolStudent(Student s) {

// simply adding

enrolled.add(s);

}

// 5)a withdrawStudent method that removes a given Student object from the

// 'enrolled' set and returns true if the student was successfully found and

// removed, false otherwise.

public boolean withdrawStudent(Student s) {

// finding the student

for (int i = 0; i < enrolled.size(); i++) {

if (enrolled.get(i).getId() == s.getId()) {

// found, removing and returning true

enrolled.remove(i);

return true;

}

}

return false; // not found

}

}

Add a comment
Know the answer?
Add Answer to:
[Continued] Your Course class should have: 1)a getter for the course 'code', so that it is...
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
  • [Continued] Your Course class should have: 1)a getter for the course 'code', so that it is...

    [Continued] Your Course class should have: 1)a getter for the course 'code', so that it is read-only; 2)a getter and setter for the lecturer attribute, so that it is readable and writable; 3)a constructor that creates the associations shown in the UML diagram; 4)an enrolStudent method that adds a given Student object into the 'enrolled' set; 5)a withdrawStudent method that removes a given Student object from the 'enrolled' set and returns true if the student was successfully found and removed,...

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

  • In c# So far, you have created object-oriented code for individual classes. You have built objects...

    In c# So far, you have created object-oriented code for individual classes. You have built objects from these classes. Last week, you created a UML for new inherited classes and objects. Finally, you have used polymorphism. When you add abstraction to this mix, you have the “4 Pillars of OOP.” Now, you begin putting the pieces together to create larger object-oriented programs. Objectives for the project are: Create OO classes that contain inherited and polymorphic members Create abstracted classes and...

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

  • You have been approached by a University for the design and implementation of a relational databa...

    You have been approached by a University for the design and implementation of a relational database system that will provide information on the courses it offers, the academic departments that run the courses, the academic staff and the enrolled students. The system will be used mainly by the students and the academic staff. The requirement collection and analysis phase of the database design process provided the following data requirements for the University Database system. Using the following requirements answer this...

  • 3. Suppose the University has two types of academics: students and lecturers. Both of these have...

    3. Suppose the University has two types of academics: students and lecturers. Both of these have names and ids, but students attend lectures while lecturers give them class Studentí private: string name; string id; public: Student(string name, string id); string getName O; string getIDO; void attendLecture (); class Lecturer< private: string name; string id; publiC: Lecturer (string name, string id); string getName (); string getIDO; void giveLecture(); ti (a) Write the header for a class called Academic and update the...

  • what is the solution for this Java problem? Generics Suppose you need to process the following...

    what is the solution for this Java problem? Generics Suppose you need to process the following information regarding Students and Courses: A Student has a name, age, ID, and courseList. The class should have a constructor with inputs for setting name, ID and age. The class should have setters and getters for attributes name, ID and age, and a method addCourse, removeCourse, printSchedule. courseList: use the generic class ArrayList<E> as the type of this attribute addCourse: this method takes as...

  • Consider the following partial UML class diagram for the class Student:

    Consider the following partial UML class diagram for the class Student:Student-studentID: String-name: String-school: String+validateStudentID (s: Student):boolean studentID is a string that consists of a letter representing the school followed by 5 digits. The codes used for the schools in this scenario are shown below:SchoolCodeExample of student IDFASC'A'"A12345" refers to a student from FASC.FAFB'B'"B88888" refers to a student from FAFB.Write the code for the method validateStudentID (Student student) such that it performs validations on the parameter's student ID to ensure that:- the...

  • How to complete this methods: import java.io.FileInputStream; import java.io.FileNotFoundException; import java.time.Loc...

    How to complete this methods: import java.io.FileInputStream; import java.io.FileNotFoundException; import java.time.LocalDate; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Scanner; import java.util.Set; /** * Utility class that deals with all the other classes. * * @author EECS2030 Summer 2019 * */ public final class Registrar {    public static final String COURSES_FILE = "Courses.csv";    public static final String STUDENTS_FILE = "Students.csv";    public static final String PATH = System.getProperty("java.class.path");    /**    * Hash table to store the list of students using their...

  • 3. Suppose the University has two types of academics: students and lecturers. Both of these have...

    3. Suppose the University has two types of academics: students and lecturers. Both of these have names and ids, but students attend lectures while lecturers give them. class Student private: string name; string id; public: Student (string name, string id); string getName ); string getIDO; void attendLecture(); class Lecturer private: string name; string id; public: Lecturer(string name, string id); string getName; string getIDO; void giveLecture (); a) Write the header for a class called Academic and update the Student and...

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