Fitness.com
Advertisement
Go Back   Sports Forum > Community > The Pub

The Pub

Grab a beer, sit back and relax.


» Current Poll
Best 5 club teams in history of Football:
Liverpool 1977-1978 - 100.00%
1 Vote
Real Madrid 1956-1960 - 0%
0 Votes
Juventus 1985 - 0%
0 Votes
Milan 1989-1990 - 100.00%
1 Vote
Ajax 1971-1973 - 0%
0 Votes
Santos 1962-1963 - 0%
0 Votes
Torinho 1940's - 100.00%
1 Vote
Ajax 1995 - 0%
0 Votes
Flamengo 1981 - 100.00%
1 Vote
Benfica 1961-1962 - 100.00%
1 Vote
Total Votes: 1
You may not vote on this poll.
» Stats
Members: 48,606
Threads: 84,985
Posts: 1,031,250
Top Poster: Rindalik (4,430)
Welcome to our newest member, MariaTCTfunds
If you register for free, you will be able to post threads, vote on polls and lots more. If you have problems with the registration or logging in, please contact the administrator.

Reply
 
LinkBack Thread Tools Display Modes
Old 11-05-2007, 12:49 PM   Java Help.... thanks in advance ;) Post #1
Junior Member
 
Join Date: Oct 2005
Posts: 0
Rep Power: 0
BartMansss is infamous around these parts
Default Java Help.... thanks in advance ;)

Does anyone here know Java!!??

This is doing my head in. I have a very simple program looking like this:

import java.util.ArrayList;

public class Menu
{

private ArrayList items;
private ArrayList prices;

//Constructor
public Menu()
{

items = new ArrayList();
prices = new ArrayList();
String[] items = {"Pizza","Bread","Beans","Large Pizza","Small Pizza"};
double[] prices = {12.99,2.00,1.99,13.99,10.99};
}

//Methods

public void newItem(String item)
{
items.add(item);
}

public void getMenuItemDescription (int itemNumber)
{
System.out.println(items.get(itemNumber));

}

public void getMenuItems()
{
int count = 0;
while (count <= items.size())
{
System.out.println(items.get(count));
count++;
}
}

public void getMenuItemPrice(int itemNumber)
{
System.out.println(prices.get(itemNumber));
}

}

It compiles fine, but when I go to access any of the variables in either array, it crashed with an error message saying IndexOutOfBoundsException

I'm obviously doing something fundamnetaly wrong! Any ideas?

Thanks in advance
BartMansss is offline   Reply With Quote
Old 11-05-2007, 01:19 PM   Java Help.... thanks in advance ;) Post #2
Member
 
Join Date: Aug 2004
Posts: 155
Rep Power: 6
Abramovic is on a distinguished road
Default

Is this the only class you have? As there is no main method in this class.

As far as other problems are concerned, your not adding the Sting or double array items into ArrayLists items or prices. So just to be on the safe side try using a for loop to add things.
Abramovic is offline   Reply With Quote
Old 11-05-2007, 01:23 PM   Java Help.... thanks in advance ;) Post #3
Member
 
Join Date: Aug 2004
Posts: 155
Rep Power: 6
Abramovic is on a distinguished road
Default

Sorry to double post but you could try to convert the arrays into ArrayLists

Example:

// converting an array to an ArrayList, without Generics
String[] animals = { "bear", "cougar", "wolverine"};
ArrayList al = new ArrayList( Arrays.asList( animals ) );

// converting an ArrayList to an array without generics,
String[] predators = (String[])al.toArray( new String[ al.size() ] );
Abramovic is offline   Reply With Quote
Old 11-05-2007, 01:33 PM   Java Help.... thanks in advance ;) Post #4
Junior Member
 
Join Date: Oct 2005
Posts: 0
Rep Power: 0
BartMansss is infamous around these parts
Default

Christ im confused

