java - Search and Change only 1 number of a 2-D array -


let me first say, "lab" i'm doing class, , i've been working on second of 2 programs around 5 hours now, 2 of them stuck on 1 part. let me first give requirements of program maybe of make bit more sense.

a theater seating chart implemented two-dimensional array of ticket prices, this:

 10 10 10 10 10 10 10 10 10 10   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 20 10 10   10 10 20 20 20 20 20 20 10 10   10 10 20 20 20 20 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 

write program prompts users pick either seat or price. mark sold seats changing price 0. when user specifies seat, make sure available. when user specifies price, find seat price.

that's book's description, here's professor has given me go well.

required program components: initial seating chart in solution generated shown in example. solution assumes user enter row , seat start @ 1 , row 1 bottom front row. program should have @ least 3 static methods i) print array, ii) sellseatbyprice, , iii)sellseatbynumber. please declare , initialize array provided seat price values in main.

what i've gotten myself stuck on around 2 hours figuring out how change 1 of numbers of 2d array 0. entered seat 30, i've changed code around 5 times work , i'll either have every 30 change 0, or few of them, or none. main portion need on method called sellseatbyprice(). i'm not getting numbers change. here's current full code:

import java.util.*; public class theater {    static scanner in = new scanner(system.in);    static int[][] seatingchart;     public static void main(string[] args)    {        seatingchart = new int[][] {            { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },           { 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, 20, 10, 10 },            { 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },            { 10, 10, 20, 20, 20, 20, 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("welcome box office program.");                //introduction statements        system.out.println("please note seats arranged such that");        system.out.println("row 1, column 1, bottom front row.");        system.out.println("also, 0 denotes seat sold.");        printseats(seatingchart);        char response = 'y';        while ((response == 'y') || (response == 'y'))        {        system.out.print("pick seat <s>, price <p>, or quit <q>: ");        char choice = in.next().charat(0);            switch (choice)             {                case's':case's':                { sellseatbynumber(seatingchart);                    break; }                case'p':case'p':                { sellseatbyprice(seatingchart);                    break; }                case'q':case'q':                { system.out.print("thank you, come again!");                    system.exit(0); }                default:                { system.out.println("error: invalid choice."); }             }            system.out.print("would reserve seat (y/n)?: ");         response = in.next().charat(0);        }        system.out.print("thank you, come again!");        }     public static void printseats(int seatingchart[][])    {        for(int i=0; i<seatingchart.length; i++)        {            for(int j=0; j<seatingchart[i].length; j++)            {                if (j>0)                    system.out.print("\t");                    system.out.print(seatingchart[i][j]);            }            system.out.println();        }    }        public static void sellseatbyprice(int seatingchart[][])    {        system.out.print("please enter price seat like: ");        int price = in.nextint();        boolean found = false;        (int i=0;i<9;i++)          (int j=0;j<10;j++)             if ((found == true)&&(seatingchart[i][j]==price))             { seatingchart[i][j]=0; break; }          printseats(seatingchart);      }     public static void sellseatbynumber(int seatingchart[][])    {        system.out.println("enter row, enter seat number.");        system.out.print("what row sit on?:");        int row = in.nextint();        row = math.abs(row-9);        system.out.print("what seat of row sit in?:");        int col = in.nextint();        col -= 1;        if (seatingchart[row][col]!=0)        {            seatingchart[row][col] = 0;            printseats(seatingchart);            system.out.println("your seat has been reserved , reflected 0 on chart now.");        }        else { system.out.println("sorry, seat taken."); }    } } 

(i apologize if looks sloppy, it's 3am , can't think anymore)

your method must like:

public static void sellseatbyprice(int seatingchart[][]) {    system.out.print("please enter price seat like: ");    int price = in.nextint();    // boolean found = false;    out: (int i=0;i<9;i++)      (int j=0;j<10;j++)         if (seatingchart[i][j]==price)         { seatingchart[i][j]=0; break out; } // notice change      printseats(seatingchart);   } 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -