What's new

Help Pahelp mga Master (JAVA) 2.0 (Solve)

Status
Not open for further replies.

LonelyNinja

Forum Veteran
Elite
Joined
Sep 21, 2016
Posts
1,846
Reaction
1,502
Points
591
Age
21
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

Last edited:
indi po e. yun namn pong naka paloob na method sa booking() ang problema yung printSeat() at bookSeat().
 
Luh, bakit di ko alam yan? hahahaha nag jajava rin naman kami dati.
 
Status
Not open for further replies.

Similar threads

Back
Top