Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You have been asked to create a simple music store on a computer. The Music Store System will allow users to search for songs by

You have been asked to create a simple music store on a computer.

The Music Store System will allow users to search for songs by their title. The results of the search will be a description of the song (title, artist, album, genre, song length).

Users should also be able to add songs to the system, by providing a description. As well as edit and remove existing songs from the system.

For your project, you will first implement a Song class. The Song class will have the following fields:

title artist album genre (ex. Country, Pop, R&B, ) length (in minutes)

And the following methods:

a constructor with five parameters an accessor method for each field a mutator method for each field

You will then complete the implementation of the MusicStore application. The application uses an array of Song objects to represent the store. Each of the four features of the system (add, edit, delete, search) is implemented as a static method. There is also a static method sort which sorts the Song object array by the songs titles

addSong(): adds a new Song object to the Song array and then sorts the array by title using the static method sort.

editSong(): searches the Song array for a Song object by title, then allows the user to edit the fields of the Song object. If the title has been edited the array will be sorted again using the static method sort.

deleteSong(): searches the Song array for a Song object by title, then removes the Song object from the array.

searchStore(): searches the Song array for a Song object by title, using the static method binarySearch, then displays the full song description.

binarySearch(String title): implements a binary search on the Song object array (Do NOT use any search methods provided in the Java API).

sort(): sorts the Song object array by title using one of the sorting algorithms discussed in class (Do NOT use any sorting methods provided in the Java API).

Here is the given MusicStore.java code:

import java.util.Scanner;

public class MusicStore {

static final int MAX_SONGS = 50; // the maximum number of songs

static Song[] store = new Song[MAX_SONGS]; // the array of Song objects that represents the music store

static int numSongs = 0; // the number of songs currently in the music store (<= MAX_SONGS)

static Scanner keyboard = new Scanner(System.in); // Scanner for keyboard

public static void main(String[] args) {

System.out.println("Welcome to the Music Store System.");

char exit = 'N';

while (exit != 'Y') {

System.out.println("What would you like to do today?");

System.out.println("\t1. Add a song to the system.");

System.out.println("\t2. Edit a song description.");

System.out.println("\t3. Remove a song from the system.");

System.out.println("\t4. Search the music store.");

System.out.print("Enter the number that applies: ");

int choice = keyboard.nextInt();

keyboard.nextLine();

// Determine which command was selected.

switch (choice) {

case 1: // 1. Add a song to the system.

addSong();

break();

case 2: // 2. Edit a song description.

editSong();

break;

case 3: // 3. Remove a song from the system.

deleteSong();

break;

case 4: // 4. Search the store.

searchLibrary();

break;

default: // Invalid command

System.out.println("That is not a valid command.");

}

System.out.print("Would you like to exit, Y or N: ");

exit = keyboard.nextLine().charAt(0);

}

}

public static void addSong() {

System.out.println("You wish to add a song to the system.");

// Write code to add a Song object to the array store

sort(); // sort the array store

}

public static void editSong() {

System.out.println("You wish to edit a song description.");

System.out.print("What is the title of the song you wish to edit: ");

String title = keyboard.nextLine();

int index = binarySearch(title);

// Write code to edit the Song object at index

sort(); // sort the array store

}

public static void deleteSong() {

System.out.println("You wish to remove a song from the system.");

System.out.print("What is the title of the song you wish to delete: ");

String title = keyboard.nextLine();

int index = binarySearch(title);

// Write code to delete the Song object at index

}

public static void searchStore() {

System.out.println("You wish to search the store for a song.");

System.out.print("What is the title of the song you are looking for: ");

String title = keyboard.nextLine();

int index = binarySearch(title);

// Write code to display the song's description

}

public static int binarySearch(String title) {

// Implement binary search for array store, searching for title

}

public static void sort() {

// Implement a sorting algorithm to sort store according to title.

}

}

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

PC Magazine Guide To Client Server Databases

Authors: Joe Salemi

1st Edition

156276070X, 978-1562760700

More Books

Students also viewed these Databases questions

Question

5. Describe how contexts affect listening

Answered: 1 week ago