Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- /**
- * This is Assignment 5 for CS114. It is able to calculate the charge of a babysitting job, given the following:
- *
- *
- * @Justin Mills (your name)
- * @9/25/2010 (a version number or a date)
- *
- * The following is the logic used for this program:
- * If H1>H2
- Then
- reject, all babysitting jobs must end within the same day
- elseif
- continue
- Military time calculator uses hour1,hour2,min1 and min2 to deduce total amount of time.
- Result is set to variables finalH and finalM
- If finalM >=20
- Then
- finalH+1=newH
- elseif
- finalH=newH
- If hour2>=22
- Then
- If hour1=>22
- Then
- 9.5(newH)=bhourlyCharge
- elseif
- ((hour2+1)-22)9.5=bhourlyCharge
- (22-newH)6.75=hourlyCharge
- elseif
- (newH)6.75=hourlyCharge
- bhourlyCharge+hourlyCharge=total
- total/100=cashtotal
- System.out.println("Actual time spent: finalH hours and finalM minutes")
- System.out.println("Total hours charged: newH")
- System.out.println("Fee charged: $cashtotal")
- */
- public class TimeTester {
- public static void main(String[] args) {
- Scanner cin = new Scanner(System.in);
- int time1, time2, time1h, time2h, time1m, time2m;
- System.out.print("Pick a first time! [0000-2359] ");
- time1= cin.nextInt();
- System.out.print("Pick a second time! [0000-2359] ");
- time2= cin.nextInt();
- while(time1 > 2359){
- System.out.println("Entered value is not 4 digits long, please enter again.");
- time1=cin.nextInt();
- }
- time1h = time1 / 100;
- time1m = time1 % 100;
- while (time1h > 23|| time1h < 0 || time1m > 59|| time1m < 0){
- System.out.print("Pick a first time! [0000-2359] ");
- time1= cin.nextInt();
- if (time1h > 23|| (time1h < 0))
- System.out.println("Incorrect value for hours. Please try again with a value greater than or equal to zero or no greater than 23."); //This check is in place to prevent the hours value from exceeding 23 (because 24:00 doesn't "exist", and less than zero also doesn't exist.
- if (time1h > 59|| time1h < 0)
- System.out.println("Incorrect value for minutes. Please try again with a value greater than or equal to zero or no greater than 59."); //This check is in place to prevent the minutes value from exceeding 59 (because XX:60 doesn't "exist", and less than zero also doesn't exist.
- }
- while(time2 > 2359){
- System.out.println("Entered value is not 4 digits long, please enter again.");
- time2=cin.nextInt();
- }
- time2h = time2 /100;
- time2m = time2 % 100;
- while (time2h > 23|| time2h < 0 || time2m > 59|| time2m < 0){
- System.out.print("Pick a first time! [0000-2359] ");
- time2= cin.nextInt();
- if (time2h > 23|| (time2h < 0))
- System.out.println("Incorrect value for hours. Please try again with a value greater than or equal to zero or no greater than 23."); //This check is in place to prevent the hours value from exceeding 23 (because 24:00 doesn't "exist", and less than zero also doesn't exist.
- if (time2h > 59|| time2h < 0)
- System.out.println("Incorrect value for minutes. Please try again with a value greater than or equal to zero or no greater than 59."); //This check is in place to prevent the minutes value from exceeding 59 (because XX:60 doesn't "exist", and less than zero also doesn't exist.
- }
- //below sets the results of the conversation to the names used in the final output of the program.
- Operations OP = new Operations();
- System.out.println("Actual time spent: "+ OP.timeEH(time1h,time2h) + " hours and "+OP.timeEM(time1m,time2m)+" minutes.") ;
- OP.minLeft(time1m, time2m, time1h, time2h);
- System.out.println("Total hours charged: " + OP.newH + " hour(s)");
- System.out.println("Fee charged: $" +OP.cashCalc(time1h, time2h)+ "!");
- }
- //System.out.println("Fee charged: $" +OP.cashCalc(time1h, time2h)+ "!");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement