Course Class
|
Variable name |
Description |
|
crn |
A unique number given each semester to a section (stands for Course Registration Number) |
|
subject |
A 4-letter abbreviation for the course (e.g., ITEC, PHED, CHEM) |
|
number |
A 4-digit number associated with the course (e.g., 1001, 1008, 0099). Note when selecting the data type: it is important to store 0099 instead of 99. |
|
sectionId |
A 2-digit number associated with a particular section of a course (e.g., 01, 13, 47) |
|
creditHours |
Number of credit hours the course is worth. Valid values are 0, 1, 2, 3, or 4. The default value is 3. |
|
instructor |
First and last name of the instructor teaching the course. If the instructor is not known, this should be listed as “TBA” |
|
isAvailable |
Value is either true or false based upon whether the course is available for registration. Default is false. |
ScheduleTester Class
- SOP course3 Schedule
Class
|
Variable name |
Description |
|
|
courseList |
An ArrayList of Course objects |
courseList = new ArrayList<Course>();
ScheduleTester Class again
Inside the main method for the ScheduleTester class, add the following line right after your SOP of course3
Thanks for the question.
Here is the completed code for this problem. Let me know if you have any doubts or if you need anything to change.
Thank You !!
================================================================================================
public class Course {
private int crn;
private String subject;
private String number;
private int sectionId;
private int creditHours;
private String instructor;
private boolean isAvailable;
//Create a constructor that has the crn, subject, number, and sectionId. Initialize the other instance variables based upon the default values in the table above.
public Course(int crn, String subject, String number, int sectionId) {
this.crn = crn;
this.subject = subject;
this.number = number;
this.sectionId = sectionId;
creditHours = 3;
instructor = "TBA";
isAvailable = false;
}
//Add a 7-argument constructor that uses all parameter variables to set the instance variables.
public Course(String crn, String subject, String number, int sectionId, int creditHours, String instructor, boolean isAvailable) {
setCrn(crn);
this.subject = subject;
setNumber(number);
this.sectionId = sectionId;
this.creditHours = creditHours;
this.instructor = instructor;
this.isAvailable = isAvailable;
}
public void setCrn(String input) {
try {
crn = Integer.parseInt(input);
} catch (NumberFormatException nfe) {
System.out.println("Invalid value typed for CRN. Defaulting to 9001.");
crn = 9001;
}
}
public void setNumber(String input) {
try {
int number = Integer.parseInt(input);
if (1 <= number && number <= 9999) {
if (number < 10) this.number = "000" + number;
else if (number < 100) this.number = "00" + number;
else if (number < 1000) this.number = "0" + number;
else this.number = String.valueOf(number);
} else {
System.out.println("Invalid value typed for course number. Defaulting to 1001.");
this.number = "1001";
}
} catch (NumberFormatException nfe) {
System.out.println("Invalid value typed for course number. Defaulting to 1001.");
this.number = "1001";
}
}
public void setSectionId(String input) {
try {
int number = Integer.parseInt(input);
if (1 <= number && number <= 80) {
sectionId = number;
} else {
System.out.println("Invalid value typed for section ID. Defaulting to 1.");
this.sectionId = 1;
}
} catch (NumberFormatException nfe) {
System.out.println("Invalid value typed for section ID. Defaulting to 1.");
this.sectionId = 1;
}
}
public void setCreditHours(String input) {
try {
int number = Integer.parseInt(input);
if (0 <= number && number <= 4) {
creditHours = number;
} else {
System.out.println("Invalid value typed for credit hours. Defaulting to 3.");
creditHours = 3;
}
} catch (NumberFormatException nfe) {
System.out.println("Invalid value typed for credit hours. Defaulting to 3.");
creditHours = 3;
}
}
public void setIsAvailable(String input) {
char firstLetter = input.charAt(0);
if (firstLetter == 't' || firstLetter == 'T') {
isAvailable = true;
} else if (firstLetter == 'f' || firstLetter == 'F') {
isAvailable = false;
} else {
isAvailable = false;
}
}
public int getCrn() {
return crn;
}
public String getSubject() {
return subject;
}
public String getNumber() {
return number;
}
public int getSectionId() {
return sectionId;
}
public int getCreditHours() {
return creditHours;
}
public String getInstructor() {
return instructor;
}
public boolean isAvailable() {
return isAvailable;
}
public void setSubject(String subject) {
this.subject = subject;
}
public void setInstructor(String instructor) {
this.instructor = instructor;
}
@Override
public String toString() {
return
"Crn: " + crn +
", Subject: " + subject +
", Number: " + number +
", Section Id: " + sectionId +
", Credit Hours: " + creditHours +
" hours, Instructor: " + instructor +
", course available: " + isAvailable;
}
}
=======================================================================================
import java.util.ArrayList;
public class Schedule {
//Schedule has the following instance variable named as shown in the table:
private ArrayList<Course> courseList;
//Create a no-argument constructor.
public Schedule() {
courseList = new ArrayList<Course>();
}
//Generate all the getters and setters.
public ArrayList<Course> getCourseList() {
return courseList;
}
//Generate all the getters and setters.
public void setCourseList(ArrayList<Course> courseList) {
this.courseList = courseList;
}
//Using the example provided above, write a toString method for this class.
@Override
public String toString() {
StringBuffer courses = new StringBuffer();
for(Course course: courseList){
courses.append(course).append("\n");
}
return courses.toString();
}
//This method returns the number of courses in the schedule which are considered available
public int numAvailableCourses(){
int availableCourseCount=0;
for(Course course : courseList){
availableCourseCount+=course.isAvailable()?1:0;
}
return availableCourseCount;
}
// This method should iterate through the courses and return the total number of credit hours being taken.
public int totalCredits(){
int totalCredits =0;
for(Course course:courseList)
totalCredits+=course.getCreditHours();
return totalCredits;
}
// This method is passed a specific subject such as “ITEC” or “ENGL”.
// It will then iterate through the courses which are part of the team. It will return the number of courses that match the subject passed in.
public int howManyBySubject(String subject){
int subjectCount =0;
for(Course course:courseList)
subjectCount+=course.getSubject().equalsIgnoreCase(subject)?1:0;
return subjectCount;
}
//public void addCourse(Course aCourse) – This method adds the provided course to the schedule
public void addCourse(Course aCourse){
courseList.add(aCourse);
}
}
=======================================================================================
Course Class Create a class called Course. It will not have a main method; it is...
Course, Schedule, and ScheduleTester (100%) Write a JAVA program that meets the following requirements: Course Class Create a class called Course. It will not have a main method; it is a business class. Put in your documentation comments at the top. Be sure to include your name. Course must have the following instance variables named as shown in the table: Variable name Description crn A unique number given each semester to a section (stands for Course Registration Number) subject A...
Thank you in advance. Create a class called Main and write the main method. I need help with calling the printChart method Declare a variable to hold the grade as it is read in Declare 5 variables to hold counts to count the number of As, Bs, Cs, etc declare a variable to hold the class name and ask the user to enter the name of the class whose grades are going to be entered. Write a loop that reads...
LE 7.1 Create a separate class called Family. This class will have NO main(). Insert a default constructor in the Family class. This is a method that is empty and its header looks like this: public NameOfClass() Except, for the main(), take all the other methods in LE 6.2 and put them in the Family class. Transfer the class variables from LE 6.2 to Family. Strip the word static from the class variables and the method headers in the Family...
Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...
Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...
In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...
Create a DataEntryException class whose getMessage() method returns information about invalid integer data. Write a program named GetIDAndAge that continually prompts the user for an ID number and an age until a terminal 0 is entered for both. If the ID and age are both valid, display the message ID and Age OK. Throw a DataEntryException if the ID is not in the range of valid ID numbers (0 through 999), or if the age is not in the range...
A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...
A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...
A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...