Question

Course, Schedule, and ScheduleTester (100%) Write a JAVA program that meets the following requirements: Course Class Cr...

Course, Schedule, and ScheduleTester (100%)

Write a JAVA program that meets the following requirements:

Course Class

  1. Create a class called Course. It will not have a main method; it is a business class.
  2. Put in your documentation comments at the top. Be sure to include your name.
  3. 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 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.

  1. 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.
  2. Add a 7-argument constructor that uses all parameter variables to set the instance variables. Make sure your constructor calls the setters from #7, to ensure all data is validated. (All arguments will be of type String.)
  3. Generate all the getters and setters
  4. Changes to make to generated getters and setters to make sure data is valid:
    • public void setCrn(String input) – if input consists of all digits, convert input to integer. Use this integer to set the CRN. Otherwise, set the CRN to 9001 and display an error message that “Invalid value typed for CRN. Defaulting to 9001.”  
    • public void setNumber(String input) – if input consists of all digits and is in the range of 1 - 9999, convert input to integer. Use this integer to set the course number. Otherwise, set the course number to 1001 and display an error message that “Invalid value typed for course number. Defaulting to 1001.”  
    • public void setSectionId(String input) – if input consists of all digits and is in the range of 1 - 80, convert input to integer. Use this integer to set the section Id. Otherwise, set the section ID to 1 and display an error message that “Invalid value typed for section ID. Defaulting to 1.”  
    • public void setCreditHours(String input) – if input consists of all digits and is in the range of 0 - 4, convert input to integer. Use this integer to set the number of credit hours. Otherwise, set the credit hours to 3 and display an error message that “Invalid value typed for credit hours. Defaulting to 3.”  
    • public void setIsAvailable(String input) – if input starts with ‘t’, ‘T’, ‘y’, or ‘Y’, set Available to true. Otherwise, set isAvailable to false.
  5. Create the toString method

ScheduleTester Class

  1. Create a class called ScheduleTester. This is the only class that will have a main method in it.
  2. Put in your documentation comments at the top. Be sure to include your name and your instructor’s name.
  3. Inside the main method
  • Construct a Course object named course1. Use the set methods to make sure it has valid information in it.
  • Construct a Course object named course2. Use the set methods to make sure it has valid information in it.
  • Construct a Course object named course3. Use the set methods to make sure it has valid information in it.
  • SOP course1
  • SOP course2

- SOP course3 Schedule

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class Course
{
   /**
   author: Add your name here
   */

   private int crn;
   private String subject;
   private int number;
   private int sectionId;
   private int creditHours;
   private String instructor;
   private boolean isAvailable;

   Course(int crn, String subject, int number, int sectionId)
   {
       this.crn = crn;
       this.subject = subject;
       this.number = number;
       this.sectionId = sectionId;
       creditHours = 3;
       instructor = "TBA";
       isAvailable = false;
   }

   Course(String crn_val, String sub_val, String number_val, String sectionId_val, String creditHours_val,
           String instructor_val, String isAvailable_val)
   {
       setCrn(crn_val);
       setSubject(sub_val);
       setNumber(number_val);
       setSectionId(sectionId_val);
       setCreditHours(creditHours_val);
       setInstructor(instructor_val);
       setIsAvailable(isAvailable_val);
   }

   public int getCrn()
   {
       return crn;
   }

   public void setCrn(String input)
   {
       int flag = 0;
for (int i = 0; i < input.length(); i++)
   if (Character.isDigit(input.charAt(i)) == false)
   {
       flag = 1;
   }
if(flag == 1)
{
   crn = 9001;
   System.out.println(“ Invalid value typed for CRN. Defaulting to 9001. ”);
}
else if(flag == 0)
{
   this.crn = Integer.parseInt(input);
}

   }

   public String getSubject()
   {
       return subject;
   }

   public void setSubject(String input)
   {
       this.subject = input;
   }

   public int getNumber()
   {
       return number;
   }

   public void setNumber(String input)
   {
       int flag = 0;
for (int i = 0; i < input.length(); i++)
   if (Character.isDigit(input.charAt(i)) == false)
   {
       flag = 1;
   }
if(flag == 1)
{
   number = 1001;
   System.out.println(“ Invalid value typed for course number. Defaulting to 1001. ”);
}
else if(flag == 0)
{
   if(input>=1 || input<=9999)
       this.number = Integer.parseInt(input);
}
   }

   int getSectionId()
   {
       return sectionId;
   }

   public void setSectionId(String input)
   {
       int flag = 0;
for (int i = 0; i < input.length(); i++)
   if (Character.isDigit(input.charAt(i)) == false)
   {
       flag = 1;
   }
if(flag == 1)
{
   sectionId = 1;
   System.out.println(“ Invalid value typed for section ID. Defaulting to 1. ”);
}
else if(flag == 0)
{
   if(input>=1 || input<=80)
       this.sectionId = Integer.parseInt(input);
}
   }

   public int getCreditHours()
   {
       return creditHours;
   }

   public void setCreditHours(String input)
   {
       int flag = 0;
for (int i = 0; i < input.length(); i++)
   if (Character.isDigit(input.charAt(i)) == false)
   {
       flag = 1;
   }
if(flag == 1)
{
   creditHours = 3;
   System.out.println(“ Invalid value typed for credit hours. Defaulting to 3. ”);
}
else if(flag == 0)
{
   if(input>=0 || input<=4)
       this.creditHours = Integer.parseInt(input);
}
   }

   public String getInstructor()
   {
       return instructor;
   }

   public void setInstructor(String input)
   {
       this.instructor = input;
   }

   public boolean getIsAvailable()
   {
       return isAvailable;
   }

   public void setIsAvailable(String input)
   {
       if(input.charAt(0) == 't' || input.charAt(0) == 'T' || input.charAt(0) == 'y' || input.charAt(0) == 'Y')
           isAvailable = true;
      
       else
           isAvailable = false;
   }

public String toString()
{
return crn + " " + subject + " " + number + " " + sectionId + " " + creditHours + " " + instructor + " " + isAvailable;
}
}

