Question: program already written below need help with methods. thank you ********Listen.Java public class Listen { public static void main(String[] args) { Records music = new
program already written below need help with methods. thank you
********Listen.Java
public class Listen {
public static void main(String[] args)
{
Records music = new Records();
music.addMp3("King Creole", "Elvis Presley", 14.99, 11);
music.addMp3("Lady in Satin", "Billie Holiday", 13.95, 11);
music.addMp3("Go Bo Diddley", "Bo Diddley", 12.95, 12);
music.addMp3("Small hours", "Frank Sinatra", 17.90, 16);
System.out.println(music);
music.addMp3("Blue Train", "John Coltrane", 14.56, 5);
music.addMp3("Miles Ahead", "Miles Davis", 11.99, 10);
System.out.println(music);
}
}
*****Records.Java
import java.text.NumberFormat;
public class Records
{
private Mp3[] collection;
private int count;
private double totalCost;
public Records()
{
collection = new Mp3[100];
count = 0;
totalCost = 0.0;
}
public void addMp3(String title, String artist, double cost, int tracks)
{
if (count == collection.length)
increaseSize();
collection[count] = new Mp3 (title, artist, cost, tracks);
totalCost += cost;
count++;
}
public String toString()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();
String report = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ";
report += "My Mp3 Collection ";
report += "Number of Mp3s: " + count + " ";
report += "Total cost: " + fmt.format(totalCost) + " ";
report += "Average cost: " +fmt.format(totalCost/count);
report += " Mp3 List: ";
for (int Mp3 = 0; Mp3 < count; Mp3++)
report += collection[Mp3].toString() + " ";
return report;
}
private void increaseSize()
{
Mp3[] temp = new Mp3[collection.length * 2];
for (int Mp3 = 0; Mp3 < collection.length; Mp3++)
temp[Mp3] = collection[Mp3];
collection = temp;
}
}
******Mp3.Java
import java.text.NumberFormat;
public class Mp3
{
private String title, artist;
private double cost;
private int tracks;
public Mp3(String name, String singer, double price, int numTracks)
{
title = name;
artist = singer;
cost = price;
tracks = numTracks;
}
public String toString()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();
String description;
description = fmt.format(cost) + "\t" + tracks + "\t";
description += title + "\t" + artist;
return description;
}
}
-Add two more mp3s of your choice to the collection
-Create a int variable index in listen.java. This value will be used to get one title from the collection.
------------------------------------------------------------------------------
Add this code to mp3.java (a getter):
public String getTitle()
{
return title;
}
------------------------------------------------------------------------------
Add this code to Records.java:
-
public String findTitle (int i)
{
return (collection[i].getTitle());
}
-----------------------------------------------------------------------------
Add this code to listen.java:
-Use a loop to allow user to enter 0 thru number of mp3s Added to select and list/display a Title of mp3 in the list. (example below is using the number entered called index)
If value entered is valid then do this line of code System.out.println(music.findTitle(index));
Index is used as the value entered, if value entered not valid try again. Allow loop to end!
If the value = 1, then Lady in Satin will displayed.
-Add the code to add up the costs in the collection and display the value. Yes, there is already a totalCost but need more All three java classes need code added
-Place this code in a for loop in Records.java and add the necessary code to the other two java files shown below. look at the for loop in toString()
total = total + (collection[mp3].getCost());
-In listen.java will ask for the total and print the total at end of program Total cost for collection:
-In mp3.java will give the the cost hence [hint:] getCost()
--------------------------------------------------------------------------------------------------------------------------------
Write a method to find most expensive mp3.
Write a method to find mp3 with most tracks
Print out results.
Modify current output and add prints.
-------------------------------------
My Mp3 Collection
Number of Mp3s: 4
Total cost: $59.79
Average cost: $14.95
Mp3 List:
$14.99 11 King Creole Elvis Presley
$13.95 11 Lady in Satin Billie Holiday
$12.95 12 Go Bo Diddley Bo Diddley
$17.90 16 Small Hours. Frank Sinatra
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
My Mp3 Collection
Number of Mp3s: 6
Total cost: $86.34
Average cost: $14.39
Mp3 List:
$14.99 11 King Creole Elvis Presley
$13.95 11 Lady in Satin Billie Holiday
$12.95 12 Go Bo Diddley Bo Diddley
$17.90 16 Small Hours. Frank Sinatra
$14.56 5 Blue Train John Coltrane
$11.99 10 Miles Ahead Miles Davis
-------------------------------------
My Mp3 Collection
Number of Mp3s: 8
Total Cost: $120.24
Average Cost: $15.03
Mp3 Listing:
$14.99 11 King Creole Elvis Presley
$13.95 11 Lady in Satin Billie Holiday
$12.95 12 Go Bo Diddley Bo Diddley
$17.90 16 Small hours Frank Sinatra
$14.56 5 Blue Train John Coltrane
$11.99 10 Miles Ahead Miles Davis
$14.95 12 After School Chuck Berry
$18.95 12 Elvis P Elvis Presley
enter number (-1 to quit) :
9
not valid, try again
enter number (-1 to quit) :
5
Miles Ahead
enter number (-1 to quit) :
3
Small hours
enter number (-1 to quit) :
2
Go Bo Diddley
enter number (-1 to quit) :
2
Go Bo Diddley
enter number (-1 to quit) :
-1
Total cost for collection is: 120.24
Most expensive mp3: Elvis P
Mp3 with most tracks: Small Hours
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
