Question
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),
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. 4Step 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