Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: What's wrong with my code? (Music store)

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation What's wrong with my code? (Music store)

    I'm creating a music store in Java, with everything categorized into genre. Each CD has a fixed quantity, which should decrease every time someone buys something. I tried, and failed epicly. Please help. My code:

    import java.io.*;
    public class CDMart
    {
    InputStreamReader read=new InputStreamReader(System.in);
    BufferedReader in=new BufferedReader(read);
    int GenreSelect;
    int SerialNo[]=new int [25];
    String Genre[]=new String[25];
    String ArtistName[]=new String[25];
    String AlbumName[]=new String[25];
    double Cost[]=new double[25];
    int Quantity[]=new int[25];
    int cart=0;
    int TotalCost=0;
    int country=0;
    int hiphop=0;
    int rock=0;
    int dubstep=0;
    int pop=0;

    int a1[]=new int[ 25];
    String b1[]=new String[ 25];
    String c1[]=new String[ 25];
    String d1[]=new String[ 25];
    double e1[]=new double[ 25];
    int f1[]=new int[ 25];
    void Genre_Select()throws IOException
    {

    System.out.println("Enter the number code of your desired genre to begin");
    System.out.println("1 \t Country");
    System.out.println("2 \t Hip-Hop");
    System.out.println("3 \t Pop");
    System.out.println("4 \t Dubstep");
    System.out.println("5 \t Rock");
    GenreSelect=Integer.parseInt(in.readLine());

    Display_Albums(GenreSelect);
    }

    void Display_Albums(int a)throws IOException
    {
    int i;int b=0, c=0, d=0, e=0, f=0;
    CDMart ob=new CDMart();
    if(a==1)
    {

    System.out.println("Albums available in Country genre are: ");
    System.out.println("Sr.No. \t Genre \t Artist Name \t Album Name \t Cost \t Quantity");
    for(i=0;i<5;i++)
    {
    b++;
    System.out.println(b+"\t Country"+ArtistName[i]+" \t "+AlbumName[i]+" \t "+Cost[i]+"\t"+Quantity[i]);
    }
    ob.Country();
    }
    else if(a==2)
    {

    System.out.println("Albums available in Hip-Hop genre are: ");
    System.out.println("Sr.No. \t Genre \t Artist Name \t Album Name \t Cost \t Quantity");
    for(i=5;i<10;i++)
    {
    c++;
    System.out.println(c+" \t Hip-Hop"+ArtistName[i]+" \t "+AlbumName[i]+" \t "+Cost[i]+" \t "+Quantity[i]);
    }
    Hiphop();
    }
    else if(a==3)
    {

    System.out.println("Albums available in Pop genre are: ");
    System.out.println("Sr.No. \t Genre \t Artist Name \t Album Name \t Cost \t Quantity");
    for(i=5;i<10;i++)
    {
    d++;
    System.out.println(d+"\t Pop"+ArtistName[i]+" \t "+AlbumName[i]+" \t "+Cost[i]+" \t "+Quantity[i]);
    }
    Pop();
    }
    else if(a==4)
    {

    System.out.println("Albums available in Dubstep genre are: ");
    System.out.println("Sr.No. \t Genre \t Artist Name \t Album Name \t Cost \t Quantity");
    for(i=5;i<10;i++)
    {
    e++;
    System.out.println(e+" \t Dubstep"+ArtistName[i]+" \t "+AlbumName[i]+" \t "+Cost[i]+" \t "+Quantity[i]);
    }
    Dubstep();
    }
    else
    {

    System.out.println("Albums available in Rock genre are: ");
    System.out.println("Sr.No. \t Genre \t Artist Name \t Album Name \t Cost \t Quantity");
    for(i=5;i<10;i++)
    {
    f++;
    System.out.println(f+" \t Rock"+ArtistName[i]+" \t "+AlbumName[i]+" \t "+Cost[i]+" \t "+Quantity[i]);
    }
    Rock();
    }
    }

    CDMart()
    {

    int i, b=0;
    for(i=0;i<25;i++)
    {
    if(i<5)
    {
    Genre[i]="Country";
    }
    else if(i>=5&&i<10)
    {
    Genre[i]="Hip-Hop";
    }
    else if (i>=10&&i<15)
    {
    Genre[i]="Pop";
    }
    else if(i>=15&&i<20)
    {
    Genre[i]="Dubstep";
    }
    else if(i>=20&&i<25)
    {
    Genre[i]="Rock";
    }

    SerialNo[i]=i+1;
    Quantity[i]=25;
    }
    ArtistName[0]="Jamie Johnson";
    AlbumName[0]="That Lonesome Song";
    Cost[0]=200;
    ArtistName[1]="Tim McGraw";
    AlbumName[1]="Live like You Were Dying";
    Cost[1]=200;
    ArtistName[2]="Alan Jackson";
    AlbumName[2]="Drive";
    Cost[2]=250;
    ArtistName[3]="Alison Krauss";
    AlbumName[3]="Raising Sand";
    Cost[3]=300;
    ArtistName[4]="Brad Paisley";
    AlbumName[4]="Mud On The Tires";
    Cost[4]=250;
    ArtistName[5]="Tupac Shakur";
    AlbumName[5]="Keep Ya Head Up";
    Cost[5]=200;
    ArtistName[6]="Wu-Tang Clan";
    AlbumName[6]="Enter the Wu-Tang(36 Chambers)";
    Cost[6]=300;
    ArtistName[7]="Public Enemy";
    AlbumName[7]="It Takes a Nation of Millions To Hold Us Back";
    Cost[7]=350;
    ArtistName[8]="Common Sense";
    AlbumName[8]="Ressurection";
    Cost[8]=200;
    ArtistName[9]="Notorious B.I.G";
    AlbumName[9]="Ready To Die";
    Cost[9]=250;
    ArtistName[10]="David Bowie";
    AlbumName[10]="Ziggy Stardust and the Spiders From Mars";
    Cost[10]=260;
    ArtistName[11]="ABBA";
    AlbumName[11]="Arrival";
    Cost[11]=320;
    ArtistName[12]="Jeff Buckley";
    AlbumName[12]="Grace";
    Cost[12]=340;
    ArtistName[13]="Michael Jackson";
    AlbumName[13]="Thriller";
    Cost[13]=350;
    ArtistName[14]="Lana Del Rey";
    AlbumName[14]="Born To Die";
    Cost[14]=270;
    ArtistName[15]="Oneiric";
    AlbumName[15]="Boxcutter";
    Cost[15]=200;
    ArtistName[16]="Pinch";
    AlbumName[16]="Underwater Dancehall";
    Cost[16]=240;
    ArtistName[17]="Skream";
    AlbumName[17]="Skream";
    Cost[17]=300;
    ArtistName[18]="Skrillex";
    AlbumName[18]="Scary Monsters and Nice Sprites";
    Cost[18]=240;
    ArtistName[19]="Burial";
    AlbumName[19]="Untrue";
    Cost[19]=250;
    ArtistName[20]="U2";
    AlbumName[20]="The Joshua Tree";
    Cost[20]=300;
    ArtistName[21]="The Beatles";
    AlbumName[21]="Rubber Soul";
    Cost[21]=250;
    ArtistName[22]="Pink Floyd";
    AlbumName[22]="Dark Side of the Moon";
    Cost[22]=200;
    ArtistName[23]="Nirvana";
    AlbumName[23]="Nevermind";
    Cost[23]=300;
    ArtistName[24]="Led Zeppelin";
    AlbumName[24]="Physical Graffiti";
    Cost[24]=250;

    }

    void Country()throws IOException
    {
    CDMart ob=new CDMart();
    System.out.println("Enter serial number of desired album");
    int AlbumSelect=Integer.parseInt(in.readLine());
    String c;int i;
    System.out.println("Enter quantity");
    int qt=Integer.parseInt(in.readLine());
    for(i=0;i<25;i++)
    {
    if(qt>Quantity[i])
    {
    System.out.println("Reenter quantity between 1 to "+Quantity[i]);
    qt=Integer.parseInt(in.readLine());
    }
    if(AlbumName[AlbumSelect-1]==AlbumName[i])
    {
    c=AlbumName[i]; country++;
    cart(i+1,"Country",ArtistName[i],AlbumName[i],Cost[i],(Quantity[i]-1));
    break;
    }
    }
    System.out.println("Do you wish to buy any more albums from this genre? Press 1 for yes, 2 for shopping from another genre, and 3 for cart");
    int a=Integer.parseInt(in.readLine());
    if(a==1)
    {
    Country();
    }
    else if(a==2)
    {
    System.out.println("You have made "+country+"purchases from this genre");
    Genre_Select();
    }
    else
    {

    checkout();
    }
    }

    void Hiphop()throws IOException
    {
    CDMart ob=new CDMart();
    System.out.println("Enter serial number of desired album");
    int AlbumSelect=Integer.parseInt(in.readLine());
    String c;
    int i;
    System.out.println("Enter quantity");
    int qt=Integer.parseInt(in.readLine());
    for(i=0;i<25;i++)
    {
    if(qt>Quantity[i])
    {
    System.out.println("Reenter quantity between 1 to "+Quantity[i]);
    qt=Integer.parseInt(in.readLine());
    }
    if(AlbumName[AlbumSelect-1]==AlbumName[i])
    {
    c=AlbumName[i];hiphop++;
    cart(i+1,"Hiphop",ArtistName[i],AlbumName[i],Cost[i],(Quantity[i]-1));
    break;
    }
    }
    System.out.println("Do you wish to buy any more albums from this genre? Press 1 for yes, 2 for shopping from another genre, and 3 for cart");
    int a=Integer.parseInt(in.readLine());
    if(a==1)
    {
    Hiphop();
    }
    else if(a==2)
    {
    System.out.println("You have made "+hiphop+"purchases from this genre");
    Genre_Select();
    }
    else
    {

    checkout();
    }

    }

    void Pop()throws IOException
    {
    CDMart ob=new CDMart();
    System.out.println("Enter serial number of desired album");
    int AlbumSelect=Integer.parseInt(in.readLine());
    String c;
    System.out.println("Enter quantity");
    int qt=Integer.parseInt(in.readLine());
    int i;
    for(i=0;i<25;i++)
    {
    if(qt>Quantity[i])
    {
    System.out.println("Reenter quantity between 1 to "+Quantity[i]);
    qt=Integer.parseInt(in.readLine());
    }
    if(AlbumName[AlbumSelect-1]==AlbumName[i])
    {
    c=AlbumName[i];pop++;
    cart(i+1,"Pop",ArtistName[i],AlbumName[i],Cost[i],(Quantity[i]-qt));
    break;
    }
    }
    System.out.println("Do you wish to buy any more albums from this genre? Press 1 for yes, 2 for shopping from another genre, and 3 for cart");
    int a=Integer.parseInt(in.readLine());
    if(a==1)
    {
    Pop();
    }
    else if(a==2)
    {
    System.out.println("You have made "+pop+"purchases from this genre");
    Genre_Select();
    }
    else
    {
    checkout();
    }

    }

    void Dubstep()throws IOException
    {
    CDMart ob=new CDMart();
    System.out.println("Enter serial number of desired album");
    int AlbumSelect=Integer.parseInt(in.readLine());
    String c;
    System.out.println("Enter quantity");
    int qt=Integer.parseInt(in.readLine());
    int i;
    for(i=0;i<25;i++)
    {
    if(qt>Quantity[i])
    {
    System.out.println("Reenter quantity between 1 to "+Quantity[i]);
    qt=Integer.parseInt(in.readLine());
    }
    if(AlbumName[AlbumSelect-1]==AlbumName[i])
    {
    c=AlbumName[i];dubstep++;
    cart(i+1,"Dubstep",ArtistName[i],AlbumName[i],Cost[i],(Quantity[i]-qt));
    break;
    }
    }
    System.out.println("Do you wish to buy any more albums from this genre? Press 1 for yes, 2 for shopping from another genre, and 3 for checkout");
    int a=Integer.parseInt(in.readLine());
    if(a==1)
    {
    Dubstep();
    }
    else if(a==2)
    {
    System.out.println("You have made "+dubstep+"purchases from this genre");
    Genre_Select();
    }
    else
    {

    checkout();
    }
    }

    void Rock()throws IOException
    {
    CDMart ob=new CDMart();
    System.out.println("Enter serial number of desired album");
    int AlbumSelect=Integer.parseInt(in.readLine()); String c;
    System.out.println("Enter quantity");
    int qt=Integer.parseInt(in.readLine());int i;
    for(i=0;i<25;i++)
    {
    if(qt>Quantity[i])
    {
    System.out.println("Reenter quantity between 1 to "+Quantity[i]);
    qt=Integer.parseInt(in.readLine());
    }
    if(AlbumName[AlbumSelect-1]==AlbumName[i])
    {
    c=AlbumName[i]; rock++;
    cart(i+1,"Rock",ArtistName[i],AlbumName[i],Cost[i],(Quantity[i]-qt));
    break;
    }
    }
    System.out.println("Do you wish to buy any more albums from this genre? Press 1 for yes, 2 for shopping from another genre, and 3 for cart");
    int a=Integer.parseInt(in.readLine());
    if(a==1)
    {
    ob.Rock();
    }
    else if(a==2)
    {
    System.out.println("You have made "+rock+"purchases from this genre");
    Genre_Select();
    }
    else
    {
    ob.checkout();

    }

    }

    void cart(int a,String b, String c, String d, double e, int f)
    {

    int i;

    for(i=cart;i< 25;i++)
    {
    a1[i]=a;
    b1[i]=b;
    c1[i]=c;
    d1[i]=d;
    e1[i]=e;
    f1[i]=f;
    System.out.println(a1[i]+" "+b1[i]+" "+c1[i]+" "+d1[i]+" "+e1[i]);
    TotalCost=TotalCost+f;
    cart++;
    }

    }

    void checkout()
    {
    System.out.println("Your bill is:"); int i;
    System.out.println("Sr.No \t Genre \t Artist Name \t Album Name \n Cost \n Quantity");
    for(i=0;i<10;i++)
    {
    System.out.println(a1[i]+" \t "+b1[i]+" \t "+c1[i]+" \t "+d1[i]+" \t "+e1[i]+" \t "+f1[i]);
    }
    System.out.println("Your total cost is Rs. "+TotalCost);
    }

    void main()throws IOException
    {
    CDMart ob=new CDMart();
    ob.Genre_Select();
    }
    }


  2. #2
    Member
    Join Date
    Sep 2013
    Posts
    64
    Thanks
    24
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with my code? (Music store)

    Haha, that's a lot of code to look at.

    I don't know what's wrong with it, but I'd recommend you edit / repost it using the CODE tags so it looks much more readable.

    Also might help if you posted the error messages you're getting.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: What's wrong with my code? (Music store)

    Please post your code in code tags (or other formatting tags). You can learn about that in the Announcements at the top of the page while I look at your code.

    --- Update ---

    Is the main() method included in the mass of code you posted supposed to be THE main() method? If so, the method signature is wrong. If not, is there another "driver" program to run/test your program?

  4. #4
    Junior Member
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with my code? (Music store)

    Quote Originally Posted by GregBrannon View Post
    Please post your code in code tags (or other formatting tags). You can learn about that in the Announcements at the top of the page while I look at your code.

    --- Update ---

    Is the main() method included in the mass of code you posted supposed to be THE main() method? If so, the method signature is wrong. If not, is there another "driver" program to run/test your program?
    ya, it's THE main()
    why is the signature wrong?

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: What's wrong with my code? (Music store)

    You should know this. It has to be static and void, and with minor variations (but why?), should look like:

    public static void main( String[] args )

Similar Threads

  1. Realtime signal processing in java concerning music
    By willemjar in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: June 27th, 2013, 06:34 AM
  2. How to load specific .midi (music) files from the cache?
    By Unseen in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 9th, 2012, 04:42 PM
  3. Replies: 5
    Last Post: August 28th, 2011, 04:48 PM
  4. Store HexDecimal Color Code in .properties file?
    By techwiz24 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 27th, 2011, 08:45 PM
  5. Music player problem
    By abhinavhardikar in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 9th, 2010, 08:41 PM