Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please follow the simple out put !!!!! LOOK!!!!Here is the simple output from th

ID: 3811620 • Letter: P

Question

Please follow the simple out put !!!!!

LOOK!!!!Here is the simple output from the course registration program

// PRINTS THE COURSE

Media Studies (5 student capacity)

// PRINTS THE ROSTER

--No students enrolled.--

//TRIES TO ADD THE SIXTH STUDENT AND PRINTS A MESSAGE IF ANY ADD FAILS

Farrah Fawcet (S956) could not be added.

//PRINTS THE ROSTER (BEFORE DROPPING 3RD STUDENT)

Enrollment: 5

Adam Ant (S925)

Bob Barker (S713)

Chevy Chase (S512)

Doris Day (S513)

Emilio Estevez (S516)

// PRINTS THE ROSTER (AFTER DROPPING 3RD STUDENT)

// NOTE: NO "null"s ARE PRINTED

Enrollment: 4

Adam Ant (S925)

Bob Barker (S713)

Doris Day (S513)

Emilio Estevez (S516)

// PRINTS THE ROSTER (AFTER ADDING 6TH STUDENT)

// NOTE: YOUR ORDER MIGHT BE DIFFERENT- THAT'S OKAY

Enrollment: 5

Adam Ant (S925)

Bob Barker (S713)

Doris Day (S513)

Emilio Estevez (S516)

Farrah Fawcet (S956)

Part 1- The Student Class (10 points)

Write a class called Student. A student is described by:

a name

an ID (text-based, such as “X002")

whether or not tuition is paid

Write a constructor, getters and setters, and a toString method for this class.

Part 2- The Course Class (10 points)

Write a class called Course to represent a college class. A course is described by:

a name

the maximum students that can be enrolled in the course

Write a constructor, getters and setters (using appropriate validity checks), and a toString method.

Part 3- The Roster (10 points)

Add a roster to the Course class. A roster is represented by an array of Student objects.

Add instance data and code to the constructor to represent the roster.

(You do not need to add a getter and setter. The methods below will allow an outside class to access the roster appropriately.)

Part 4- Course Methods (50 points)

Write the following 3 methods in the Course class:

public boolean addStudent(Student s)

if there is room for the student and the student has paid their tuition, add the student to the roster and return true

return false otherwise

public boolean dropStudent(Student s)

if the student is currently in the roster, remove them from the roster and return true

return false otherwise

Note: There are different approaches to implementing this method. Any approach is fine, but be sure to test your method thoroughly considering lots of different possible cases. (Use your driver program for this!)

public void printRoster()

print how many students are enrolled in the course

also print the list of each student on a single line (use good object-oriented principles to access a text representation of each student!)

print an appropriate message if there are no students yet enrolled

Part 5- Driver Program (20 points)

For this project, you will not write an interactive driver. Instead, you will write a driver to demonstrate that your class works. To do this, write a driver program that does the following (in this order):

creates six students

creates a course that can hold five students

prints the course

prints the roster

adds the first five students to the course

tries to add the sixth student and prints a message if the add fails

prints the roster

drops the third student from the course

prints the roster

tries again to add the sixth student to the course (it should succeed this time)

prints the roster

Explanation / Answer


import java.util.Objects;

/*
* 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 Sam
*/
public class CourseClassDriver {

    public static void main(String[] args) {

        Student s1 = new Student("Adam Ant", "S925", true);
        Student s2 = new Student("Bob Barker", "S713", true);
        Student s3 = new Student("Chevy Chase", "S512", true);
        Student s4 = new Student("Doris Day", "S513", true);
        Student s5 = new Student("Emilio Estevez", "S516", true);
        Student s6 = new Student("Farrah Fawcet", "S956", true);

        Course c = new Course("Media Studies", 5);
        System.out.println(c);
        c.printRoster();
        c.addStudent(s1);
        c.addStudent(s2);
        c.addStudent(s3);
        c.addStudent(s4);
        c.addStudent(s5);
        c.addStudent(s6);
        c.printRoster();
        c.dropStudent(s3);
        c.printRoster();
        c.addStudent(s6);
        c.printRoster();
    }
}

class Student { //this class is too simple to be commented!

    private String name;
    private String id;
    private boolean paidTution;

    public Student(String name, String id, boolean paidTution) {
        this.name = name;
        this.id = id;
        this.paidTution = paidTution;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public boolean isPaidTution() {
        return paidTution;
    }

    public void setPaidTution(boolean paidTution) {
        this.paidTution = paidTution;
    }

    @Override
    public String toString() {
        return name + " (" + id + ")";
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Student other = (Student) obj;
        if (!Objects.equals(this.name, other.name)) {
            return false;
        }
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        if (this.paidTution != other.paidTution) {
            return false;
        }
        return true;
    }

}

class Course {

    private String name;
    private int maxCapacity;
    private Student roster[];
    private int countStudent;

    public Course(String name, int maxCapacity) {
        if (maxCapacity <= 0) { //argument validity chk
            throw new IllegalArgumentException("max Capacity should be mre then 0");
        }
        this.name = name;
        this.maxCapacity = maxCapacity;
        roster = new Student[maxCapacity];
        countStudent = 0;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getMaxCapacity() {
        return maxCapacity;
    }

    public void setMaxCapacity(int maxCapacity) {
        if (maxCapacity <= 0) { // argument validity check
            throw new IllegalArgumentException("max Capacity should be mre then 0");
        }
        this.maxCapacity = maxCapacity;
    }

    @Override
    public String toString() {
        return name + "(" + maxCapacity + " student capacity)";
    }

    public boolean addStudent(Student s) {
        if (countStudent < maxCapacity && s.isPaidTution()) { // validity chk
            roster[countStudent++] = s;
            return true;
        }
        System.out.println(s + " could not be added."); //failure respone
        return false;
    }

    public boolean dropStudent(Student s) {
        for (int i = 0; i < countStudent; i++) {
            if (roster[i].equals(s)) {
                for (int j = i; j < countStudent - 1; j++) { //to remove the student, we shift the students on right to fill the vacant space
                    roster[j] = roster[j + 1];
                }
                countStudent--;
                roster[countStudent] = null; //remove reference of last data, so that garbage can be collected if applicable
                return true;
            }
        }
        System.out.println(s + " could not be found.");
        return false;
    }

    public void printRoster() {
        if (countStudent == 0) {
            System.out.println("--No students enrolled.--");
            return;
        }
        System.out.println("Enrollment: " + countStudent);
        for (int i = 0; i < countStudent; i++) {
            System.out.println(roster[i]);
        }
    }
}

I made the code very simple for you. Hope you like the code. Let me know if you face any difficulty!