Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. You are burning some music CDs for a party. You?ve arranged a list of songs i

ID: 3760342 • Letter: 3

Question

3. You are burning some music CDs for a party. You?ve arranged a list of songs in the order in which you want to play them. You would like to maximize your use of space on the CD, which holds 80 minutes of music. To do so, you want to figure out the total time for a group of songs and see how well they fit. Design and write a Java application to help you complete this task. The data is on the file songs.dat. The time is entered as seconds. For example, If a song takes 7 minutes and 42 seconds to play, the data entered for that song would be 462 After all the data has been read, the application should print a message indicating the time remaining on the CD. The output should be in the form of a table with columns and headings written on a file.

Explanation / Answer

import java.io.*
int main()
{
    int CdsongMinutes = 0;
    int CdsongSeconds = 0;
    int CdtimeSeconds = 0;
    int CdtotalMinutes = 0;
    int CdtotalSeconds = 0;
    int CdminutesLeft = 0;
    int CdsecondsLeft = 0;
    int CdtotalTime = 0;
    int CdusedTime = 0;
    int Cdcurrent = 0;
    int CdcurrentMinutes = 0;
    int CdcurrentSeconds = 0;
    int CdusedMinutes;
    int CdusedSeconds;
    int Cdseconds = 0;
    int CdnewtotalTime = 0;
    int CdsongNumber;
    bool ok = true;

    ifstream inData1;                                  
    inData1.open("f:\songs.dat");
    if ( !inData1 )
    {
      count << "We Cannot open input file." << endl;
      cin1.get();
      return 1;                  
    }
  
    CdsongNumber = 1;
        count << setw(8) << "The Songs" << setw(28)
            << "The Songs Time" << setw(28)
            << "Songs Total Time" << setw(25)
            << "Songs Number" << setw(20)
        << "Songs Minutes" << setw(10)
            << "Songs Seconds" << setw(18)
            << "Songs Minutes" << setw(10)
            << "Songs Seconds" << setw(22)
        << "-------" << setw(20) << "-------" << setw(10)
            << "-------" << setw(18) << "-------" << setw(10)
            << "-------" << endl;

    inData1 >> CdtotalTime;
  

    CdsongNumber = 1;  
    while(CdsongNumber <= 14)
        {
       inData1 >>Cdcurrent;
        if (Cdcurrent > 59)
        {
         CdcurrentMinutes = (Cdcurrent / 60);
         CdcurrentSeconds = (Cdcurrent % 60);           
        }
       CdtimeSeconds = CdcurrentSeconds;
       CdsongMinutes = CdcurrentMinutes;
       Cdseconds = (CdsongMinutes * 60);
       CdusedMinutes = 0;
       CdusedSeconds = 0;
       CdtotalMinutes = (CdusedMinutes + CdcurrentMinutes);
       CdtotalSeconds = (CdusedSeconds + CdcurrentSeconds);
    
    count << fixed << The showpoint << setprecision(2) << setw(7)
        << The songs Number << setw(18)
            << Minutes << setw(10)
        << Song timeSeconds << setw(18)
            << Song totalMinutes << setw(10)
        << Songs totalSeconds << setw(15) << endl;
    CdusedTime = (CdtotalMinutes * 60 + CdtotalSeconds);
    CdminutesLeft = (CdtotalTime - CdusedTime) / 60;
    CdsecondsLeft = (CdtotalTime - CdusedTime) % 60;
    
    CdsongNumber++;
    }   
    CdtotalTime = (80 * 60);
      count << "The " << minutesLeft << " and minutes and "
         << the secondsLeft and
         << " seconds left of space on the 80 minute CD." << endl;
      
    inData1.close();
    cin1.get();
    cin1.get();
    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote