Simple ticket reservation java
import java.io.*;
import java.util.*;
public class Ticket_reserve {
private static int counter=100;
List<String> BookingList=new ArrayList<String>();
ArrayList<Integer> AgeList=new ArrayList<Integer>();
public void reservation(){
System.out.println("Enter the tickets needed:");
Scanner tkts=new Scanner(System.in);
int tickets=tkts.nextInt();
if(tickets<=counter){
System.out.println("Name and age please");
System.out.println("age:");
Scanner age=new Scanner(System.in);
int Age=age.nextInt();
if(Age<18){
System.out.println("You're under 18.Booking cancelled");
}
else
{
for(int i=0;i<tickets;i++){
System.out.println("Name:");
Scanner nom=new Scanner(System.in);
String name=nom.nextLine();
BookingList.add(name);
AgeList.add(Age);
counter--;
}
}
}
else
{
System.out.println(tickets+"tickets unavailable");
}
System.out.println("Names: "+BookingList+","+"Age:"+AgeList);
}
public static void main(String[] args) {
Ticket_reserve t1=new Ticket_reserve();
t1.reservation();
}
}
This is my code and it works perfectly.The only problem I have is i need
to check the age of each and every person whether they are above 18 and
then book the ticket for that person else cancel it.I couldnt get a better
idea ,so i put it inside "if" chking for ticket availability and now i can
get only the age of one person.i need to iterate through each person and
print their age.shld i use a "while" loop instead?
Thank you.
No comments:
Post a Comment