Guest User

Untitled

a guest
Nov 23rd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. //####################################################
  2. //# Patrick Freed's Amazing Time Machine #
  3. //# PF ATM #
  4. //# 2011 #
  5. //####################################################
  6. import java.util.Scanner;
  7. public class Time {
  8. public static void main(String args[]){
  9. Scanner input = new Scanner(System.in);
  10. System.out.println("What is the current hour?");
  11. int originalhour = input.nextInt();
  12. System.out.println("What is the current minute?");
  13. int originalminute = input.nextInt();
  14. System.out.println("AM or PM?");
  15. String originalampm = input.next();
  16. System.out.println("The current time is "+ originalhour + ":" + originalminute+ " " + originalampm+ ". Correct?");
  17. String answer = input.next();
  18. if (answer.compareToIgnoreCase("yes")== 1){
  19. main(null);
  20. if (originalampm.compareToIgnoreCase("PM")==0){
  21. originalhour+=12;}
  22. }
  23. int counter = 1;
  24. while (counter == 1){
  25. System.out.println("What is the hour of the next time you want to enter?");
  26. int newhour = input.nextInt();
  27. int copyofnewhour = newhour;
  28. System.out.println("What is the minute count of the next time you want to enter?");
  29. int newminute = input.nextInt();
  30. int copyofnewminute = newminute;
  31. System.out.println("AM or PM?");
  32. String newampm = input.next();
  33. System.out.println("The time you just entered is "+newhour+":"+newminute+" "+newampm+". Correct?");
  34. String answer2 = input.next();
  35. if (answer2.compareToIgnoreCase("no")== 0){
  36. counter++;}//if
  37. if (newampm.compareToIgnoreCase("PM")== 0 ){
  38. newhour += 12;}
  39.  
  40. elapsedTime(originalhour, originalminute, originalampm, newhour, newminute, newampm, copyofnewhour, copyofnewminute);
  41. }//while
  42.  
  43. }//main
  44. public static void elapsedTime(int oh, int om, String oampm, int nh, int nm, String nampm, int newhour, int newminute){
  45. if (nh<oh && nampm.compareToIgnoreCase("am")== 0 && oampm.compareToIgnoreCase("pm")== 0){
  46. nh+=12;}
  47. int finalhour = nh-=oh;
  48. int finalminute = nm-=om;
  49. if (finalminute < 0){
  50. finalhour-=1;
  51. finalminute = Math.abs(finalminute);
  52. finalminute = 60-finalminute;}
  53. if (finalhour > 12){
  54. finalhour-=12;}
  55. if (finalhour < 0){
  56. finalhour = Math.abs(finalhour);}
  57. System.out.println("The time between "+oh + ":" + om+ " " + oampm+" and "+newhour+":"+newminute+" "+nampm+ " is " + finalhour+" hour(s) and "+finalminute+ " minute(s).");
  58. main(null);
  59. }//elapsedTime
  60.  
  61.  
  62. }//Time
Add Comment
Please, Sign In to add comment