Amazon Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Station {
    private int stationID;
    private String stationName;

    // Getters and Setters
}

public class Train {
    private int trainID;
    private String trainName;
    private Map<Station, Double> 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<Station, Double>();
        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 TicketDetails {
    private Train t;
    private Station from;
    private Station to;

    // 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
}

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) {
    }
}

Other classes/methods can be added to further enhance the design. Please share your thoughts, comments and suggestions. Thank you.

- Anonymous April 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Getters and Setters are evil in OOAD, for more info google it..

- Anonymous February 14, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

it looks good other than TrainTicket class should be like


public class TrainTicket {
private int ID;
private TicketDetails ticketDetails;
private Double fare;
private Passenger passenger;
private SeatDetail seatDetail;
}

and there should be one more class

public class Passenger {
private String Name;
private int id;
private int age;
private static final enum { Male, Female } gender;
}

- Shiavm May 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Still it misses the following points:
1. The details of Boggy objects like A/C, non-A/C, number of seats etc..
2. The details of Seat object like number
3. How to search the available Seats for particular kind of boggies efficiently ?
4. How cancellation will free the seat in boggie ?

- spiderman August 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

What about the availabilty of sets, capacity and current load?

I think that should be maintained as part of Train. Any suggestions

- check123 March 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How will it take care of searching and fetching available trains between two stations.

- Kartik October 26, 2016 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More