Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. import TerminalIO.KeyboardReader;
  2.  
  3. public class PartyDisc
  4. {
  5. public static void main(String[]args)
  6. {
  7.  
  8. int currentSong = 0, minutes = 0, totalMinutes = 0, seconds = 0, totalSeconds = 0, minutesLeft = 0, secondsLeft = 0;
  9.  
  10. KeyboardReader reader = new KeyboardReader();
  11.  
  12. do
  13. {
  14. currentSong = reader.readInt("\nPlease enter the song number: ");
  15. while(currentSong <= -1)
  16. {
  17. currentSong = reader.readInt("Invalid song number. Please re-enter a song number: ");
  18. }
  19. minutes = reader.readInt("Please enter the minutes of song " + currentSong + ": ");
  20. while(minutes <= -1 || minutes >= 80)
  21. {
  22. minutes = reader.readInt("Invalid number of minutes. Please re-enter minutes for song " + currentSong + ": " );
  23. }
  24. totalMinutes += minutes;
  25. seconds = reader.readInt("Please enter the seconds of song " + currentSong + ": ");
  26. while(seconds <= -1 || seconds > 59)
  27. {
  28. seconds = reader.readInt("Invalid number of seconds. Please re-enter seconds for song " + currentSong + ": " );
  29. }
  30. totalSeconds += seconds;
  31.  
  32. if(totalSeconds == 60)
  33. {
  34. totalSeconds = 0;
  35. totalMinutes = totalMinutes + 1;
  36. }
  37. if(totalMinutes >= 80 && totalSeconds >= 59)
  38. {
  39. System.out.print("Max amount of music has been stored");
  40. totalMinutes = 80;
  41. totalSeconds = 59;
  42. currentSong = 0;
  43. }
  44. System.out.println("Song #" + currentSong + ", " + minutes + " minutes and " + seconds + " seconds.");
  45. System.out.println("The total time is " + totalMinutes + " minutes and " + totalSeconds + " seconds.");
  46.  
  47. }while(currentSong != 0);
  48. minutesLeft = 80 - totalMinutes;
  49. secondsLeft = 59 - totalSeconds;
  50. System.out.println("\nThere are " + minutesLeft + " minutes and " + secondsLeft + " seconds left on the CD.");
  51.  
  52.  
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement