473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Error in my Program[URGENT]

i get
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at Live.main(Live.java:86)

The program given forward is the program that gives me the above error...please help
import java.io.*;
class Live
{
public static void main(String args[])throws IOException
{
float tot=0;
String ar[]=new String[25];
int aa[]=new int[25];
String ag[]=new String[15];
int gg[]=new int[15];
String at[]=new String[10];
int tt[]=new int[10];
String ac[]=new String[10];
int cc[]=new int[10];
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Choose the alternative for the place you would like to visit from the following:");
System.out.println("1: Big Bazaar");
System.out.println("2: Sgs Mall");
System.out.println("3: Central");
System.out.println("4: Pune Central");
String s=buf.readLine();
int a=Integer.parseInt(s);
switch(a)
{
case 1:System.out.println(" * Welcome to Big Bazaar *");
break;
case 2:System.out.println(" ** Welcome to Sgs Mall **");
break;
case 3:System.out.println(" * Welcome to Central *");
break;
case 4:System.out.println(" ** Welcome to Pune Central **");
break;
default:System.out.println("This place does not exist in the alternatives");
}
for(int hu=0;hu<=5;hu++)
{
System.out.println(" Choose the alternative to which section would you like to go to from our mall");
System.out.println("1: Clothes");
System.out.println("2: Grocery");
System.out.println("3: Eatables");
System.out.println("4: Stationery");
String t=buf.readLine();
int b=Integer.parseInt(t);
switch(b)
{
case 1:System.out.println("You are in the clothes section");
break;
case 2:System.out.println("You are in the Grocery section");
break;
case 3:System.out.println("You are in the eatable section");
break;
case 4:System.out.println("You are in the Stationery section");
break;
default:System.out.println("Sorry! This section does not exist in our mall");
}
if(b==1)
{
System.out.println("Sr no"+"\t\t"+"ITEM"+"\t\t\t\t\t"+"PRICE");
ar[0]="Any shirt from VAN HEUSEN brand";
ar[1]="Any shirt from LOUIS PHILIPPE brand";
ar[2]="Any shirt from WILLS LIFESTYLE brand";
ar[3]="Any party wear shirt PROVOGUE brand";
ar[4]="Any shirt from AUSTIN REED brand";
ar[5]="Blackberry flat front trousers(white)";
ar[6]="Blackberry flat front trousers(black)";
ar[7]="Any zodiac tie";
ar[8]="Life 3/4ths";
ar[9]="Life cargo";
ar[10]="Life Denim shorts";
ar[11]="Formal shirt for women from AUSTIN REED";
ar[12]="Ladies Denim Jeans";
ar[13]="Kashish Sarees";
ar[14]="Kashish Salwar Kameez";
ar[15]="BIBA Salwar Kameez";
ar[16]="Life Denim Shorts for Ladies";
ar[17]="Gini & Jony Top for girls";
ar[18]="Gini & Jony Dresses for girls";
ar[19]="Stop Girl Casual Dresses for girls";
ar[20]="Denim Shorts for girls below 7";
ar[21]="Tantra T-shirts for boys below 10";
ar[22]="Giny & Jony kids Shirt";
ar[23]="Giny & Jony Kids Jeans[boys]";
ar[24]="Giny & Jony Kids Jeans[girls]";
ar[25]="Socks for kids";
aa[0]=1599;
aa[1]=1499;
aa[2]=1399;
aa[3]=1499;
aa[4]=1499;
aa[5]=1595;
aa[6]=1695;
aa[7]=999;
aa[8]=999;
aa[9]=899;
aa[10]=699;
aa[11]=799;
aa[12]=999;
aa[13]=2395;
aa[14]=2295;
aa[15]=2295;
aa[16]=799;
aa[17]=599;
aa[18]=899;
aa[19]=549;
aa[20]=599;
aa[21]=225;
aa[22]=799;
aa[23]=999;
aa[24]=999;
aa[25]=135;
for(int r=0;r<=25;r++)
{
System.out.println((r+1)+"\t\t"+ar[r]+"\t\t\t\t\t"+aa[r]);
}
System.out.println("CHOOSE THE ITEM YOU WANT TO BUY FROM THE ABOVE ITEMS");
String see=buf.readLine();
int x=Integer.parseInt(see);
if(x==1)
tot+=aa[0];
else if(x==2)
tot+=aa[1];
else if(x==3)
tot+=aa[2];
else if(x==4)
tot+=aa[3];
else if(x==5)
tot+=aa[4];
else if(x==6)
tot+=aa[5];
else if(x==7)
tot+=aa[6];
else if(x==8)
tot+=aa[7];
else if(x==9)
tot+=aa[8];
else if(x==10)
tot+=aa[9];
else if(x==11)
tot+=aa[10];
else if(x==12)
tot+=aa[11];
else if(x==13)
tot+=aa[12];
else if(x==14)
tot+=aa[13];
else if(x==15)
tot+=aa[14];
else if(x==16)
tot+=aa[15];
else if(x==17)
tot+=aa[16];
else if(x==18)
tot+=aa[17];
else if(x==19)
tot+=aa[18];
else if(x==20)
tot+=aa[19];
else if(x==21)
tot+=aa[20];
else if(x==22)
tot+=aa[21];
else if(x==23)
tot+=aa[22];
else if(x==24)
tot+=aa[23];
else if(x==25)
tot+=aa[24];
else
tot+=aa[25];
System.out.println("Would you like to but anything else from this section");
String ss=buf.readLine();
if(ss.equalsIgnoreCase("Yes")==true)
continue;
else
break;
}
if(b==2)
{
System.out.println("Sr no"+"\t\t"+"ITEM"+"\t\t\t\t\t"+"PRICE");
ag[0]="1kg Potatoes";
ag[1]="1kg Tomatoes";
ag[2]="1kg Onion";
ag[3]="1kg Apples";
ag[4]="1kg Cabbage";
ag[5]="1kg Cauliflower";
ag[6]="1dozen Bannanas";
ag[7]="1dozen Chikoos";
ag[8]="1kg Watermelon";
ag[9]="1kg Strawberries";
ag[10]="1kg Sugar";
ag[11]="1kg Red Label Tea";
ag[12]="1kg Tata Salt";
ag[13]="5 Lemons";
ag[14]="1kg Rice";
ag[15]="1kg Wheat";
gg[0]=15;
gg[1]=20;
gg[2]=30;
gg[3]=80;
gg[4]=20;
gg[5]=40;
gg[6]=40;
gg[7]=60;
gg[8]=65;
gg[9]=150;
gg[10]=30;
gg[11]=200;
gg[12]=10;
gg[13]=10;
gg[14]=40;
gg[15]=25;
for(int q=0;q<=15;q++)
{
System.out.println((q+1)+"\t\t"+ag[q]+"\t\t\t\t\t"+gg[q]);
}
System.out.println("CHOOSE THE ITEM YOU WANT TO BUY FROM THE ABOVE ITEMS");
String go=buf.readLine();
int y=Integer.parseInt(go);
if(y==1)
tot+=gg[0];
else if(y==2)
tot+=gg[1];
else if(y==3)
tot+=gg[2];
else if(y==4)
tot+=gg[3];
else if(y==5)
tot+=gg[4];
else if(y==6)
tot+=gg[5];
else if(y==7)
tot+=gg[6];
else if(y==8)
tot+=gg[7];
else if(y==9)
tot+=gg[8];
else if(y==10)
tot+=gg[9];
else if(y==11)
tot+=gg[10];
else if(y==12)
tot+=gg[11];
else if(y==13)
tot+=gg[12];
else if(y==14)
tot+=gg[13];
else if(y==15)
tot+=gg[14];
else
tot+=gg[15];
System.out.println("Would you like to but anything else from this section");
String xx=buf.readLine();
if(xx.equalsIgnoreCase("Yes")==true)
continue;
else
break;
}
if(b==3)
{
System.out.println("Sr no"+"\t\t"+"ITEM"+"\t\t\t\t\t"+"PRICE");
at[0]="Pani Puri";
at[1]="Sev Puri";
at[2]="Ragda Puri";
at[3]="Club sandwich";
at[4]="Basket Chaat";
at[5]="Pav Bhaji";
at[6]="Plain Dosa";
at[7]="Masala Dosa";
at[8]="Idli Chatni";
at[9]="Veg Pizza";
at[10]="Veg Burger";
tt[0]=25;
tt[1]=25;
tt[2]=30;
tt[3]=20;
tt[4]=45;
tt[5]=60;
tt[6]=75;
tt[7]=95;
tt[8]=80;
tt[9]=125;
tt[10]=25;
for(int u=0;u<=10;u++)
{
System.out.println((u+1)+"\t\t"+at[u]+"\t\t\t\t\t"+tt[u]);
}
System.out.println("CHOOSE THE ITEM YOU WANT TO BUY FROM THE ABOVE ITEMS");
String ew=buf.readLine();
int w=Integer.parseInt(ew);
if(w==1)
tot+=tt[0];
else if(w==2)
tot+=tt[1];
else if(w==3)
tot+=tt[2];
else if(w==4)
tot+=tt[3];
else if(w==5)
tot+=tt[4];
else if(w==6)
tot+=tt[5];
else if(w==7)
tot+=tt[6];
else if(w==8)
tot+=tt[7];
else if(w==9)
tot+=tt[8];
else if(w==10)
tot+=tt[9];
else
tot+=tt[10];
System.out.println("Would you like to but anything else from this section");
String kk=buf.readLine();
if(kk.equalsIgnoreCase("Yes")==true)
continue;
else
break;
}
if(b==4)
{
System.out.println("Sr no"+"\t\t"+"ITEM"+"\t\t\t\t\t"+"PRICE");
ac[0]="Navneet A4 size notebooks(200 pgs)";
ac[1]="Navneet fullscape notebooks(200 pgs)";
ac[2]="Navneet Journals(200 pgs)";
ac[3]="Navneet small square maths notebook(200 pgs)";
ac[4]="Reynolds pen";
ac[5]="Add Gel pen";
ac[6]="Journal Sheets(1 dozen)";
ac[7]="Graph Paper(1 dozen)";
ac[8]="400 pages Diary";
ac[9]="Apsara Pencil Box";
ac[10]="Geometry Box";
cc[0]=15;
cc[1]=25;
cc[2]=49;
cc[3]=25;
cc[4]=15;
cc[5]=10;
cc[6]=6;
cc[7]=6;
cc[8]=75;
cc[9]=25;
cc[10]=120;
for(int n=0;n<=10;n++)
{
System.out.println((n+1)+"\t\t"+ac[n]+"\t\t\t\t\t"+cc[n]);
}
System.out.println("CHOOSE THE ITEM YOU WANT TO BUY FROM THE ABOVE ITEMS");
String es=buf.readLine();
int bo=Integer.parseInt(es);
if(bo==1)
tot+=cc[0];
else if(bo==2)
tot+=cc[1];
else if(bo==3)
tot+=cc[2];
else if(bo==4)
tot+=cc[3];
else if(bo==5)
tot+=cc[4];
else if(bo==6)
tot+=cc[5];
else if(bo==7)
tot+=cc[6];
else if(bo==8)
tot+=cc[7];
else if(bo==9)
tot+=cc[8];
else if(bo==10)
tot+=cc[9];
else
tot+=cc[10];
System.out.println("Would you like to but anything else from this section");
String jj=buf.readLine();
if(jj.equalsIgnoreCase("Yes")==true)
continue;
else
break;
}
System.out.println("Would you like to go to any other section");
String ss=buf.readLine();
if(ss.equalsIgnoreCase("Yes")==true)
continue;
else
break;
Nov 23 '10 #1
2 1191
improvcornartist
303 Expert 100+
You defined ar with a size of 25, but are trying to set 26 values.
Expand|Select|Wrap|Line Numbers
  1. String ar[]=new String[25]; //ar can hold 25 elements - ar[0] to ar[24]
  2. ar[25]="Socks for kids"; //this is the 26th element, which causes the error
  3.  
Nov 23 '10 #2
Dheeraj Joshi
1,123 Expert 1GB
Array in Java or zero indexed.

Regards
Dheeraj Joshi
Nov 23 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Daniel | last post by:
Hi, why i get an error as below after running the program. "There is already an open Data Reader associated with this connection which must be closed first." the original code that produce...
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
4
by: XML newbie: Urgent pls help! | last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it verifies the login information it should display the SessionID and enable some button . I appreciate your help and thanku...
1
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
4
by: Garimella | last post by:
Hi When I'm trying to write data to a file from a custom variable(contains group of string items) it is giving me Runtime Error 59: bad record length. Put #1, , ee_rec20 --this is the line...
14
by: James Wong | last post by:
Hi everybody, I'm facing a serious trouble relating to GDI+ generic error. The error message is "A Generic error occured in GDI+" and the following information is stored in Excepton object:...
4
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
4
by: musai | last post by:
I have created vb oracle application I installed oracle client in three machine. All machine was reconfigured after oracle installed I could see table and record set through sql plus sheet in...
1
by: niranjanapte | last post by:
hello In my assignment we asked to create classes like student, grade, semester, course all of them have constructors & methods. We have to create hashmap that contains key as student id & object...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.