In case you didnt guess programming is not my forte
BartMansss is offline   Reply With Quote
Old 11-05-2007, 01:36 PM   Java Help.... thanks in advance ;) Post #5
Junior Member
 
Join Date: Apr 2001
Posts: 0
Rep Power: 0
JK Galgreefe is infamous around these parts
Default

i don't get what you're trying to do with it to be honest. if you're trying to map the prices to the items wouldn't you be better off using a HashMap or an enum or something?
JK Galgreefe is offline   Reply With Quote
Reply

Go Back   Sports Forum > Community > The Pub

Bookmarks

Thread Tools
Display Modes


Similar threads to Java Help.... thanks in advance ;)
Thread Thread Starter Forum Replies Last Post
Java problem 10.5.2
Java problem 10.5.2: I couldnt install FM 08 i looked forums i couldnt...
AliGösterisli Football Manager 1 06-22-2008 07:47 AM
Luton Town Please Help. Thanks In Advance.
Luton Town Please Help. Thanks In Advance.: I am Luton as you will know. Can anyone tell me...
ShaunCpfc Scout Report 1 11-26-2007 07:16 PM
java problem which couldn`t resolved.
java problem which couldn`t resolved.: Hi.I purchased the game 11/11/07.I am trying to...
Reraslan Football Manager 0 11-12-2007 03:25 AM
apologies in advance im a newbie!
apologies in advance im a newbie!: Please can you choose a more appropriate topic...
Matt Jones Skinning Hideout 0 11-06-2005 08:24 PM
AbsoluteDeNoiser...Free Java machine denoiser
AbsoluteDeNoiser...Free Java machine denoiser: This is very interesting software and definitely...
Welles The Pub 0 03-04-2004 12:56 AM

More threads of BartMansss
Thread Date Forum Replies Last Post
Java Help.... thanks in advance ;)
Java Help.... thanks in advance ;): Does anyone here know Java!!?? This is doing...
11-05-2007 The Pub 4 11-05-2007 01:36 PM
A cool download
A cool download: .
07-08-2006 Scout Report 3 07-08-2006 11:51 PM
Is this ok?
Is this ok?: What if i just post a link to some good players...
07-08-2006 Scout Report 1 07-08-2006 11:35 PM
Closed
Closed: Why was my thread closed??
07-08-2006 Scout Report 1 07-08-2006 11:33 PM
BillyBob Thornton
BillyBob Thornton: Best budget player in the game really Buy...
07-08-2006 Scout Report 8 07-08-2006 11:30 PM

Other threads in forum The Pub
Thread Date Thread Starter Replies Last Post
Women's World Cup 2007. - It's a bit like 'Danny Baker's Goals And Gaffes' video
Women's World Cup 2007. - It's a bit like 'Danny Baker's Goals And Gaffes' video: Err yeah dunno if there's already a thread,...
09-10-2007 ACou2000 666 10-22-2007 11:54 PM
A serious work behaviour question
A serious work behaviour question: My brother works with me at a very well known...
10-16-2007 BamBamBam 56 10-17-2007 08:12 PM
No US Heroes Season 2 Thread?
No US Heroes Season 2 Thread?: Unless there is one ofc. Had no idea this starts...
09-24-2007 goon 55 09-25-2007 06:43 PM
Help me find a new Telly
Help me find a new Telly: Ok so my living room 28" widescreens on its last...
09-07-2007 Synthahols_for_Girls 2 09-08-2007 02:19 PM
wrinkle in time author dies at 88
wrinkle in time author dies at 88: read all the books when I was a kid. remember...
09-08-2007 Daaaaave 11 09-08-2007 10:12 AM

» Online Users: 31
2 members and 29 guests
efgh094, klmn823
Most users ever online was 2,128, 07-21-2008 at 08:27 PM.

All times are GMT +1. The time now is 06:42 PM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Fitness.com | Weight Loss | Training & Fitness | BodyBuilding | Chinese | Spanish | French | Germany | Italian | Friend Codes |
You are viewing Java Help.... thanks in advance ;).