Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

JAVA PROGRAM 5

import java.io.*;

import java.util.*;

import java.text.ParseException;

import java.text.SimpleDateFormat;

class PassengerDetails

int passenger_id;

String passenger_name,gender;

int passenger_age;

String train;

String tickets;

String password;

PassengerDetails(int id,String name,int age,String gen,String tname,String tkts,String pass)

this.passenger_id = id;

this.passenger_name = name;

this.passenger_age = age;

this.gender = gen;

this.train = tname;

this.tickets = tkts;

this.password = pass;

PassengerDetails(String pass)

this.password = pass;

}
class Program5

static int count;

static

count = 5;

static public void main(String args[])throws IOException,InterruptedException, ParseException

PassengerDetails[] obj;

obj = new PassengerDetails[5];

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

welcome();

Program5 var = new Program5();

var.initializeValues(obj);

char choice;

do

menu();

System.out.print("Enter your choice : ");

int ch = Integer.parseInt(br.readLine());

switch(ch)

case 1:

welcome();

System.out.println(" ");

System.out.println("ENTER YOUR LOGIN CREDENTIALS...");

System.out.print("\nYour Login ID (Passenger ID) : ");

int id = Integer.parseInt(br.readLine());

System.out.print("Your Password : ");

String pass = br.readLine();

int i;

String pass1;
int flag=0;

for(i=0;i<obj.length;i++)

if((id==obj[i].passenger_id)&&(pass.equals(obj[i].password)))

flag=1;

display(obj[i]);

break;

if(flag!=1)

System.out.println("\nWrong Password entered ....");

System.out.println(" ");

System.out.print("Forgot Password ?? (Y/N) ");

choice = br.readLine().charAt(0);

if(choice=='y'||choice=='Y')

do

System.out.print("Enter New Password : ");

pass = br.readLine();

System.out.print("\nRe-enter the New Password : ");

pass1 = br.readLine();

if(!(pass.equals(pass1)))

flag = 1;

System.out.println("Re-entered Password doesn't matches, Enter again ");

else

System.out.println("Congratulations ! Your Password has been successfully changed ..");

flag = 0;

}
}while(flag==1);

PassengerDetails arr = new PassengerDetails(pass);

for(i=0;i<obj.length;i++)

if(id==obj[i].passenger_id)

obj[i].password = arr.password;

break;

else

System.out.println("Back to the Main Page");

break;

break;

case 2:

welcome();

System.out.println(" ");

System.out.println("Register yourself by entering the following credentials -->");

count++;

PassengerDetails arr[] = new PassengerDetails[count];//original obj[5]

for(int i=0;i<obj.length;i++)

arr[i]=obj[i];//1 2 3 4 5

System.out.println(" ");

System.out.print("PASSENGER NAME : ");

String name = br.readLine();

System.out.print("PASSENGER AGE : ");


int age = Integer.parseInt(br.readLine());

System.out.print("GENDER : ");

String gender = br.readLine();

System.out.print("TRAIN NAME : ");

String tname = br.readLine();

System.out.print("TICKETS : ");

String tkts = br.readLine();

System.out.print("NEW PASSWORD : ");

String pass = br.readLine();

int id = obj[count-2].passenger_id+1;

arr[count-1] = new PassengerDetails(id,name,age,gender,tname,tkts,pass);

display(arr[count-1]);

obj = arr;

System.out.println("\nYou have been successfully registerd!!! Your Passenger ID is "+obj[count-1].passenger_id);

display(obj[count-1]);

break;

case 3:

System.exit(0);

default:

System.out.println("Wrong Choice Entered ..");

System.out.print("\n\nDo you want to enter again ? (y/n) ");

choice = br.readLine().charAt(0);

}while(choice=='y'||choice=='Y');

void initializeValues(PassengerDetails[] arr) throws ParseException

arr[0] = new PassengerDetails(1001,"Ankita",19,"Female","Rajdhani Express","AC","welcome123");

arr[1] = new PassengerDetails(1002,"Mayank",19,"Male","Duranto Express","NON AC","welcome123");


arr[2] = new PassengerDetails(1003,"Ananya",19,"Female","Jaipur Superfast Express","CHAIR CAR","welcome123");

arr[3] = new PassengerDetails(1004,"Rishabh",22,"Male","Howrah Special Express","AC","welcome123");

arr[4] = new PassengerDetails(1005,"Kriti",20,"Female","Toofan Express","AC","welcome123");

static void display(PassengerDetails obj)throws IOException,InterruptedException

welcome();

System.out.println("\n");

System.out.println("ID : "+obj.passenger_id);

System.out.println("NAME : "+obj.passenger_name);

System.out.println("AGE : "+obj.passenger_age);

System.out.println("GENDER : "+obj.gender);

System.out.println("DISORDER DIAGNOSED : "+obj.train);

System.out.println("SYMPTOMS : "+obj.tickets);

static void menu()

System.out.println("1. Already a User, LOG IN");

System.out.println("2. New User, SIGN UP ");

System.out.println("3. Exit Portal");

System.out.println("\
n------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");

static void welcome()throws IOException, InterruptedException

new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();

System.out.println("\t\t\t\t\t\t\t\tWELCOME TO THE TRAVEL MONITORING PORTAL !!!!!!!");

System.out.println("\n");

System.out.println("\
n------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");

You might also like