Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

inport java.util.Scanner; public class Project3 { public static String toTime(int time) { } public static int getStart(Scanner kbd, String courseName, char day) { } public

inport java.util.Scanner;

public class Project3 {

public static String toTime(int time) {

}

public static int getStart(Scanner kbd, String courseName, char day) {

} public static int calcEnd(int begin, int length) {

} public static int getEnd(Scanner kbd, int startTime, String courseName, char day) {

} public static String getDays(Scanner kbd, String className) {

} public static int getInfo(Scanner kbd, int [ ] startTime, int[ ] endTime, String[ ] names, char[ ] dayInSched, int nbrCourses ) {

} public static void printSchedule(int[ ] startTime, int[ ] endTime, String[ ] names, char[ ] days, int length) {

} public static void main(String[ ] args) {

Scanner kbd = new Scanner(System.in);

System.out.print("How many courses are you taking? ");

int nbrCourses = kbd.nextInt( );

// there will be a max of 5 class meetings for each course, // so the size of the array is nbrCourses * 5

int[ ] startTime = new int[nbrCourses*5];

int[ ] endTime = new int[nbrCourses*5];

String[ ] names = new String[nbrCourses*5];

char[ ] days = new char[nbrCourses*5];

// the actual number of class meetings is nbrTimes

int nbrTimes = getInfo(kbd, startTime, endTime, names, days, nbrCourses );

printSchedule(startTime, endTime, names, days, nbrTimes );

}

}

public static String toTime(int time) This method takes an integer, and uses String format to return a value in time format. For example, 920 should return "09:20". 2 would return "00:02". You should do this by breaking the parameter up into the hundreds digits (parameter/100) and 0 filling the value (String.format("%02d",9) returns "09"). Then, append a ":" character then the last 2 digits of the parameter (parameter % 100).

toTime(920) should return "09:20"

toTime(1234) should return "12:34"

toTime(1) should return "00:01"

public static int getStart(Scanner kbd, String courseName, char day) This method reads in (as an integer) the start time for courseName on day, and returns the result. A sample run for getStart(kbd, "Phys151L", 'T') would produce:

public static int calcEnd(int begin, int length) This method takes a beginning time and a duration and returns an ending time.

calcEnd(900, 50) should return 950

calcEnd(930, 50) should return 1020

calcEnd(950, 150) should return 1220 To do this, you will need to split the begin time into hours and minutes, add the number of minutes to length, then convert that into the number of hours to add if the total number of minutes is >60. Solve this on paper, and write the steps down before writing it in Java. The solution requires a loop (in the case that you will need to add more than one hour as in calcEnd(950, 150)).

public static int getEnd(Scanner kbd, int startTime, String courseName, char day) This method reads in from kbd the number of minutes that courseName lasts on day, and returns as an integer the time that the course will end starting at startTime. This method should call calcEnd.

getEnd(kbd, 900, "CPSC150", 'M') returns 950 if 50 is entered.

getEnd(kbd, 930, "CPSC150", 'M') returns 1020 if 50 is entered.

getEnd(kbd, 1800, "Phys151L", 'M') returns 2045 if 165 is entered.

public static String getDays(Scanner kbd, String className) getDays reads the days of the week from kbd that className meets. The user should enter the days as a String (e.g., "MWF"); the method method should contain a validation loop to verify that each character in the String is a day of the week (M, T, W, R, or an F). If one character is not a day of the week, the user should reenter the string. The method should return the String that is entered. For example, the input and output below, repeated from the sample run, should be in getDays:

public static int getInfo(Scanner kbd, int [ ] startTime, int[ ] endTime, String[ ] names, char[ ] dayInSched, int nbrCourses ) This method reads in all of the information for the program, and populates the arrays with the information. Before this method, all arrays are empty; after this method, all of the arrays are populated with the information read in by the user. It should read in nbrCourses number of courses. For each course, it should read the days of the week that the course meets (by calling getDays). For each day that the course meets, the method should call getStart and getEnd. getInfo should return the number of time slots that the user has in the schedule (e.g., if the user is taking 2 courses that both meet 3 times per week, this method returns 6).

public static void printSchedule(int[ ] startTime, int[ ] endTime, String[ ] names, char[ ] days, int length) This method prints the schedule with each index as a row from 0 to length. For example if the first class meeting is CPSC150, a 50 minute class at 9AM on Monday, the first line printed by printSchedule would display: CPSC150: M 09:00-09:50.

main You should use this main. Do not modify it:

public static void main(String[ ] args) { Scanner kbd = new Scanner(System.in); System.out.print("How many courses are you taking? "); int nbrCourses = kbd.nextInt( ); // there will be a max of 5 class meetings for each course, // so the size of the array is nbrCourses * 5 int[ ] startTime = new int[nbrCourses*5]; int[ ] endTime = new int[nbrCourses*5]; String[ ] names = new String[nbrCourses*5]; char[ ] days = new char[nbrCourses*5]; // the actual number of class meetings is nbrTimes int nbrTimes = getInfo(kbd, startTime, endTime, names, days, nbrCourses ); printSchedule(startTime, endTime, names, days, nbrTimes ); }

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

Step: 3

blur-text-image

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

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions