Results 1 to 2 of 2
  1. #1
    snobbysteven is offline Member
    Join Date
    Oct 2012
    Posts
    17
    Rep Power
    0

    Exclamation 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;
    
       
    
      }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Need help, creating CD collection problem

    Quote Originally Posted by snobbysteven View Post
    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!
    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?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Problem creating arrays
    By JohnPringle83 in forum New To Java
    Replies: 7
    Last Post: 05-07-2011, 12:01 AM
  2. problem creating new thread
    By SeanieSortMeOut in forum Forum Lobby
    Replies: 2
    Last Post: 01-23-2011, 09:40 PM
  3. Thread collection problem
    By FoxHound10 in forum Threads and Synchronization
    Replies: 0
    Last Post: 11-23-2010, 07:44 PM
  4. Problem creating dialog box
    By SeanC in forum New To Java
    Replies: 2
    Last Post: 08-13-2010, 06:38 PM
  5. i am having a problem with creating graphics
    By umpire43055 in forum AWT / Swing
    Replies: 3
    Last Post: 08-07-2009, 06:26 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •