• Post Reply Bookmark Topic Watch Topic
  • New Topic

Retrieving array element info/value using users selection  RSS feed

 
Ashly Martinez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
basically what i want to happen in the end is have the user select which item they want and have the corresponding array element print out. So if they choose "5" then "Garlic Bread" will print out. any help or tips are greatly appreciated! thanks

 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have got rid of the worst of the long lines in that code, and removed some of the blank lines which don't aid legibility.
You will soon understand why we recommend getting as much as possible out of the main method. That method will get so long before you get to the cheeseboard that it will be completely unmanageable.

Clever idea to have 0 in the array for no selection. That means you can enter 0. You need to get an int from the keyboard with your Scanner. Have you read the Scanner documentation? It tells you how to do that. Then you can use that number as the index for your array. You seem to be able to get the number of people in a party; why are you using nextLine() twice? Why don't you use the same technique to get the menu line number?

Have you not been taught to create a Dinner class and MenuLine classes? You could have a Meat class, a Vegetables class, a Dessert class, etc.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
O, that isn't an array. Sorry for misreading, but I think I have given you a hint.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!