Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

These are the guidelines: Do the TestClass and Write a Menu Driven program *for the student to enter information and enroll from the list of

These are the guidelines:

Do the TestClass and Write a Menu Driven program

*for the student to enter information and enroll from the list of available courses

Explanations: Final Project Video 4

1. Ask student for first name, last name, id, address and instantiate a student object.

2. Create a menu from the sections returned from the DataStore class (an array of section objects)

3. Prompt the student to enroll in sections available from the menu

4. Handle the custom exceptions and let the student know if they try to enroll in a duplicate section or if they

have enrolled in too many

5. Provide a "Quit" option in your menu

6. When the user chooses "Quit", automatically print their information and schedule

Pseudo Code

1. Get information from console to instantiate your student

2. Create an array and call the getsections from your singleton to load it

DataStore dataStore = DataStore.getInstance();

Section[] courseMenu = dataStore.getSections();

3. Use a loop to show your menu:

while true {

for loop to display menu (this is courseMenu array or whatever you named it)

ask user for input of which to enroll in

if choose quit, break

try

student addCourse (courseMenu[choice);

catch Duplicate

sys out Duplicate Exception getMessage()

catch TooMany

sys out TooMany Exception getMessage()

}

4. After your loop is over, print the student schedule

a. Sys out student toString()

This is the Section.txt

CSC 151 Beginning_Java FJT01 MW 8AM AT 226

CSC 151 Beginning_Java FJT02 MW 10AM AT 226

CSC 151 Beginning_Java FJT03 MW 12PM AT 226

CSC 251 Advanced_Java FJT01 MW 8AM AT 226

CSC 251 Advanced_Java FJT02 MW 10AM AT 226

CSC 251 Advanced_Java FJT03 MW 12PM AT 226

WEB 151 Beginning_Mobile FJT01 TTH 8AM AT 129

WEB 151 Beginning_Mobile FJT02 TTH 10AM AT 129

WEB 115 Beginning_Web FJT01 TTH 12PM AT 219

WEB 115 Beginning_Web FJT02 TTH 2PM AT 219

CSC 139 Beginning_Visual_Basic FJT01 F 10AM AT 226

CSC 139 Beginning_Visual_Basic FJT02 MW 2PM AT 226

WEB 251 Advanced_Mobile FJT01 TTH 2PM AT 129

WEB 251 Advanced_Mobile FJT02 MW 6PM AT 129

ENG 111 English_Composition FJT01 M 6PM AT 254

......................................................................

This is what i've done so far

-----------------------------

Course.java

public class Course {

// Attributes

private String subject;

private String number;

private String name;

public Course(){

}

// Designated Constructor

public Course(String subject, String number, String name) {

super();

this.subject = subject;

this.number = number;

this.name = name;

}

// Getter and Setter methods...

public String getSubject() {

return subject;

}

public void setSubject(String subject) {

this.subject = subject;

}

public String getNumber() {

return number;

}

public void setNumber(String number) {

this.number = number;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

@Override

public String toString() {

return "Course [subject=" + subject +

", number=" + number +

", name=" + name + "]";

}

}

.........................................................

Section.java

public class Section extends Course {

String id; //e.g. FJT01

String days; // e.g "MW" for Wednesday Friday or "TTH" for Tuesday - Thursday

String startTime; //e.g. 10AM

String building; //AT

String room; //226

public Section() {

}

public Section(String subject, String number, String id, String days, String startTime, String building, String room, String name) {

super(subject, number, name);

this.id = id;

this.days = days;

this.startTime = startTime;

this.building = building;

this.room = room;

}

public Section(Course c, String id, String days, String startTime, String building, String room, String name){

super(c.getSubject(), c.getNumber(), c.getName());

this.id = id;

this.days = days;

this.startTime = startTime;

this.building = building;

this.room = room;

}

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getDays() {

return days;

}

public void setDays(String days) {

this.days = days;

}

public String getStartTime() {

return startTime;

}

public void setStartTime(String startTime) {

this.startTime = startTime;

}

public String getBuilding() {

return building;

}

public void setBuilding(String building) {

this.building = building;

}

public String getRoom() {

return room;

}

public void setRoom(String room) {

this.room = room;

}

@Override

public String toString() {

return " Section{" +

super.toString()+

"id='" + id + '\'' +

", days='" + days + '\'' +

", startTime='" + startTime + '\'' +

", building='" + building + '\'' +

", room='" + room + '\'' +

')' + " ";

}

}

.............................................................

Student.java

import java.util.Arrays;

public class Student extends Person {

String id;

Section [] sections = new Section[5];

//Private utility variable

int numberEnrolled = 0;

//Constructor

public Student(){

this("0000");

}

public Student(String id){

this.id = id;

for (int i=0; i

sections[i] = new Section();

}

}

//Get and set

public String getId(){

return id;

}

public void setId(String id){

this.id = id;

}

public void addCourse(Section ss) throws CoursesException, DuplicateCourseException{

try {

for (int i = 0; i < numberEnrolled; i++) {

if (sections[i].getSubject().equals(ss.getSubject()) &&

sections[i].getNumber().equals(ss.getNumber())) {

throw new DuplicateCourseException("Duplicate Course Enrollment: ", ss);

}

}

sections[numberEnrolled] = ss;

numberEnrolled++;

} catch(ArrayIndexOutOfBoundsException e){

throw new CoursesException();

}

}

@Override

public String toString(){

return "Student{" +

super.toString()+

"id='" + id + '\'' +

", course='" + Arrays.toString(sections) +

", firstName=" + firstName +

", lastName=" + lastName +

", dob=" + dob +

", address=" + address +

") ";

}

}

................................................................................................

Person.java

import java.util.Date;

import java.util.Date;

public class Person {

// Attributes

String firstName;

String lastName;

Date dob;

Address address;

public Person(){

}

// Designated Constructor

public Person(String firstName, String lastName, Date dob, Address address) {

this.firstName = firstName;

this.lastName = lastName;

this.dob = dob;

this.address = address;

}

// Getter and Setter methods...

public String getFirstName() {

return firstName;

}

public void setFirstName(String firstName) {

this.firstName = firstName;

}

public String getLastName(){

return lastName;

}

public void setLastName(String lastName) {

this.lastName = lastName;

}

public Date getDob() {

return dob;

}

public void setDob(Date dob) {

this.dob = dob;

}

public Address getAddress() {

return address;

}

public void setAddress(Address address) {

this.address = address;

}

@Override

public String toString() {

return "Person{" +

"firstName='" + firstName + '\'' +

", lastName='" + lastName + '\'' +

", dob=" + dob +

", address=" + address +

'}';

}

}

...................................................................

Address.java

public class Address {

// Attributes

private String street;

private String city;

private String state;

private String zip;

public Address() {

this(" ", " ", "NC", "27282");

}

public Address(String city, String state, String zip) {

this(" ", city, state, zip);

}

// Designated Constructor

public Address(String street, String city, String state, String zip) {

this.street = street;

this.city = city;

this.state = state;

this.zip = zip;

}

// Getter and Setter methods...

public String getStreet() {

return street;

}

public void setStreet(String street) {

this.street = street;

}

public String getCity() {

return city;

}

public void setCity(String city) {

this.city = city;

}

public String getState() {

return state;

}

public void setState(String state) {

this.state = state;

}

public String getZip() {

return zip;

}

public void setZip(String zip) {

this.zip = zip;

}

@Override

public String toString() {

return "Address [street=" + street +

", city=" + city +

", state=" + state +

", zip=" + zip + "]";

}

}

.......................................................................

DuplicateCourseException.java

public class DuplicateCourseException extends Exception{

public DuplicateCourseException(String message, Section c){

super(message + " " + c.getSubject() + " " + c.getNumber());

}

}

.........................................................................

CourseException

public class CoursesException extends Exception{

public CoursesException(){

this("You're trying to enroll in too many sections");

}

public CoursesException(String message){

super(message);

}

}

.........................................................................

DataStore.java

import java.io.File;

import java.io.FileNotFoundException;

import java.nio.file.Paths;

import java.util.Scanner;

public class DataStore {

// Static datastore attribute

private static DataStore singleton = null;

//Private default constructor

private DataStore(){

}

//Private section array attribute

private static Section[] sections = new Section[5];

private static File sectionFile = Paths.get(".", "resources", "Sections.text").normalize().toFile();

public static DataStore getInstance(){

if(singleton == null){

singleton = new DataStore();

Scanner fs;

try {

fs = new Scanner(sectionFile);

for (int i=0; i

sections[i] = new Section(fs.next(),fs.next(), fs.next(), fs.next(), fs.next(), fs.next(), fs.next(), fs.next());

}

} catch (FileNotFoundException e){

System.out.print(e.getMessage());

}

}

return singleton;

}

public static Section[] getSections(){

return sections;

}

}

..........................................................................

Please I really need your help. Thanks for help! ...............................

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Excel 2024 In 7 Days

Authors: Alan Dinkins

1st Edition

B0CJ3X98XK, 979-8861224000

More Books

Students also viewed these Databases questions

Question

Locate the centroid (xc, yc) of the exparabolic segment of area.

Answered: 1 week ago

Question

love of humour, often as a device to lighten the occasion;

Answered: 1 week ago

Question

orderliness, patience and seeing a task through;

Answered: 1 week ago

Question

well defined status and roles (class distinctions);

Answered: 1 week ago