Your code is useless, throw it away. Here's something to get you started.
A class called record:
public class Record{
private final String name;
private final String artist;
private final int cost;
public String getName(){
return name;
}
public String getArtist(){
return artist;
}
public int getCost(){
return cost;
}
public Record(final String name, final String artist, final int cost){
super();
this.name = name;
this.artist = artist;
this.cost = cost;
}
}
A method to calculate the cost of a record collection (no, this should not use int, but I've got to leave some work for you to do):
public static int calculateCostOfRecordCollection(
final Collection<Record> records){
int cost = 0;
for(final Record record : records){
cost += record.getCost();
}
return cost;
}
And some test code:
public static void main(final String[] args){
final Collection<Record> records =
Arrays.asList(
new Record("The Beatles", "White Album", 25),
new Record("Roxy Music", "Stranded", 27),
new Record("Bjork", "Debut", 25),
new Record("David Bowie", "ChangesBowie", 39)
);
System.out.println(calculateCostOfRecordCollection(records));
}
Output:
116