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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started