Commit 43fb16b8 authored by alexandru.radulesc's avatar alexandru.radulesc

Added comments

parent 4b062ccc
...@@ -3,13 +3,13 @@ import java.util.Scanner; ...@@ -3,13 +3,13 @@ import java.util.Scanner;
public class Yeyey1 { public class Yeyey1 {
static Scanner input = new Scanner(System.in); //We're just setting up the input for now; static Scanner input = new Scanner(System.in); //We're just setting up the input for now;
static String[] seat = new String[100]; static String[] seat = new String[100];//Seat array
static int j=0,k=0,mainSeatNumber=0,classRead; static int j=0,k=0,mainSeatNumber=0,classRead;//Seat number and seat class, both inputs from the user
static String personName; static String personName;// name, destination and city, will be printed on the boarding pass
static String destination; static String destination;
static String currentCity; static String currentCity;
static String[] planeName = new String[28]; static String[] planeName = new String[28];
static int bookAgain = 1; static int bookAgain = 1;// variable to check if the user wants to book another seat
public static void main(String[] args) { public static void main(String[] args) {
...@@ -20,7 +20,7 @@ public class Yeyey1 { ...@@ -20,7 +20,7 @@ public class Yeyey1 {
{ {
seat[i] = "0" + String.valueOf(i+1); seat[i] = "0" + String.valueOf(i+1);
} }
} }//here we set up the numbers for the seats
for(int i = 0; i<28; i++) for(int i = 0; i<28; i++)
{ {
...@@ -30,38 +30,35 @@ public class Yeyey1 { ...@@ -30,38 +30,35 @@ public class Yeyey1 {
} }
else else
planeName[i] = "FL" + (i + 1); planeName[i] = "FL" + (i + 1);
} }//here we set up the flight names
GiveInfo(); GiveInfo();//here we ask the user for his info
while(true) while(true)
{ {
if(bookAgain == 1) if(bookAgain == 1)//if the user wishes to book
{ {
System.out.println(""); System.out.println("");
System.out.println("For First Class please input 1"); System.out.println("For First Class please input 1");
System.out.println("For Business Class please input 2"); System.out.println("For Business Class please input 2");
System.out.println("For Economy Class please input 3"); System.out.println("For Economy Class please input 3");
classRead = input.nextInt(); classRead = input.nextInt();//we ask for his class
BookSeats(classRead); BookSeats(classRead);//and pass it over to booking the respective seat
System.out.println(""); System.out.println("");
System.out.println("Would you like to book another seat? 0 = no / 1 = yes"); System.out.println("Would you like to book another seat? 0 = no / 1 = yes");
bookAgain = input.nextInt(); bookAgain = input.nextInt();//ask the user if he wishes to book again
} }
else if(bookAgain == 0) else if(bookAgain == 0)//if not, we show his boarding pass and exit
{ {
ShowBoardingPass(); ShowBoardingPass();
System.out.println("Have a good day!"); System.out.println("Have a good day!");
break; break;
} }
} }
} }
public static void BookSeats(int mainClass) //Method for adding the seats and displaying them yey public static void BookSeats(int mainClass) //Method for asking the user for his seat number
{ {
if(mainClass == 1) if(mainClass == 1)
...@@ -87,16 +84,15 @@ public class Yeyey1 { ...@@ -87,16 +84,15 @@ public class Yeyey1 {
} }
} }
public static void AssignSeats(int start, int finish) public static void AssignSeats(int start, int finish)//method for assigning seats and adding the changes to
{ { //them (if they're occupied)
for(int i = start;i<finish;i++) for(int i = start;i<finish;i++)//start and finish are assigned in the ShowSeats method
{ {
if(k<9) if(k<9)
{ {
if(j<3) if(j<3)
{ {
if(i<9) System.out.print("[" + seat[i] + "]"); System.out.print("[" + seat[i] + "]");
else System.out.print("[" + seat[i] + "]");
j++; j++;
} }
if(j==3) if(j==3)
...@@ -122,7 +118,7 @@ public class Yeyey1 { ...@@ -122,7 +118,7 @@ public class Yeyey1 {
System.out.println("---------------FIRST CLASS----------------"); System.out.println("---------------FIRST CLASS----------------");
System.out.println(""); System.out.println("");
AssignSeats(0,18); AssignSeats(0,18);//for efficiency we only modify the seats in the respective class, instead of rewriting all of them
System.out.println(""); System.out.println("");
System.out.println("--------------BUSINESS CLASS--------------"); System.out.println("--------------BUSINESS CLASS--------------");
...@@ -137,24 +133,23 @@ public class Yeyey1 { ...@@ -137,24 +133,23 @@ public class Yeyey1 {
AssignSeats(45,90); AssignSeats(45,90);
} }
public static void OccupySeats() public static void OccupySeats()//method for displaying the occupied seats
{ {
mainSeatNumber = input.nextInt(); mainSeatNumber = input.nextInt();
if(seat[mainSeatNumber - 1] !="XX") if(seat[mainSeatNumber - 1] !="XX")//we verify if the seat is already taken
{ {
seat[mainSeatNumber - 1] = "XX"; seat[mainSeatNumber - 1] = "XX";//if not, occupy it and show the seats
ShowSeats(); ShowSeats();
} }
else else
{ {
System.out.println("Seat is already occupied"); System.out.println("Seat is already occupied");//if it is, tell the user the seat is occupied
} }
} }
public static void GiveInfo() public static void GiveInfo()//method for taking the user's info and displaying the seats for the first time
{ {
System.out.println("Welcome to our online booking system"); System.out.println("Welcome to our online booking system");
System.out.print("Please enter your name: "); System.out.print("Please enter your name: ");
personName = input.nextLine(); personName = input.nextLine();
System.out.print("Please enter your city: "); System.out.print("Please enter your city: ");
...@@ -164,15 +159,15 @@ public class Yeyey1 { ...@@ -164,15 +159,15 @@ public class Yeyey1 {
ShowSeats(); ShowSeats();
} }
public static void ShowBoardingPass() public static void ShowBoardingPass()//method for displaying the boarding pass
{ {
System.out.println(""); System.out.println("");
System.out.println(" -------------BOARDING PASS-----------------"); System.out.println(" -------------BOARDING PASS-----------------");
System.out.println(" Name: " + personName + " ------------------"); System.out.println(" Name:---------- " + personName );
System.out.println(" Current City: " + currentCity + " ---------"); System.out.println(" Current City:-- " + currentCity);
System.out.println(" Destination: " + destination + " ----------"); System.out.println(" Destination:--- " + destination );
System.out.println(" Seat: " + mainSeatNumber + " --------"); System.out.println(" Seat:---------- " + mainSeatNumber);
System.out.println(" Flight: " + planeName[0] + " -----------------"); System.out.println(" Flight:-------- " + planeName[0]);
System.out.println(" -------------------------------------------"); System.out.println(" -------------------------------------------");
System.out.println(""); System.out.println("");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment