Question
please help with this code. BlueJ (java), CarTest /** * The test class CarTest. */ public class CarTest extends junit.framework.TestCase { /** * Default constructor
please help with this code. BlueJ (java),
CarTest
/** * The test class CarTest. */ public class CarTest extends junit.framework.TestCase { /** * Default constructor for test class CarTest */ public CarTest() { }
/** * Sets up the test fixture. * * Called before every test case method. */ protected void setUp() { }
/** * Tears down the test fixture. * * Called after every test case method. */ protected void tearDown() { } public void testCreateBusinessCar() { Car aCar = new Car(1385, true); Seat[] seats = aCar.seats(); /* Verify that the car has the right number of seats. */ assertEquals(Car.BUSINESS_SEATS, seats.length); /* Verify that each seat has the correct number and price. */ for (int i = 0; i
Car
public class Car { /** This car's identifier. */ private int id; /** * true == this car is a business-class car, * false == this car is an economy-class car. */ private boolean businessClass; /** The cost of a business class seat, in dollars. */ public static final double BUSINESS_SEAT_COST = 125.0; /** The cost of an economy class seat, in dollars. */ public static final double ECONOMY_SEAT_COST = 50.0; /** The number of seats in a business class car. */ public static final int BUSINESS_SEATS = 30; /** The number of seats in an economy class car. */ public static final int ECONOMY_SEATS = 40; /** The list of this car's seats. */ private Seat[] seats; /** * Constructs a new Car object with the specified id. * If parameter isBusinessClass is true, the car is a business-class * car. If parameter isBusinessClass is false, the car is an * economy-class car. */ public Car(int carId, boolean isBusinessClass) { id = carId; businessClass = isBusinessClass; if (businessClass == true) { seats = new Seat[BUSINESS_SEATS]; for(int i = 1; i
/** * Returns this car's list of seats. This method is intended for * testing purposes only, and should not be called by other objects, * as it may be removed from the final version of this class. * * @return The seats in this car, an array of Seat objects. */ public Seat[] seats() { return seats; } /** * Returns true if this is a business-class car, * false if this is an economy-class car. */ public boolean isBusinessClass() { if(businessClass == true){ return true; } return false; } /** * Returns the id of this car. */ public int id() { return id; } /** * This method is called when the specified seat has been booked, * to print a ticket for that seat. * * @param seatNo The integer identifier of the seat. */ private void printTicket(int seatNo) { System.out.println("Car ID: " + id); System.out.println("Seat number: " + seatNo); System.out.println("Price: "); if (businessClass) { System.out.println(BUSINESS_SEAT_COST); } else { System.out.println(ECONOMY_SEAT_COST); } } /** * Attempts to book a seat. If successful, this method prints a * ticket and returns true. * If no seats are available, this method returns false. */ public boolean bookNextSeat() { for(int i = 1; i
public boolean cancelSeat(int seatNo) { if(seatNo seats.length) { return false; } else{ if(seats[seatNo-1].isBooked() == false) { return false; } else{ seats[seatNo-1].cancelBooking(); return true; } } } }
Part 2: Improving Class CarTest 1. Add to testBookNextSeat () so that all the current tests are done for an economy car (as well as the current business car) 2. Make the same changes to testCancelSeat () . Also modify testCancelseat () to try to cancel a booking of seat 50 in each of the cars. (Note: There is no seat 50 in either car, so the bookings should be unsuccessful.) Check that your code is nicely formatted and well commented. Generate your javadoc to check that it is complete and correct 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