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();
}
}