Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Test {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- String [][] seats = {
- { " *"," *", " *", " *" },
- { " *"," *", " *", " *" },
- { " *"," *", " *", " *" },
- { " *"," *", " *", " *" },
- { " *"," *", " *", " *" },
- { " *"," *", " *", " *" },
- { " *"," *", " *", " *" },
- { " *"," *", " *", " *" },
- { " *"," *", " *", " *" },
- { " *"," *", " *", " *" }
- };
- int choiceSeat[] = {0,0};
- // Ito yung do loop. Nilagay sa loob para mag loloop lang hanggang true yung while sa baba check mo.
- do{
- System.out.println("Bus Seat Reservation: ");
- System.out.println("\t\tCol 1 \t Col 2 \t Col 3 \t Col 4");
- for(int row = 0; row < seats.length; row++){
- if((row+1) != 10){
- System.out.print("Row " + (row + 1) + " |");
- }else{
- System.out.print("Row " + (row + 1) + "|");
- }
- for(int column = 0; column < seats[row].length; column++){
- System.out.print( " " + seats[row][column] + "\t\t" );
- }
- System.out.println();
- }
- System.out.print("Enter row and column number to reserve separated by space (Enter a negative number to exit): ");
- String NumSchoice;
- NumSchoice = in.nextLine();
- String[] StrSchoice = NumSchoice.split(" ");
- for(int i = 0; i < StrSchoice.length; i++){
- choiceSeat[i] = Integer.parseInt(StrSchoice[i]);
- }
- if(choiceSeat[0] < 0){
- System.out.println("Program exit!");
- }else{
- seats[choiceSeat[0] - 1][choiceSeat[1] - 1] = "X";
- }
- }while (choiceSeat[0] > 0);
- //Eto yung while. Hanggat Mas malaki sa 0 yung value magrurun siya. Meaning pag negative nilagay mo na input titigil yung program
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement