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

inport java.util.Scanner; public class Project3 { public static String toTime(in

ID: 3741093 • Letter: I

Question

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 );
}

Explanation / Answer

import java.util.Scanner;

public class Project3 {

   public static String toTime(int time) {

      int pr=time/100;
      
      String str=String.format("%02d",pr);
      str+=":";
      int pr2=time%100;
      str=str+String.format("%02d",pr2);
       return str;
   }
  
   public static int getStart(Scanner kbd, String courseName, char day) {
      
       int startTime=kbd.nextInt();
       return startTime;

   }
  
   public static int calcEnd(int begin, int length) {
  
      
       int pr=begin/100;
          int pr2=begin%100;

          int len=pr2+length;
          while(len>60){
          
              if(len>60){
                  pr++;
                  len-=60;
              }
          
          
          }
      
       pr=pr*100;
       pr+=len;
       return pr;
   }
  
   public static int getEnd(Scanner kbd, int startTime, String courseName, char day) {
      
       int length=kbd.nextInt();
       return calcEnd(startTime, length);
      
   }
  
   public static String getDays(Scanner kbd, String className) {
  
       String days=kbd.nextLine();
      
       String daysInWeek="";
       for(int i=0;i<days.length();i++){
           if(days.charAt(i)=='M') daysInWeek+="Monday";
           else if(days.charAt(i)=='M') daysInWeek+="Monday";
           else if(days.charAt(i)=='T') daysInWeek+="Tuesday";
           else if(days.charAt(i)=='W') daysInWeek+="Wednesday";
           else if(days.charAt(i)=='H') daysInWeek+="Thursday";
           else if(days.charAt(i)=='F') daysInWeek+="Friday";
           else if(days.charAt(i)=='A') daysInWeek+="Saturday";
           else daysInWeek+="Sunday";
       }
       return daysInWeek;
   }
  
   public static int getInfo(Scanner kbd, int [ ] startTime, int[ ] endTime, String[ ] names, char[ ] dayInSched, int nbrCourses ) {

               int noOfcourses=kbd.nextInt();
             
               for(int i=0;i<startTime.length;i++){
                   toTime(startTime[i]);
                   getStart(kbd, names[i], dayInSched[i]);
                   calcEnd(startTime[i], endTime[i]);
                   getEnd(kbd, startTime[i], names[i], dayInSched[i]);
                   getDays(kbd, names[i]);
               }
      
             
       return noOfcourses;
   }
  
   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 );
      
       System.out.println(Project3.calcEnd(950,150));
      
  
   }

  
}