Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import TerminalIO.KeyboardReader;
- public class PartyDisc
- {
- public static void main(String[]args)
- {
- int currentSong = 0, minutes = 0, totalMinutes = 0, seconds = 0, totalSeconds = 0, minutesLeft = 0, secondsLeft = 0;
- KeyboardReader reader = new KeyboardReader();
- do
- {
- currentSong = reader.readInt("\nPlease enter the song number: ");
- while(currentSong <= -1)
- {
- currentSong = reader.readInt("Invalid song number. Please re-enter a song number: ");
- }
- minutes = reader.readInt("Please enter the minutes of song " + currentSong + ": ");
- while(minutes <= -1 || minutes >= 80)
- {
- minutes = reader.readInt("Invalid number of minutes. Please re-enter minutes for song " + currentSong + ": " );
- }
- totalMinutes += minutes;
- seconds = reader.readInt("Please enter the seconds of song " + currentSong + ": ");
- while(seconds <= -1 || seconds > 59)
- {
- seconds = reader.readInt("Invalid number of seconds. Please re-enter seconds for song " + currentSong + ": " );
- }
- totalSeconds += seconds;
- if(totalSeconds == 60)
- {
- totalSeconds = 0;
- totalMinutes = totalMinutes + 1;
- }
- if(totalMinutes >= 80 && totalSeconds >= 59)
- {
- System.out.print("Max amount of music has been stored");
- totalMinutes = 80;
- totalSeconds = 59;
- currentSong = 0;
- }
- System.out.println("Song #" + currentSong + ", " + minutes + " minutes and " + seconds + " seconds.");
- System.out.println("The total time is " + totalMinutes + " minutes and " + totalSeconds + " seconds.");
- }while(currentSong != 0);
- minutesLeft = 80 - totalMinutes;
- secondsLeft = 59 - totalSeconds;
- System.out.println("\nThere are " + minutesLeft + " minutes and " + secondsLeft + " seconds left on the CD.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement