title: Designing a class for train reservation system
body: <p>I am new to Object Oriented design and still in the process of learning it.
  I designed a class for a train reservation system but I am not sure on how to model the main reservation class.</p>
  <p>This is how my design looks:</p>
  <pre><code>public class Station {
      private int stationID;
      private String stationName;
  
      // Getters and Setters
  }
  
  public class Train {
      private int trainID;
      private String trainName;
      private Map&lt;Station, Double&gt; trainStationsWithFares;
  
      public Train(int ID, String trainName, Station[] stations) {
      // Initialize ID and name and create a hashmap with all stations and
      // zero fare initially for all stations.
      ....
      trainStationsWithFares = new HashMap&lt;Station, Double&gt;();
      for(Station s : stations) trainStationsWithFares.put(s, new Double(0.0));
      }
  
      // Getters and Setters (including methods to add new stations with fares and
      // update fares of existing stations
  }
  
  public class Passenger {
      private String Name;
      private int id;
      private int age;
      private static final enum { Male, Female } gender; 
  }
  
  public class TicketDetails {
      private Train t;
      private Station from;
      private Station to;
      private Passenger passenger;
  
      // Getters and Setters
  }
  
  public class TrainTicket {
      private int ID;
      private TicketDetails ticketDetails;
      private Double fare;
  
      public TrainTicket(TicketDetails ticketDetails)
          throws InvalidTrainException, InvalidFromStationException,
              InvalidToStationException {
          ...
          calculateFare();
      }
  
      // Calculates fare based on Train and from and to Stations and taxes, etc.
      private void calculateFare() {
          this.fare = ...
      }
  }
  
  // Assuming card payment only for online reservation system for simplicity.
  // Design can be modified and enhanced suitably.
  public class PaymentDetails {
      private String cardNumber;
      private String cardExpirationMonth;
      private String cardExpirationYear;
      private String cardCVV;
  
      // Getters and Setters
  }
  </code></pre>
  <p>My question is, should my reservation class look like this?
  If so, how will the methods in this class access the objects of others classes like <code>TrainTicket</code>, <code>PaymentDetails</code>, etc.?</p>
  <pre><code>public abstract class ReservationSystem {
  
      // Purchase train ticket by providing ticket details and payment details.
      public abstract TrainTicket purchaseTicket(TicketDetails ticketDetails,
          PaymentDetails paymentDetails);    
  
      // Cancel existing train ticket by providing ticket reference and payment details
      // for cancellation charges.
      public abstract boolean cancelTicket(TrainTicket tt, PaymentDetails details);
  
      // Modify existing train ticket by providing existing ticket reference,new ticket
      // details and payment details for any additional charge or modify charges.
      public abstract TrainTicket modifyTicket(TrainTicket existingTicket,
          TicketDetails newTicketDetails, PaymentDetails paymentDetails) {
      }
  }
  </code></pre>
  <br>
  Or should it look like this:
  <pre><code>public class ReservationSystem{
      private Map&lt;trainId, Train&gt; trains;   
      private Ticketdetails ticketdetails;
      private PaymentDetails paymentDetails;
      private TrainTicket tt;
  
      public vector&lt;Train&gt; getTrain(TicketDetails ticketdetails);
      public TrainTicket purchaseTicket(TicketDetails ticketDetails,
          PaymentDetails paymentDetails);    
      public boolean cancelTicket(TrainTicket tt, PaymentDetails details);
      public TrainTicket modifyTicket(TrainTicket existingTicket,
          TicketDetails newTicketDetails, PaymentDetails paymentDetails);
  }
  </code></pre>
  <p>I want to know how should the main Reservation class access the methods and members of other classes.</p>