
hi,how can i write a program in Java programming to place reservation in air plane from the menu let the user to inter his/her name, age, date of traveling, and the seat in the plane?

import java.sql.*;
import java.util.*;
class Passenger{
public int no;
public String seatA;
public String seatB;
public String seatC;
public String seatD;
public Passenger() {
}
public Passenger(int no, String seatA, String seatB, String seatC,
String seatD) {
this.no = no;
this.seatA = seatA;
this.seatB = seatB;
this.seatC = seatC;
this.seatD = seatD;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getSeatA() {
return seatA;
}
public void setSeatA(String seatA) {
this.seatA = seatA;
}
public String getSeatB() {
return seatB;
}
public void setSeatB(String seatB) {
this.seatB = seatB;
}
public String getSeatC() {
return seatC;
}
public void setSeatC(String seatC) {
this.seatC = seatC;
}
public String getSeatD() {
return seatD;
}
public void setSeatD(String seatD) {
this.seatD = seatD;
}
}

continue..
public class AirlineReservation{
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement st=con.createStatement();
List<Passenger> list = new ArrayList<Passenger>();
list.add(new Passenger(1, "A", "B", "C", "D"));
list.add(new Passenger(2, "A", "B", "C", "D"));
list.add(new Passenger(3, "A", "B", "C", "D"));
list.add(new Passenger(4, "A", "B", "C", "D"));
list.add(new Passenger(5, "A", "B", "C", "D"));
list.add(new Passenger(6, "A", "B", "C", "D"));
list.add(new Passenger(7, "A", "B", "C", "D"));
for(Passenger s : list){
System.out.println(s.getNo() + " " + s.getSeatA() + " " + s.getSeatB() + " " + s.getSeatC() + " " + s.getSeatD());
}
Scanner input = new Scanner(System.in);
System.out.println("Enter Name: ");
String name=input.nextLine();
System.out.println("Enter Age: ");
int age=input.nextInt();
System.out.println("Enter date of travelling(yyyy-MM-dd): ");
String dt=input.next();
System.out.println("Enter seat no(like 1 A): ");
int num = input.nextInt();
String sn = input.next();
for(Passenger s : list){
if(num == s.getNo()){
if(sn.equals(s.getSeatA())){
s.setSeatA("X");
String ss=Integer.toString(num)+sn;
int i=st.executeUpdate("insert into airlines(name,age,dateOfTravelling,seat) values('"+name+"',"+age+",'"+dt+"','"+ss+"')");
System.out.println("Seat "+num+""+sn+" is Reserved");
} else if (sn.equals(s.getSeatB())) {
s.setSeatB("X");
String ss=Integer.toString(num)+sn;
int i=st.executeUpdate("insert into airlines(name,age,dateOfTravelling,seat) values('"+name+"',"+age+",'"+dt+"','"+ss+"')");
System.out.println("Seat "+num+""+sn+" is Reserved");
} else if (sn.equals(s.getSeatC())) {
s.setSeatC("X");
String ss=Integer.toString(num)+sn;
int i=st.executeUpdate("insert into airlines(name,age,dateOfTravelling,seat) values('"+name+"',"+age+",'"+dt+"','"+ss+"')");
System.out.println("Seat "+num+""+sn+" is Reserved");
} else if (sn.equals(s.getSeatD())) {
s.setSeatD("X");
String ss=Integer.toString(num)+sn;
int i=st.executeUpdate("insert into airlines(name,age,dateOfTravelling,seat) values('"+name+"',"+age+",'"+dt+"','"+ss+"')");
System.out.println("Seat "+num+""+sn+" is Reserved");
} else {
System.out.println("Not Available");
}
}
System.out.println(s.getNo()+" "+s.getSeatA()+" "
+s.getSeatB()+ " "+s.getSeatC()+" "+ s.getSeatD());
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.