Question: I'm having trouble trying to code the closest time to 240 without using arrays or loops. Can you please help me in the right direction



I'm having trouble trying to code the closest time to 240 without using arrays or loops. Can you please help me in the right direction of what i need
here is my code so far
public class PlayList {
public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Enter a song Title: "); String title = scan.nextLine(); System.out.print("Enter a song artist: "); String artist = scan.nextLine(); System.out.print("Enter a song album: "); String album = scan.nextLine(); System.out.print("Enter play time (mm:ss):"); String playTime = scan.nextLine(); //======================================================================== System.out.print("Enter a song Title: "); String title1 = scan.nextLine(); System.out.print("Enter a song artist: "); String artist1 = scan.nextLine(); System.out.print("Enter a song album: "); String album1 = scan.nextLine(); System.out.print("Enter play time (mm:ss):"); String playTime1 = scan.nextLine(); //======================================================================== System.out.print("Enter a song Title: "); String title2 = scan.nextLine(); System.out.print("Enter a song artist: "); String artist2 = scan.nextLine(); System.out.print("Enter a song album: "); String album2 = scan.nextLine(); System.out.print("Enter play time (mm:ss):"); String playTime2 = scan.nextLine(); //======================================================================== //Print int index = playTime.indexOf(':'); int Song1playtime = 60 * Integer.parseInt(playTime.substring(0, index)) + Integer.parseInt(playTime.substring(index + 1)); int index1 = playTime1.indexOf(':'); int Song1playtime1 = 60 * Integer.parseInt(playTime1.substring(0, index1)) + Integer.parseInt(playTime1.substring(index1 + 1)); int index2 = playTime2.indexOf(':'); int Song1playtime2 = 60 * Integer.parseInt(playTime2.substring(0, index2)) + Integer.parseInt(playTime2.substring(index2 + 1)); Song Song1= new Song(title,artist, album, Song1playtime); Song Song2= new Song(title1,artist1, album1, Song1playtime1); Song Song3= new Song(title2,artist2, album2, Song1playtime2); double totalTime = Song1.getPlayTime() + Song2.getPlayTime() + Song3.getPlayTime(); double AveragePlayTime = totalTime/3; DecimalFormat df = new DecimalFormat(".##"); System.out.println("Average play time for songs: "+df.format(AveragePlayTime)); int min = 240; int closestTimeToFourMin = (min); int timeSong1 = (closestTimeToFourMin-Song1playtime); int timeSong2 = (closestTimeToFourMin-Song1playtime1); int timeSong3 = (closestTimeToFourMin-Song1playtime2); System.out.println("========================================================================================"); System.out.println("Title Artist Album Time"); System.out.println("========================================================================================"); System.out.println("Song with play time closest to 240 secs is:" ); if (Song1playtime > Song1playtime1 && Song1playtime > Song1playtime2 && Song1playtime1 > Song1playtime2 ) { System.out.println(Song3); System.out.println(Song2); System.out.println(Song1); } else if (Song1playtime > Song1playtime1 && Song1playtime > Song1playtime2 && Song1playtime1 Song1playtime && Song1playtime1 > Song1playtime2 && Song1playtime > Song1playtime2 ) { System.out.println(Song3); System.out.println(Song1); System.out.println(Song2); } else if (Song1playtime1 > Song1playtime && Song1playtime1 > Song1playtime2 && Song1playtime Song1playtime && Song1playtime2 > Song1playtime1 && Song1playtime > Song1playtime1 ) { System.out.println(Song2); System.out.println(Song1); System.out.println(Song3); } else if (Song1playtime2 > Song1playtime && Song1playtime2 > Song1playtime1 && Song1playtime
}
}
IMPORTANT: DO NOT use a loop, ArrayLists, or arrays to read/create your Songs. We will discuss how to do this later, but please don't over complicate things now. 3. Find Song With Play Time Closest to 4 Minutes Determine which song has play time closest to 4 minutes and print the title of that song formatted as shown in the output below. Song with play time closest to 240 secs is: Big Jet Plane Program Input (1) Last Tango in Paris Gotan Project Hotel Costes 05:50 Where you end Moby Hotel 3:18 Big Jet Plane Julia Stone Down the Way 3:54 Expected Output (1) Enter title: Enter artist: Enter album: Enter play time (mm:ss): Enter title: Enter artist: Enter album: Enter play tim e (mm:ss): Enter title: Enter artist: Enter album: Enter play time (mm:ss): Average play time for songs: 260.67 Song with play time closest to 240 secs: Big Jet Plane ===== Title Artist Album Time ==== Where you end Big Jet Plane Last Tango in Paris Moby Julia Stone Gotan Project Hotel Down the Way Hotel Costes 198 234 350 =================== Your Outut (1)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
