Guest User

Untitled

a guest
May 23rd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. interface FlightDetails {
  4. void getFlightDetails();
  5. void book(Ticket ticket);
  6. }
  7.  
  8. class AirIndia implements FlightDetails {
  9. public void getFlightDetails() {
  10. System.out.println("Flight Details of Air India");
  11. }
  12.  
  13. public void book(Ticket ticket) {
  14. System.out.println("Ticket booked in Air India");
  15. }
  16. }
  17.  
  18. class Emirates implements FlightDetails {
  19. public void getFlightDetails() {
  20. System.out.println("Flight Details of Emirates");
  21. }
  22.  
  23. public void book(Ticket ticket) {
  24. System.out.println("Ticket booked in Emirates");
  25. }
  26. }
  27.  
  28. class Lufthansa implements FlightDetails {
  29. public void getFlightDetails() {
  30. System.out.println("Flight Details of Lufthansa");
  31. }
  32.  
  33. public void book(Ticket ticket) {
  34. System.out.println("Ticket booked in Lufthansa");
  35. }
  36. }
  37.  
  38. class Ticket{
  39.  
  40. }
  41.  
  42. public class InterfaceFlight {
  43. public static void main(String[] args) throws IOException {
  44. FlightDetails flight = null;
  45. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  46. System.out.println("1.Air Indian2.Emiratesn3.Lufthansa");
  47. System.out.print("Enter choice = ");
  48. int choice = Integer.parseInt(br.readLine());
  49. if(choice == 1){
  50. flight = new AirIndia();
  51. flight.book(new Ticket());
  52. } else if(choice == 2){
  53. flight = new Emirates();
  54. flight.book(new Ticket());
  55. } else if(choice == 3){
  56. flight = new Lufthansa();
  57. flight.book(new Ticket());
  58. }
  59. }
  60. }
Add Comment
Please, Sign In to add comment