TheRightGuy

Untitled

Oct 24th, 2020
516
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.ARS.ticket;
  2.  
  3. import org.jetbrains.annotations.NotNull;
  4.  
  5. import java.awt.*;
  6.  
  7. import java.time.LocalDate;
  8. import java.time.LocalDateTime;
  9.  
  10.  
  11. public class Ticket {
  12.     private final static Random random = new Random();
  13.     private List<String> seat = Arrays.asList("A", "B", "C", "D", "E", "F", "G", "H", "J", "K");
  14.  
  15.     public String calculateNewRandomSeat(){
  16.         StringBuilder sb = new StringBuilder();
  17.         sb.append(random.nextInt(347));
  18.         sb.append(seat.get(random.nextInt(seat.size())));
  19.         return sb.toString();
  20.     }
  21.  
  22.     public void setSeat(String seat) {
  23.         this.seat = Collections.singletonList(seat);
  24.     }
  25.  
  26. }
  27.  
  28. ----------------------------------- ONE CLASS
  29. package com.ARS.ticket.controller;
  30.  
  31. import com.ARS.ticket.Ticket;
  32. import com.ARS.ticket.view.TicketView;
  33.  
  34. import java.awt.*;
  35.  
  36. import java.time.LocalDate;
  37.  
  38. public class TicketController {
  39.     Ticket model;
  40.     TicketView view;
  41.  
  42.     public TicketController(Ticket model, TicketView view) {
  43.         this.model = model;
  44.         this.view = view;
  45.     }
  46.  
  47.     public void setSeat(String seat) {
  48.         model.setSeat(seat);
  49.     }
  50.  
  51.     public String getSeat() {
  52.         return model.calculateNewRandomSeat();
  53.     }
  54.  
  55.  
  56.     public void updateView() {
  57.         view.TicketDetails(model.calculateNewRandomSeat());
  58.     }
  59. }
  60. ------------------------- ONE MORE
  61. public class TicketView {
  62.  
  63.     public void TicketDetails(String seat){
  64.         System.out.println("Ticket: ");
  65.         System.out.println("Seat: " + seat);
  66.         System.out.println("-------------");
  67.     }
  68. }
  69. -------------------------
  70. package com.ARS;
  71.  
  72. import com.ARS.flight.Flight;
  73. import com.ARS.flight.controller.FlightController;
  74. import com.ARS.flight.view.FlightView;
  75.  
  76. import com.ARS.ticket.Ticket;
  77. import com.ARS.ticket.controller.TicketController;
  78. import com.ARS.ticket.view.TicketView;
  79.  
  80. import com.ARS.user.User;
  81. import com.ARS.user.controller.UserController;
  82. import com.ARS.user.view.UserView;
  83. import org.jetbrains.annotations.NotNull;
  84.  
  85. import java.awt.*;
  86.  
  87. public class Main {
  88.  
  89.     public static void main(String[] args) {
  90.  
  91.         Ticket ticketModel = retrieveTicket();
  92.  
  93.         TicketView ticketView = new TicketView();
  94.  
  95.         TicketController ticketController = new TicketController(ticketModel, ticketView);
  96.  
  97.         ticketController.updateView();
  98.  
  99.     }
  100.  
  101.     @org.jetbrains.annotations.NotNull
  102.     private static Ticket retrieveTicket() {
  103.         Ticket ticket = new Ticket();
  104.         ticket.setPassenger_name(User.getName());
  105.         ticket.setCompanies(ticket.getCompanies());
  106.         ticket.setFrom(ticket.getFrom());
  107.         ticket.setDestination(ticket.getDestination());
  108.         while(ticket.getFrom() == ticket.getDestination()){
  109.             ticket.setFrom(ticket.getFrom());
  110.             ticket.setDestination(ticket.getDestination());
  111.         }
  112.         ticket.setIATA_airline_code(ticket.getIATA_airline_code());
  113.         ticket.setAirline_class(ticket.getAirline_class());
  114.         ticket.setBoarding_time(ticket.getBoarding_time());
  115.         ticket.setGate(ticket.getGate());
  116.         ticket.setDate(ticket.getDate());
  117.         ticket.setSeat(ticket.calculateNewRandomSeat());
  118.  
  119.         return ticket;
  120.     }
  121.  
  122.    
  123. }
RAW Paste Data