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

These are the guidelines: Inheritance - Subclass Course to Section Explanations:

ID: 3718784 • Letter: T

Question

These are the guidelines:

Inheritance - Subclass Course to Section

Explanations: Final Project Video 1

Requirements

Changes to Course:

1. Add default constructor (leave it blank)

2. Add constructor with all attributes

3. You may want to modify the “toString()” once you are finished with the project

Create Section Class: (Inheritance, Chapter 11)

1. Extend Course

2. Attributes:

- String id; //e.g. FJT01

- String days; // e.g "MW" for Monday Wednesday or "TTH" for tuesday

- thursday

- String startTime; //e.g. 10AM

- String building; //AT

- String room; //226

3. Add default constructor (leave it blank)

4. Add constructor with all attributes

5. Add all getter and setters

6. Override toString(), be sure to call the super toString()

** for the “days” attribute, there is leeway , you can use a char array or other solution, you can also use a

java.util.date class for the time if you want to

Changes to Student:

1. Change Courses array to Section array

2. Change addCourse() to addSection(), be sure it returns void (we will eventually throw a custom exception)

3. You may want to format the toString(), possibly get rid of the Arrays.toString() or add some line returns

Singleton Design Pattern

Explanations: Final Project Video 2

Create a Singleton DataStore Class

1. Create a DataStore class that implements the Singleton Design Pattern to store data.

2. Read all Section data from a file and store in the singleton class

3. Provide a getSections() method that returns an array of all the sections for the client (in our case the client is

your test class)

4. Instantiate the DataStore from the TestClass and access the data

Additional resources for the singleton design pattern: https://youtu.be/KUTqnWswPV4,

https://youtu.be/SR46F0ryt40

Error handling and Custom Exceptions

Explanations: Final Project Video 3

Create two custom Exceptions (Chapter 12 - Read and watch video notes that come with your book ESPECIALLY

the first two video notes)

1. Create a DuplicateCourseException

2. Create a MaximumCoursesExceededException

3. Throw appropriate exception in the addSection ( or enroll if that is what you called it) method of the Student

class

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; i could'nt also have done the TestClass.java

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

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;

}

}

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

Thanks for help!

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

Explanation / Answer

//Driver.java

package com.src;

import java.util.Scanner;

public class Driver {

public static void main(String[] args) {

String firstName,lastName,id,address;

Scanner sc = new Scanner(System.in);

firstName = sc.nextLine();

lastName = sc.nextLine();

id = sc.nextLine();

Address addr = new Address();

Student s = new Student(id);

s.setFirstName(firstName);

s.setLastName(lastName);

s.setAddress(addr);

Section[] sections = DataStore.getSections();

int i=0;

int choice = 0;

while(choice != 6) {

for(i=0;i<sections.length;i++)

System.out.println( (i+1) + " :" + sections[i]);

System.out.println((i+1) + " : Quit");

System.out.println("Enter choice in 1-6");

s.sections[i] = sections[i];

}

System.out.println(s);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote