Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help with the code. BlueJ (java), SeatTest /** * The test class SeatTest. */ public class SeatTest extends junit.framework.TestCase { private Seat seat1; private

please help with the code. BlueJ (java),

image text in transcribed

SeatTest

/** * The test class SeatTest. */ public class SeatTest extends junit.framework.TestCase { private Seat seat1; private Seat seat2;

/** * Default constructor for test class SeatTest */ public SeatTest() { }

/** * Sets up the test fixture. * * Called before every test case method. */ protected void setUp() { seat1 = new Seat(1, 125.0); seat2 = new Seat(2, 50.0); }

/** * Tears down the test fixture. * * Called after every test case method. */ protected void tearDown() { }

/** * Test creating a seat. * * Check that seat 1 has the correct price (within 1.25) * and isn't booked. * * Check that seat 2 has the correct price (within 0.5) * and isn't booked. */ public void testCreateSeat() { assertEquals(1, seat1.number()); assertEquals(125.0, seat1.price(), 1.25); assertEquals(false, seat1.isBooked()); assertEquals(2, seat2.number()); assertEquals(50.0, seat2.price(), 0.5); assertEquals(false, seat2.isBooked()); }

/** * Test booking a seat. * * Book a seat and check that it is indeed booked. Try to book it * again and check that book() returns false, and that the seat * is still booked. */ public void testBooking() { assertEquals(true, seat1.book()); assertEquals(true, seat1.isBooked()); assertEquals(false, seat1.book()); assertEquals(true, seat1.isBooked()); } /** * Test canceling a seat booking. * * Try to cancel a booking that hasn't been made. Book a set * and cancel the booking, and check that it isn't booked. Try * canceling the booking again and check that cancelBooking() * returns false and that the seat is still not booked. */ public void testCancelBooking() { assertEquals(false, seat1.cancelBooking()); assertEquals(true, seat1.book()); assertEquals(true, seat1.cancelBooking()); assertEquals(false, seat1.isBooked()); assertEquals(false, seat1.cancelBooking()); assertEquals(false, seat1.isBooked()); } }

Seat

/** * Seat models a seat in a car in a passeger train. * */ public class Seat { private int number; // the seat's number private boolean booked; // has this seat has been reserved? private double price; // the cost of a ticket for this seat, in dollars

/** * Constructs a new Seat with the specified seat number and * ticket price. */ public Seat(int seatNo, double cost) { booked = false; number = seatNo; price = cost; }

/** * Returns the cost of purchasing a ticket for this Seat. */ public double price() { return price; }

/** * Returns this seat's number. */ public int number() { return number; }

/** * Returns true if someone has purchased a ticket * for this this Seat. */ public boolean isBooked() { return booked; }

/** * If this seat is available, books it and returns true. * If the seat is not available, returns false. */ public boolean book() { if (!booked) { booked = true; return true; } return false; }

/** * If this seat is booked, cancels the booking and returns true. * If the seat was not booked, returns false. */ public boolean cancelBooking() { if (booked) { booked = false; return true; } return false; } }

Part 1: Improving Class SeatTest 1. Change testCreateSeat ) to ensure that all prices are within 50c accuracy (i.e. no more than 50c higher or lower than the expected value) 2. In testBooking) perform the same tests on seat2 that were performed on seat1. Ensure that seat2 has a different seat number and cost from seat1. Make the same changes to testCancelBooking () Check that your code is nicely formatted and well commented. Generate your javadoc to check that it is complete and correct. 3. 4. Part 1: Improving Class SeatTest 1. Change testCreateSeat ) to ensure that all prices are within 50c accuracy (i.e. no more than 50c higher or lower than the expected value) 2. In testBooking) perform the same tests on seat2 that were performed on seat1. Ensure that seat2 has a different seat number and cost from seat1. Make the same changes to testCancelBooking () Check that your code is nicely formatted and well commented. Generate your javadoc to check that it is complete and correct. 3. 4

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_2

Step: 3

blur-text-image_3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 1 Lnai 9284

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Carlos Soares ,Joao Gama ,Alipio Jorge

1st Edition

3319235273, 978-3319235271

Students also viewed these Databases questions

Question

(5) If X has a mean value of 5, then E(2X) = 10.

Answered: 1 week ago

Question

6. Identify characteristics of whiteness.

Answered: 1 week ago

Question

9. Explain the relationship between identity and communication.

Answered: 1 week ago