❓ Help Pahelp mga Master (JAVA) 2.0 (Solve)

Status
Not open for further replies.

LonelyNinja

Forum Veteran
import java.util.Scanner;
public class Main
{
private static String seat[][];
public static void main(String[] args) {
booking();
}


public static void Bus() {
seat=new String[10][4];
for(int i=0;i<10;i++) {
for(int j=0;j<4;j++) {
seat[j]="*";
}
}
}
public static void bookSeat(int row,int col) {
if(seat[row][col].equals("X"))
System.out.println("Seat already booked!");
else {
seat[row][col]="X";
System.out.println("Seat booked successfully!");
}
}

public static void printSeat() {
System.out.println("Bus Seat Reservation:");
String str=String.format("%15s %6s %6s %6s %6s", "","Col 1","Col 2","Col 3","Col 4");
System.out.println(str);
for(int i=0;i<10;i++) {
str=String.format("%15s", "Row "+(i+1));
for(int j=0;j<4;j++) {
if(j==0)
str+=String.format("%6s", "|"+seat[j]);
else
str+=String.format("%6s", seat[j]);
}
System.out.println(str);
}
}

public static void booking() {
int row,col;
Scanner sc=new Scanner(System.in);
while(true) {
printSeat();
System.out.print("Enter row and column number to reserve separated by space (Enter a negative number to exit): ");
row=sc.nextInt();
if(row<1)
break;
col=sc.nextInt();
if(col<1) {
break;
}else if(row>10 || col>4) {
System.out.println("Invalid seat number!");
}else {
bookSeat(row-1,col-1);
}
}
sc.close();
}
}

ERROR:

1610722064436.png

Output:


1610722009673.png

yun pong pdf ay yun po yung mismong activity

Salamat po..
 

Attachments

Luh, bakit di ko alam yan? hahahaha nag jajava rin naman kami dati.
 
Status
Not open for further replies.

Similar threads

About this Thread

  • 10
    Replies
  • 674
    Views
  • 3
    Participants
Last reply from:
PHC-DarkJaVa

Online now

Members online
976
Guests online
1,343
Total visitors
2,319

Forum statistics

Threads
2,277,053
Posts
28,973,948
Members
1,229,697
Latest member
librengsabit01
Back
Top