Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider a Course Class that consists of id , title, credit, tuition per credit, number of students that defines the number of students currently enrolled

Consider a Course Class that consists of id, title, credit, tuition per credit, number of students
that defines the number of students currently enrolled in this course. It has the seat capacity that
determines the maximum number of students that are allowed in this course. The default capacity
has been set to 3 but it is increased by increaseSeatCapacity(int size) method describe
below. 30
public class Course {
private final static int DEFAULT_CAPACITY =3;
private String id;
private String title;
private int credit;
private int tuitionPerCredit;
private int numOfStudent;
private int seatCapacity;
public Course(String id, String title, int credit, int
tuitionPerCredit){
this.id = id;
this.title = title;
this.credit = credit;
this.tuitionPerCredit = tuitionPerCredit;
this.seatCapacity = DEFAULT_CAPACITY;
}
// getter and setter methods for instance variables
public void increaseSeatCapacity(int size){
this.seatCapacity = this.seatCapacity + size;
}
public void increaseNumberOfStudent(){
numOfStudent++;
}
public void decreaseNumberOfStudent(){
numOfStudent--;
}
}
CurrentOfferedCourse class forms the pool of academic courses, the university offers. The
pool of courses is put in cList array which has a default capacity of 5 but it could be increased
dynamically by doubling it if its capacity is exhausted.
Class: CurrentOfferedCourse
addCourse(course : Course) : void This method will take a Course object as a
parameter and will add it to the array of cList if the
number of courses is less than the array length. If
the capacity exceeded the length, the array pool is
doubled and the course is put there.
getCourse(course : Course) : Course This method returns a Course object if it is offered
in a semester otherwise returns null.
getCourseList() : Course[] This method will return an array of Course,
containing all the offered courses in a semester.
public class CurrentOfferedCourse {
private Course[] cList;
private int numberOfCourse;
private static CurrentOfferedCourse instance;
public CurrentOfferedCourse(){
cList = new Course[5];
}
public static CurrentOfferedCourse getInstance(){
if(instance == null){
instance = new CurrentOfferedCourse();
}
return instance;
}
public int getNumberOfCourse(){
return numberOfCourse;
}
public void addCourse(Course course){
}
Code for addCourse
public Course getCourse(Course course){
}
public Course[] getCourseList(){
}
}
Question: Write down the code for addCouse, getCourse, getCourseList in script
with comments highlighting the necessity of the line in coding.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

please dont use chat gpt or other AI 1 5 5 . .

Answered: 1 week ago