I was wondering if I could get some quick help on some java code. I created an array and each position/seat has a specific 'price'. I need to write a program that asks the user to either pick a seat or price. I've already completed the first half of finding a specific seat location picked by the users input and replacing it with 0 but I've been having trouble with the second half of taking the users desired seat price and changing it to 0. There are multiple seats at the price they choose so I just need to pick a random one and change it to 0. I'll cut out a bunch of code to make it easier to read but basically what I need help with is towards the bottom:
Scanner in = new Scanner(System.in);
String seat = "";
String price = "";
int[][] seating = new int[][]
{
{ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
{ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
{ 10, 10, 20, 20, 20, 20, 20, 10, 10, 10 },
{ 10, 10, 20, 20, 20, 20, 20, 10, 10, 10 },
{ 10, 10, 20, 20, 20, 20, 20, 10, 10, 10 },
{ 10, 10, 20, 20, 30, 30, 20, 20, 10, 10 },
{ 20, 20, 30, 30, 40, 40, 30, 30, 20, 20 },
{ 20, 30, 30, 40, 50, 50, 40, 30, 30, 20 },
{ 30, 40, 50, 50, 50, 50, 50, 50, 40, 30 },
};
System.out.println("\nHere is a map of the current seating:\n");
printArray(seating);
System.out.println("\nWould you like to pick a seat or a price?\n");
String decision = in.nextLine();
if(decision.equals("price"))
{
System.out.println("\nWould you like to pay 10, 20, 30, 40, or 50 dollars?\n");
int pickedPrice = in.nextInt();
//HELP HERE //replace a random seat with the selected price to 0 in the array
}
I've only come here as a last resort as I've looked all over the place and couldn't find any help. Thanks in advance, I really appreciate it!
ArrayList<Seat>aand initialize it to empty. (3) Use a double loop to go throughseating. Every time a price matches the user's price, add the "row" and "seat number" of the seat to thea. (4) Usea.size()to get the number of entries N in theArrayList, and generate a random integer from 0 to N-1. (5) Usea.getto get theSeatfor the random number. That will give you the row and seat number, and then I think you can do the rest.