Results 1 to 2 of 2
- 11-27-2012, 08:12 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 17
- Rep Power
- 0
Need help, creating CD collection problem
in very need of help! having a hard time figuring this out! I know everything is very sloppy right now but any assistance is greatly appreciated!
Write a program to manage your collection of CDs
Define a class CD0000
Instance variables
private String title;
private String artist;
private double cost;
Methods
public CD0000 (String name, String singer, double price) // create a new CD
public String toString() //Returns a description of this CD.
Define another class CDCollection0000
Instance variables
private CD[] collection;
private int count; // number of CDs
private double totalCost;
Methods
public CDCollection0000 ()
public void addCD (String title, String artist, double cost) // create a CD, add it to the collection, increase the count by 1
public String toString() // Returns a report describing the CD collection.
Write a test program Ass9ID0000.java
Add your collection of CDs
Print out your collection
Optional
Your collection increases as time goes by. So if you initialize your collection of certain size, at some point you may find it is not large enough, what do you do? Define a new method
private void increaseSize ()
//-----------------------------------------------------------------
// Doubles the size of the collection by creating a larger array
// and copying the existing collection into it.
//-----------------------------------------------------------------
When you add a new CD, you may want to check if you already have one
public boolean inCollection(CD newCD)
Sample output
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
My CD Collection
Number of CDs: 4
Total cost: $61.75
Average cost: $15.44
CD List:
$14.95 Storm Front Billy Joel
$14.95 Come On Over Shania Twain
$17.95 Soundtrack Les Miserables
$13.90 Graceland Paul Simon
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
My CD Collection
Number of CDs: 6
Total cost: $97.69
Average cost: $16.28
CD List:
$14.95 Storm Front Billy Joel
$14.95 Come On Over Shania Twain
$17.95 Soundtrack Les Miserables
$13.90 Graceland Paul Simon
$19.99 Double Live Garth Brooks
$15.95 Greatest Hits Jimmy Buffet
Java Code:public class Ass9ID0000 { public static void main(String[] args) { CD0000 c1; c1 = new CD0000(); CDCollection0000 c2; c2 = new CDCollection0000(); System.out.println("My CD Collection"); System.out.println(); System.out.println("Number of CDs:" + c2.count); System.out.println("Total cost:" + c2.totalCost); System.out.println("Average cost: $" + c2.sum); System.out.println(); System.out.println("CD List:"); System.out.println(); System.out.println(); } }
Java Code:import java.util.*; public class CD0000 { private String name; private String singer; private double price; public String returnString; public double sum; Scanner keyboard = new Scanner(System.in); //Method public CD0000 () { } public void setname() { System.out.println("Whats the name of the CD?"); name = keyboard.nextLine(); return; } public void setsinger() { System.out.println("Whos the Singer?"); singer = keyboard.nextLine(); return; } public void setprice() { System.out.println("what was the cost of the CD?"); price = keyboard.nextDouble(); sum = sum + price; return; } public String getsinger() { return singer; } public String getname() { return name; } public double getprice() { return price; } //method String public String toString() { String returnString; returnString = "$" + price; returnString = returnString + name; returnString = returnString + singer; return returnString; } public String getString() { return returnString; } }Java Code:import java.util.*; public class CDCollection0000 { CD0000 c1 = new CD0000(); private String[] collection = new String[50]; public double totalCost; public double sum; Scanner keyboard = new Scanner(System.in); String music = c1.returnString; //Methods public CDCollection0000() { } public void addCD(String name, String singer, double price) { for (int index = 1; index < 50; index++) collection[index] = keyboard.nextLine(); } int count = collection.length; }
- 11-27-2012, 08:22 AM #2
Re: Need help, creating CD collection problem
Do you have a specific question?
Also, you didn't bother to return to the other three threads you started. Why should we expect any better behavior this time round?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Problem creating arrays
By JohnPringle83 in forum New To JavaReplies: 7Last Post: 05-06-2011, 11:01 PM -
problem creating new thread
By SeanieSortMeOut in forum Forum LobbyReplies: 2Last Post: 01-23-2011, 08:40 PM -
Thread collection problem
By FoxHound10 in forum Threads and SynchronizationReplies: 0Last Post: 11-23-2010, 06:44 PM -
Problem creating dialog box
By SeanC in forum New To JavaReplies: 2Last Post: 08-13-2010, 05:38 PM -
i am having a problem with creating graphics
By umpire43055 in forum AWT / SwingReplies: 3Last Post: 08-07-2009, 05:26 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks