0% found this document useful (0 votes)
8 views3 pages

Nheil John Abrantes ITP 1 Introduction To Java Programming 10 Hands On Activity 1

The document contains a Java program for a bus seat reservation system. It initializes a 10-row seat layout using a 2D ArrayList and allows users to reserve seats by entering row and column numbers. The program continues to prompt for reservations until a negative number is entered, at which point it exits.

Uploaded by

Skatie Rider
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Nheil John Abrantes ITP 1 Introduction To Java Programming 10 Hands On Activity 1

The document contains a Java program for a bus seat reservation system. It initializes a 10-row seat layout using a 2D ArrayList and allows users to reserve seats by entering row and column numbers. The program continues to prompt for reservations until a negative number is entered, at which point it exits.

Uploaded by

Skatie Rider
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Nheil John Abrantes

ITP 1
Introduction to Java Programming

10 Hands on Activity 1 pdf

package SeatReservation;

import java.util.*;
import java.util.Scanner;
public class SeatReservation {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int n = 10;
int row=1;
int colmn=1;

ArrayList<ArrayList<String> > aList = new ArrayList<ArrayList<String> >(n);

ArrayList<String> a1 = new ArrayList<String>();


a1.add("*");
a1.add("*");
a1.add("*");
a1.add("*");
aList.add(a1);

ArrayList<String> a2 = new ArrayList<String>();


a2.add("*");
a2.add("*");
a2.add("*");
a2.add("*");
aList.add(a2);

ArrayList<String> a3 = new ArrayList<String>();


a3.add("*");
a3.add("*");
a3.add("*");
a3.add("*");
aList.add(a3);

ArrayList<String> a4 = new ArrayList<String>();


a4.add("*");
a4.add("*");
a4.add("*");
a4.add("*");
aList.add(a4);

ArrayList<String> a5 = new ArrayList<String>();


a5.add("*");
a5.add("*");
a5.add("*");
a5.add("*");
aList.add(a5);

ArrayList<String> a6 = new ArrayList<String>();


a6.add("*");
a6.add("*");
a6.add("*");
a6.add("*");
aList.add(a6);

ArrayList<String> a7 = new ArrayList<String>();


a7.add("*");
a7.add("*");
a7.add("*");
a7.add("*");
aList.add(a7);

ArrayList<String> a8 = new ArrayList<String>();


a8.add("*");
a8.add("*");
a8.add("*");
a8.add("*");
aList.add(a8);

ArrayList<String> a9 = new ArrayList<String>();


a9.add("*");
a9.add("*");
a9.add("*");
a9.add("*");
aList.add(a9);

ArrayList<String> a10 = new ArrayList<String>();


a10.add("*");
a10.add("*");
a10.add("*");
a10.add("*");
aList.add(a10);

while(row>0&&colmn>0){

System.out.println("Bus Seat Reservation:");

System.out.println("\tCol 1"+"\t\t\tCol 2"+"\t\t\tCol 3"+"\t\t\t\tCol 4\n");

for (int i = 0; i <10; i++) {


System.out.print("Row "+(i+1)+"\t|");
for (int j = 0; j < aList.get(i).size(); j++) {
System.out.print(aList.get(i).get(j) + "\t\t\t");
}
System.out.println();
}
System.out.print("Enter row and column number to reserve separated by space (Enter a
negative number to exit): " );

row = sc.nextInt();
colmn = sc.nextInt();

if(row>0&&colmn>0){
aList.get((row-1)).set((colmn-1), "X");
}
}
if(row < 0 || colmn < 0){
System.out.println("Project exit!");
sc.close();
}
}
}

You might also like