(Solved) : ~~~~~~~cddriver Class~~~~~~~~~ Import Javaioioexception Author Public Class Cddriver Publi Q42477108 . . .

$9.00

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 th

WHILE (choice != 3) CASE choice WHEN 1: READ data for new song from keyboard ADD the new song object to the array INCREMENT c

Run your program to test getting the menu choice to be sure this is working correctly. 4. Open the file, read the input data

~~~~~~~CDDriver class~~~~~~~~~

import java.io.IOException;

/**
* <insert class description here>
*
* @author
*
*/
public class CDDriver
{

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

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

// Create array to hold song collection

// Create TextMenu object for menu (this may involve writingmultiple lines of code)

// Read the data from the input file into the array
// Count the elements currently in the array

// Get the menu choice

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

// 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.”);
}

// Get the menu choice

}

}

}

———————————————————————————–

~~~~~~~~TextMenu class~~~~~~~~

import java.util.*;

public class TextMenu
{
private String [] menuItems;

/**
* @param menuItems
* An array of Strings that represent the various menu labels. Thearray
* must be the exact size to hold the number of menu itemsdesired.
*/
public TextMenu(String[] menuItems)
{
this.menuItems = menuItems;
}

/**This method displays the menu and gets a choice from the user.The choice
* is validated.
*
* @param scan A Scanner object attached to the keyboard for userinput
* @return
* A number between 1 and the number of menu items, representing theuser’s choice
*/
public int getChoice(Scanner scan)
{
int choice;
String input;

this.displayMenu();
System.out.print(“Please enter your choice(1-” + menuItems.length +”): “);
input = scan.next();
choice = this.validateChoice(input);
while (choice == -1)
{
System.out.println(“That is not a valid choice. Please tryagain.”);
System.out.print(“Enter a number between 1 and ” + menuItems.length+ “: “);
input = scan.next();
choice = this.validateChoice(input);
}
return choice;
}

// displays the menu to the screen
private void displayMenu()
{
System.out.println();
System.out.println();
for (int i = 0; i < menuItems.length; i++)
{
System.out.println(” ” + (i+1) + ” ” + menuItems[i]);
}
System.out.println();
}

// validates the menu choice
private int validateChoice(String input)
{
int choice;
try
{
choice = Integer.parseInt(input);
}
catch (NumberFormatException e)
{
choice = -1;
}
if (choice < 1 || choice > menuItems.length)
{
choice = -1;
}
return choice;
}
}

————————————————————————–

~~~~~collection.txt~~~~~

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

Please let me know if you have any questions

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 modify an existing class. Class diagram and main algorithm Song – title:String – artist:String + Song (String title, String artist) + toString(): String all getters and setters main algorithm CREATE array of Song objects CREATE TextMenu object READ music collection into array choice = get menu choice using TextMenu object WHILE (choice != 3) CASE choice WHEN 1: READ data for new song from keyboard ADD the new song object to the array INCREMENT count WRITE the new song data to the file WHEN 2: PRINT the array OTHERWISE: PRINT “Invalid menu choice. Please try again” END CASE PRINT menu choice = get menu choice using TextMenu object END WHILE CLOSE output file END MAIN 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 . 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. Review the Text Menu class, and write code to create a TextMenu object with appropriate menu choices. Call the appropriate method to display the menu and get the user’s choice before the loop and at the bottom of the loop. Run your program to test getting 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. Show transcribed image text 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 modify an existing class. Class diagram and main algorithm Song – title:String – artist:String + Song (String title, String artist) + toString(): String all getters and setters main algorithm CREATE array of Song objects CREATE TextMenu object READ music collection into array choice = get menu choice using TextMenu object
WHILE (choice != 3) CASE choice WHEN 1: READ data for new song from keyboard ADD the new song object to the array INCREMENT count WRITE the new song data to the file WHEN 2: PRINT the array OTHERWISE: PRINT “Invalid menu choice. Please try again” END CASE PRINT menu choice = get menu choice using TextMenu object END WHILE CLOSE output file END MAIN 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 . 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. Review the Text Menu class, and write code to create a TextMenu object with appropriate menu choices. Call the appropriate method to display the menu and get the user’s choice before the loop and at the bottom of the loop.
Run your program to test getting 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.

Expert Answer


Answer to ~~~~~~~CDDriver class~~~~~~~~~ import java.io.IOException; /** * * * @author * */ public class CDDriver { public static …

Description

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 th

WHILE (choice != 3) CASE choice WHEN 1: READ data for new song from keyboard ADD the new song object to the array INCREMENT c

Description

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle

Contact us

Tips and Tricks

You will always receive notifications. They will inform when a draft is ready, when you receive a chat message from your writer, or when the final paper is uploaded.

Track your projects

By using the account dashboard you can check your available funds, view order history, or check current order progress.