class ScheduleTester
{
   /**
   Add your name and instructor's name here
   */
   public static void main(String[] args)
   {
       Course course1 = new Course(crn_val, sub_val, number_val, sectionId_val, creditHours_val, instructor_val, isAvailable_val);
       Course course2 = new Course(crn_val, sub_val, number_val, sectionId_val, creditHours_val, instructor_val, isAvailable_val);
       Course course3 = new Course(crn_val, sub_val, number_val, sectionId_val, creditHours_val, instructor_val, isAvailable_val);
       System.out.println(course1);
       System.out.println(course2);
       System.out.println(course3);
   }
}

Add a comment
Know the answer?
Add Answer to:
Course, Schedule, and ScheduleTester (100%) Write a JAVA program that meets the following requirements: Course Class Cr...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a DataEntryException class whose getMessage() method returns information about invalid integer data. Write a program...

    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...

  • Please write in dr java Here is the driver: import java.util.*; public class SquareDriver { public...

    Please write in dr java Here is the driver: import java.util.*; public class SquareDriver { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String input =""; System.out.println("Welcome to the easy square program"); while(true) { System.out.println("Enter the length of the side of a square or enter QUIT to quit"); try { input = keyboard.nextLine(); if(input.equalsIgnoreCase("quit")) break; int length = Integer.parseInt(input); Square s = new Square(); s.setLength(length); s.draw(); System.out.println("The area is "+s.getArea()); System.out.println("The perimeter is "+s.getPerimeter()); } catch(DimensionException e)...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

  • Create a simple Java class for a Month object with the following requirements:  This program...

    Create a simple Java class for a Month object with the following requirements:  This program will have a header block comment with your name, the course and section, as well as a brief description of what the class does.  All methods will have comments concerning their purpose, their inputs, and their outputs  One integer property: monthNumber (protected to only allow values 1-12). This is a numeric representation of the month (e.g. 1 represents January, 2 represents February,...

  • Implement a Java program using simple console input & output and logical control structures such that...

    Implement a Java program using simple console input & output and logical control structures such that the program prompts the user to enter 5 integer scores between 0 to 100 as inputs and does the following tasks For each input score, the program determines whether the corresponding score maps to a pass or a fail. If the input score is greater than or equal to 60, then it should print “Pass”, otherwise, it should print “Fail”. After the 5 integer...

  • please write code in java, assignment is due soon Thanks. public interface Named The Named interface...

    please write code in java, assignment is due soon Thanks. public interface Named The Named interface is a simple interface which applies to anything which has a name. The only thing required is the following method: String name() which returns the name of the instance. public interface MessageSink, It includes: void deliver(Named sender, String message) delivers the specified message from the given sender. public interface Sharable, which is Named, It includes no method. public abstract class GeneralCapability It incudes: The...

  • 4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java...

    4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java source code file named H01_43.java (your main class is named H01_43). Problem: Write a program that prompts the user for the name of a Java source code file (you may assume the file contains Java source code and has a .java filename extension; we will not test your program on non-Java source code files). The program shall read the source code file and output...

  • A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS...

    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...

    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...

  • Please help me with this code. Thank you Implement the following Java class: Vehicle Class should...

    Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT