Question: Java programming a. Write a test method that calls the following constructor with valid arguments: Ticket(Passenger p, Seat s, double price) - In the test

Java programming

a. Write a test method that calls the following constructor with valid arguments: Ticket(Passenger p, Seat s, double price) - In the test method, create a Passenger object. The default constructor of the Passenger class generates a valid name T. B. A., so either of the following statements instantiate a Passenger:

Passenger passenger = new Passenger(); Passenger passenger = new Passenger( new PassengerName(Mary, I, Worth);

- Create a Seat object. The Seat class has no explicit constructor so you must use the implicit default constructor and then call seat.setRow(int i) and seat.setLetter(char c) to specify a specific seat.

- Create the ticket object, providing the passenger object, seat object and the price as a number as the three arguments of the constructor.

Ticket ticket = new Ticket(passenger, seat, price);

b. For a condition that verifies that a ticket is issued, use the fact that tickets are numbered, starting at 1,000,000. So lines in the test method could look like:

Assert.assertTrue(ticket.getTicketNo() > 1000000 );

c. Write a second test in the same class that generates a ticket when called with arguments that are not valid. In real life, you should create several tests to isolate different combinations of valid and invalid input values, but for purposes of this exercise combine several tests, as in:

@Test( expected=Exception.class) public void testTicketBad() { Ticket ticket = new Ticket(null, new Seat(), -100); Assert.assertTrue(ticket.getTicketNo() > 1000000 ); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!