Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Set-Up : Create a new project in your Eclipse workspace named: Lab14 ? In the src folder, create a package named: edu.ilstu ? Import the

Set-Up :

Create a new project in your Eclipse workspace named: Lab14 ? In the src folder, create a package named: edu.ilstu ? Import the following file into the src folder of your project.: CDDriver.java , Import the input file, Collection.txt, into the root of your project.

Problem:

You will be writing a program to manage a list for a CD collection. Existing CDs are stored in a file. The data in the file (title and artist) is read into an array. The user will be presented with a menu with the following choices: add a new CD, display the list, or quit. You will create one new class and modifying existing classes. Be sure to write good comments as you will be generating JavaDoc API documents at the end of the lab.

Processing Instructions (write the code in this order) use the comments in the program to help with placement.

1. Create the new class called Song.java using the given class diagram. ? There is no default constructor, only the one sending in both title and artist. ? toString - define it so that it prints in the form: title by artist

2. Write the code for menu choice 2 to print the array to the screen. Doing this at the beginning allows you to test that the array has the correct values whenever a change has been made to it. You have been given the declarations for: MAX_ARRAY_SIZE

FILENAME

count (used to keep track of the number of elements currently in the array)

choice (used to capture the menu choice made by the user)

3 Write the prompt and read the menu choice from the user. There are two of these statements. One before the loop and another at the bottom of the loop. ? Run your program to test printing and reading the menu choice to be sure this is working correctly.

4. Open the file, read the input data from the file, create a Song object for each set of data, store the song object in the array. When done, close the file. Remember to use a try/catch when attempting to open the file. You will also be keeping track of how many Song objects are put into the array. ? Test this using menu choice 2 to see if everything loaded correctly.

5. Write the code for the following: ? write the output to SongData.txt. Use a try/catch for any exceptions.

6. Write the code for menu choice 1. ? Prompt the user, read the data from the keyboard and create a new Song object. ? Add the song to the array o Don't forget to add to the count so you know how many items are in the array ? Add the song to the file

7. Close the output file.

8. Run the code. Add a song, then use menu choice 2 to see if it was added correctly. If both prompts print at the same time, you may have to deal with the newline character between reading choice and the title.

CDDriver.java:

/* * File name: CDDriver.java * * Programmer: * ULID: * * Date: * * Class: * Lecture Section: * Lecture Instructor: * Lab Section: * Lab Instructor: */ package edu.ilstu;

import java.io.IOException;

/** * * * @author * */ public class CDDriver {

public static void main(String[] args) throws IOException { final int MAX_ARRAY_SIZE = 50; final String FILENAME = "Collection.txt";

CDOutput out = new CDOutput(); CDInput in = new CDInput();

int count = 0; // Counter to keep track of number of elements in the array int choice = 0; // Menu choice

// Create array to hold song collection

// Read the data from the input file into the array // Return the count for the elements currently in the array

// Open the file to append (this is the same file used for the input

// Print the menu

// Read the menu choice

while (choice != 3) { switch (choice) { case 1: // Read a new song to add to the collection from the keyboard

// Add the song to the array // Don't forget to increment the count

// Add the song to the file

break; case 2: // Print the list

break; default: System.out.println("Invalid menu choice. Please try again."); }

// Print the menu

// Read the menu choice

}

// Close the output file

}

}

COLLECTION.TXT

Ode to Joy Bach The Sleeping Beauty Tchaikovsky Lullaby Brahms Canon Bach Symphony No. 5 Beethoven The Blue Danube Waltz Strauss

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions

Question

Azure Analytics is a suite made up of which three tools?

Answered: 1 week ago