Question: Part II: CD Download the following files: FileIOException.java //has the following public interface: FileIO.java //has the following public interface: o FileIO(String fileName, int operation) //either

Part II: CD Download the following files: FileIOException.java //has the following public interface:

FileIO.java //has the following public interface:

o FileIO(String fileName, int operation) //either FileIO.FOR_READING or FileIO.FOR_WRITING

o boolean EOF() //has the end of the file been reached?

o String readLine()

o void writeLine(String line) o void close() //close the file when you are done, especially when writing to a file

Song.java //constructor takes the title and the length of the Song as Strings

CD.java //the year is the search key Complete the CD class by extending KeyedItem. Set the year of the CD as the key field (use the primitive wrapper class for integers, the Integer class). Make sure that there is no setYear method in your CD class to ensure that the key is immutable. A getYear method is not necessary as KeyedItem already has a getKey method. Write the following two methods:

public Song getSong(int index)

public void addSong(String title, String length) //create the song and then add it

// FileIOException.java

public class FileIOException extends RuntimeException { public FileIOException(String message) { super(message); } }

//Song.java

//an immutable class public final class Song { private String title; private int length; private static String cr = " "; private static DecimalFormat fmt = new DecimalFormat("00");

public Song(String title, String length) { this.title = title;

String[] pieces = length.split(":"); String minutes = pieces[0]; String seconds = pieces[1]; int min = Integer.parseInt(minutes); int sec = Integer.parseInt(seconds); this.length = 60*min + sec; }

public void writeSong(FileIO file, int count) { String temp = "

" + fmt.format(count) + ""; temp += title + ""; temp += (length / 60) + ":" + fmt.format(length % 60) + ""; temp += "";

file.writeLine(" " + temp); }

public String getTitle() { return title; }

public int getLength() { return length; }

}

//CD.java

import java.util.ArrayList; /eed another import

public class CD extends KeyedItem { private String title; private String img; private ArrayList songs; private int numTracks; //used by addSong private int rating;

public CD (String title, String artist, int year, int rating, int tracks) { //complete the constructor with respect to extending KeyedItem

this.title = title; img = artist + " - " + title + ".jpg"; numTracks = tracks; songs = new ArrayList();

if (rating > 0 && rating

public Song getSong(int index) {

}

//create the song and then add it public void addSong(String title, String length) { }

//No work below

public int getNumberOfTracks() { return songs.size(); }

public String getTitle() { return title; }

public int getRating() { return rating; }

public String toString() { return title + " " + getKey() + " " + rating + " " + getNumberOfTracks(); }

public void writeCD(FileIO file) { if (rating == 10) { file.writeLine("

  • " + "" + title + "" + "
  • "); } else { file.writeLine("
  • " + title + "
  • "); }

    file.writeLine("

    "); file.writeLine("
      "); file.writeLine("
    • Year: " + getKey() + "
    • "); file.writeLine("
    • Rating: " + rating + "
    • "); file.writeLine("
    • Tracks:
    • ");

      file.writeLine("

      "); file.writeLine(""); int count = 0; for (Song song : songs) { file.writeLine(""); song.writeSong(file, ++count); file.writeLine(""); } file.writeLine("
      Track TitleLength
      ");

      file.writeLine("

    "); } }

    Step by Step Solution

    There are 3 Steps involved in it

    1 Expert Approved Answer
    Step: 1 Unlock blur-text-image
    Question Has Been Solved by an Expert!

    Get step-by-step solutions from verified subject matter experts

    Step: 2 Unlock
    Step: 3 Unlock

    Students Have Also Explored These Related Databases Questions!