import java.util.Scanner;
public class ICSEJava{
public static void main(String[] args) {
RailwayTicket obj = new RailwayTicket();
obj.accept();
obj.update();
obj.display();
}
}
class RailwayTicket {
public void display() {
System.out.println("Passenger's name:"+name);
System.out.println("Travelling coach:"+coach);
System.out.println("Passenger's mobile no:"+mobileNumber);
System.out.println("Intial Amount:"+amount);
if( amount < totalAmount)
System.out.println("Amount after upgradation:"+totalAmount);
else
System.out.println("You have not opted for upgradation:");
}
public void update() {
Scanner in = new Scanner(System.in);
String choice;
String temp;
int counter = 0;
System.out.println("Do you want to update your coach(Yes,No):");
choice = in.nextLine();
if(choice.toUpperCase().equals("NO"))
System.out.println("You have not opted for upgradation:");
else if(choice.toUpperCase().equals("YES")){
if (coach.equals("First_AC"))
System.out.println("Cannot be upgraded:");
else {
int currentCoachPos = 0;
int upgradeCoachPos = 0;
System.out.println("Enter the coach name you want to upgrade:");
temp = in.nextLine();
while(!coach.equals(coachType[currentCoachPos++]));
while(!temp.equals(coachType[upgradeCoachPos++]));
if (currentCoachPos <= upgradeCoachPos)
if(currentCoachPos < upgradeCoachPos)
System.out.println("You are already in a higher class:");
else
System.out.println("You have opted to upgrade in the same class!:");
else {
counter = 0;
while(!temp.equals(coachType[counter++]) && counter < 4);
if(counter == 4 )
System.out.println("Invalid choice:");
else {
coach = coachType[counter-1];
totalAmount = amount + chargesForCoach[counter-1];
}
}
}
}
else {
System.out.println("Invalid choice:");
}
in.close();
}
public void accept() {
Scanner in = new Scanner(System.in);
System.out.println("Enter your name:");
name = in.nextLine();
System.out.println("Enter your coach type:(First_AC/Second_AC/Third_AC/Sleeper):");
coach = in.nextLine();
System.out.println("Enter your mobile number:");
mobileNumber = in.nextLong();
System.out.println("Enter your fare:");
amount = in.nextInt();
//in.close();
}
String name;
String coach="Sleeper";
long mobileNumber;
int amount;
int totalAmount;
String[] coachType = {"First_AC","Second_AC","Third_AC","Sleeper"};
int[] chargesForCoach = {700,500,250,0};
}
Thanks for share as
ReplyDelete