Hvad er der galt med følgende kode?!?
Hej - nedenfor er indsat lidt java kode - som får en fejmeddelelse. Bemærk at der er to klasser!public class Tunes
{
public static void main (String[] args)
{
CDCollection music = nev CDCollection ();
music.addCD ("Strom Front", "Billy Joel", 14.95, 10);
music.addCD ("Faith", "Anastacia", 12.30, 14);
music.addCD ("TLC", "TLC", 11.95, 17);
music.addCD ("BAD", "Michael Jackson", 18.95, 12);
System.out,println (music);
music.addCD ("It's not serius", "Jenifer LO", 18.95, 15);
music.addCD ("Marinus", "Anders Bagger", 11.95, 1);
System.out.println (music);
}
}
//*********************************************
//*********************************************
import java.text.NumberFormat;
public class CDCollection
{
private CD[] collection;
private int count;
private double totalCost;
public CDCollection()
{
collection = new CD[100];
count = 0;
totalCost = 0.0;
}
public void addCD (String title, String artist, double cost, int tracks)
{
if (count == collection.length)
increaseSize();
collection[count] = new CD (title, artist, cost, tracks);
totalCost += cost;
count++;
}
public String toString()
{
NumberFormat fmt = NumberFormat.getCurrencyInstance();
String report = "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n";
report += "Min CD Collection\n\n";
report += "Number of CDs: " + count + "\n";
report += "Total cost: " + fmt.format(totalCost) + "\n";
report += "Average cost: " + fmt.format(totalCost/count);
report += "\n\nCD List:\n\n";
for (int cd = 0; cd < count; cd++)
report += collection[cd].toString() + "\n";
return report;
}
private void increaseSize()
{
CD[] temp = new CD[collection.length *2];
for (int cd = 0; cd < collection.length; cd++)
temp[cd] = collection [cd];
collection = temp;
}
}
