Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. import java.util.*;
  2. /**
  3. * This is Assignment 5 for CS114. It is able to calculate the charge of a babysitting job, given the following:
  4. *
  5. *
  6. * @Justin Mills (your name)
  7. * @9/25/2010 (a version number or a date)
  8. *
  9. * The following is the logic used for this program:
  10. * If H1>H2
  11. Then
  12. reject, all babysitting jobs must end within the same day
  13. elseif
  14. continue
  15.  
  16. Military time calculator uses hour1,hour2,min1 and min2 to deduce total amount of time.
  17. Result is set to variables finalH and finalM
  18.  
  19. If finalM >=20
  20. Then
  21. finalH+1=newH
  22. elseif
  23. finalH=newH
  24.  
  25. If hour2>=22
  26. Then
  27. If hour1=>22
  28. Then
  29. 9.5(newH)=bhourlyCharge
  30. elseif
  31. ((hour2+1)-22)9.5=bhourlyCharge
  32. (22-newH)6.75=hourlyCharge
  33.  
  34. elseif
  35. (newH)6.75=hourlyCharge
  36.  
  37. bhourlyCharge+hourlyCharge=total
  38. total/100=cashtotal
  39.  
  40. System.out.println("Actual time spent: finalH hours and finalM minutes")
  41. System.out.println("Total hours charged: newH")
  42. System.out.println("Fee charged: $cashtotal")
  43. */
  44.  
  45. public class TimeTester {
  46.  
  47. public static void main(String[] args) {
  48. Scanner cin = new Scanner(System.in);
  49. int time1, time2, time1h, time2h, time1m, time2m;
  50.  
  51. System.out.print("Pick a first time! [0000-2359] ");
  52. time1= cin.nextInt();
  53. System.out.print("Pick a second time! [0000-2359] ");
  54. time2= cin.nextInt();
  55.  
  56. while(time1 > 2359){
  57. System.out.println("Entered value is not 4 digits long, please enter again.");
  58. time1=cin.nextInt();
  59. }
  60.  
  61. time1h = time1 / 100;
  62. time1m = time1 % 100;
  63.  
  64. while (time1h > 23|| time1h < 0 || time1m > 59|| time1m < 0){
  65. System.out.print("Pick a first time! [0000-2359] ");
  66. time1= cin.nextInt();
  67. if (time1h > 23|| (time1h < 0))
  68. 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.
  69. if (time1h > 59|| time1h < 0)
  70. 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.
  71. }
  72.  
  73. while(time2 > 2359){
  74. System.out.println("Entered value is not 4 digits long, please enter again.");
  75. time2=cin.nextInt();
  76. }
  77.  
  78. time2h = time2 /100;
  79. time2m = time2 % 100;
  80.  
  81. while (time2h > 23|| time2h < 0 || time2m > 59|| time2m < 0){
  82. System.out.print("Pick a first time! [0000-2359] ");
  83. time2= cin.nextInt();
  84. if (time2h > 23|| (time2h < 0))
  85. 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.
  86. if (time2h > 59|| time2h < 0)
  87. 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.
  88. }
  89.  
  90. //below sets the results of the conversation to the names used in the final output of the program.
  91. Operations OP = new Operations();
  92. System.out.println("Actual time spent: "+ OP.timeEH(time1h,time2h) + " hours and "+OP.timeEM(time1m,time2m)+" minutes.") ;
  93. OP.minLeft(time1m, time2m, time1h, time2h);
  94. System.out.println("Total hours charged: " + OP.newH + " hour(s)");
  95.  
  96.  
  97. System.out.println("Fee charged: $" +OP.cashCalc(time1h, time2h)+ "!");
  98. }
  99.  
  100.  
  101. //System.out.println("Fee charged: $" +OP.cashCalc(time1h, time2h)+ "!");
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement