Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions