This question already has an answer here:
- How do I compare strings in Java? 23 answers
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String search;
Flightinfo f = new Flightinfo();
Customerinfo f1[] = new Customerinfo[1];
System.out.print("Enter the destination: ");
search = s.nextLine();
System.out.println("Enter The Name of the Plane You Want to Fly : \n1.USBangla\n2.Regent Air\n3.Novo Air");
String Plane = s.nextLine();
if(Plane=="USBangla")
{
f.USBangla();
if((search.equals(f.flightDest1)==true)||(search.equals(f.flightDest2)==true)||(search.equals(f.flightDest3)==true)){
System.out.println(f.flightName);
System.out.println(f.flightDest1);
System.out.println(f.seatClass);
for(int i = 0 ;i<f1.length;i++){
f1[i] = new Customerinfo();
System.out.print("Enter the customer name: ");
String cname = s.nextLine();
System.out.print("Enter the customer address: ");
String cadd = s.nextLine();
System.out.print("Enter the customer gender: ");
String cgen = s.nextLine();
System.out.print("Enter the customer email: ");
String cem = s.nextLine();
System.out.print("Enter the customer phone number : ");
String cpho = s.nextLine();
f1[i].set(cname, cadd, cpho, cem, cgen);
System.out.println(f1[i].customerName+" "+f1[i].address+" "+f1[i].email+" "+f1[i].gender);
}
}
}
else if (Plane=="Regent Air")
{
f.RegentAir();
if((search.equals(f.flightDest1)==true)||(search.equals(f.flightDest2)==true)||(search.equals(f.flightDest3)==true))
{
System.out.println(f.flightName);
System.out.println(f.flightDest1);
System.out.println(f.seatClass);
for(int i = 0 ;i<f1.length;i++){
f1[i] = new Customerinfo();
System.out.print("Enter the customer name: ");
String cname = s.nextLine();
System.out.print("Enter the customer address: ");
String cadd = s.nextLine();
System.out.print("Enter the customer gender: ");
String cgen = s.nextLine();
System.out.print("Enter the customer email: ");
String cem = s.nextLine();
System.out.print("Enter the customer phone number : ");
String cpho = s.nextLine();
f1[i].set(cname, cadd, cpho, cem, cgen);
System.out.println(f1[i].customerName+" "+f1[i].address+" "+f1[i].email+" "+f1[i].gender);
}
}
}
else if(Plane=="Novo Air")
{
f.NovoAir();
if((search.equals(f.flightDest1)==true)||(search.equals(f.flightDest2)==true)||(search.equals(f.flightDest3)==true))
{
System.out.println(f.flightName);
System.out.println(f.flightDest1);
System.out.println(f.seatClass);
for(int i = 0 ;i<f1.length;i++){
f1[i] = new Customerinfo();
System.out.print("Enter the customer name: ");
String cname = s.nextLine();
System.out.print("Enter the customer address: ");
String cadd = s.nextLine();
System.out.print("Enter the customer gender: ");
String cgen = s.nextLine();
System.out.print("Enter the customer email: ");
String cem = s.nextLine();
System.out.print("Enter the customer phone number : ");
String cpho = s.nextLine();
f1[i].set(cname, cadd, cpho, cem, cgen);
System.out.println(f1[i].customerName+" "+f1[i].address+" "+f1[i].email+" "+f1[i].gender);
}
}
}
}
}
import java.util.Scanner;
public class Flightinfo {
String flightName;
String flightDest1;
String flightDest2;
String flightDest3;
int priceToK_b;
int priceToR_b;
int priceToC_b;
int priceToK_e;
int priceToR_e;
int priceToC_e;
String TOFF;
String seatClass1 ;
String seatClass2;
String seatClass;
double arrivalTime,departureTime;
Scanner sc = new Scanner(System.in);
int seatnum[] = new int[40];
void USBangla(){
System.out.println("Enter Seat Class : " );
String Sclass = sc.nextLine();
flightName = "US BANGLA";
TOFF = "Dhaka";
flightDest1 = "Khulna";
flightDest2 = "Rajshahi";
flightDest3 ="Chittagong";
arrivalTime = 4.30;
departureTime = 1.45;
//String seatClass1 = "Business";
//String seatClass2 = "Economy";
priceToK_b= 5000;
priceToR_b= 4000;
priceToC_b= 7000;
priceToK_e= 4000;
priceToR_e= 3000;
priceToC_e= 6000;
if(Sclass=="Business")
{
seatClass = "Business";
}
else
{
seatClass = "Economy";
}
}
void RegentAir()
{
System.out.println("Enter Seat Class : " );
String Sclass = sc.nextLine();
flightName = "Regent Air";
TOFF = "Dhaka";
flightDest1 = "Khulna";
flightDest2 = "Rajshahi";
flightDest3 ="Chittagong";
arrivalTime = 4;
departureTime = 1;
seatClass1 = "Business";
seatClass2 = "Economy";
priceToK_b= 4500;
priceToR_b= 3500;
priceToC_b= 7500;
priceToK_e= 4200;
priceToR_e= 2500;
priceToC_e= 5500;
if(Sclass=="Business")
{
seatClass = "Business";
}
else
{
seatClass = "Economy";
}
}
void NovoAir()
{
System.out.println("Enter Seat Class : " );
String Sclass = sc.nextLine();
flightName = "Novo Air";
TOFF = "Dhaka";
flightDest1 = "Khulna";
flightDest2 = "Rajshahi";
flightDest3 ="Chittagong";
arrivalTime = 4;
departureTime = 1;
seatClass1 = "Business";
seatClass2 = "Economy";
priceToK_b= 6500;
priceToR_b= 3500;
priceToC_b= 6400;
priceToK_e= 4400;
priceToR_e= 3200;
priceToC_e= 5600;
if(Sclass=="Business")
{
seatClass = "Business";
}
else
{
seatClass = "Economy";
}
}
}
public class Customerinfo extends Flightinfo{
String customerName;
String address;
String phonenumber;
String email;
String gender;
void set(String customerName,String address,String phonenumber,String email,String gender){
this.customerName = customerName;
this.address = address;
this.phonenumber = phonenumber;
this.email = email;
this.gender = gender;
}
public String getCustomerName() {
return customerName;
}
public String getAddress() {
return address;
}
public String getPhonenumber() {
return phonenumber;
}
public String getEmail() {
return email;
}
public String getGender() {
return gender;
}
@Override
public String toString() {
return "Customerinfo [getCustomerName()=" + getCustomerName() + ", getAddress()=" + getAddress()
+ ", getPhonenumber()=" + getPhonenumber() + ", getEmail()=" + getEmail() + ", getGender()="
+ getGender() + "]";
}
}
After Taking Plane name input it doesn't advance any more..The PROGRAM just stops taking input.Is it the if else messing up everything? or something else?Please Help me out here..
Aucun commentaire:
Enregistrer un commentaire