Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Sorry its a little too long.. These are the file to be submitted:- 1. Vehicle.java 2. CarCompany.java 3. PickupTruck.java 4. Sedan.java 5. SportsCar.java 6. Your

Sorry its a little too long..

These are the file to be submitted:- 1. Vehicle.java 2. CarCompany.java 3. PickupTruck.java 4. Sedan.java 5. SportsCar.java 6. Your test program ==============Please provide Tester code too================== 1. Define a simple Vehicle class. It should keep track of a make and a model, both as strings. It should have a toString() method that returns a String representation that includes the make and the model, as in "Toyota Rav4" or "Nissan Rogue". Since the make and model are fixed after the vehicle is created, you should create getters for each instance variable, but no setters. 2. Write a test class to make sure your Vehicle class works properly. Be sure to test your toString method by including code like: Vehicle aCar = new Vehicle( "Honda", "Accord"); System.out.println("aCar is: " + aCar); When you use aCar (a variable of type Vehicle) in this way, it should call your toString() method to print the car. This happens automatically if you've declared toString properly. 3. Create a second class called CarCompany that just holds the name of the company and provides a toString method returning that name. Change the type of the make field (and the constructor argument) in your Vehicle class to be a CarCompany. You should not have to change the toString method on Vehicle. Be sure to test this before continuing. 4. Add the following methods to your Vehicle class. As you add them, you will need to add additional fields to your class to keep track of things like how many passengers are in your car, and how much it is currently carrying. a) int getPassengerCapacity() // how many passengers not counting the driver fit in the vehicle Just have it return the constant 3 for now. This field is the maximum number of passengers will fit in the car, not the number that are actually in it. b) int getCargoCapacity() // how many pounds of cargo can the vehicle carry Just have it return the constant 250 for now. This is the maximum amount of cargo. 5) Add the necessary fields and getters to keep track of how many passengers and how much cargo is loaded. Note that these are different than the passenger and cargo

capacities. The capacities are the maximum amount the car can hold, whereas these are the current amount loaded into the car (either people or cargo). a) getNumPassengers() // how many passengers are currently in the car. and b) amountCargo() // how many pounds of cargo are loaded Both of these should start out as returning zero, until the load methods below are called. c) void loadPassengers(int numPassengers) // put passengers in the car When you loadPassengers, you need to add the numPassengers to the passengers already in the car. For example, if you do: aCar.loadPassengers(1); aCar.loadPassengers(2); int num = aCar.getNumPassengers(); // num should be 3 -- a total of 3 passengers were loaded. Assume for now that a legal numPassengers is passed. We will come back to this later. d) int unloadPassengers() // unloads all the passengers, returns the number of passengers that were in the car before unloading. So, if there were 2 passengers in the car, it would return 2, and set the number of passengers to zero e) void loadCargo(int weight) // put cargo in the vehicle f) int unloadCargo() // unload all cargo, return cargo that was in car before unloading 5. Create a subclass of Vehicle called PickupTruck. It should override the passengerCapacity in vehicle. Instead of returning 3, it should return 1. Your PickupTruck class should also override the cargo capacity, always returning 1000. In your test class, create a PickupTruck instance, and check that the loading cargo and passengers methods of your truck reflect the changed capacities. Add another subclass, Sedan. The Sedan should have the same 3 passengers and 250 pounds of cargo as Vehicle. Lastly, add a subclass SportsCar, which can hold 1 passenger and 100 pounds of cargo. Verify that all these classes work by writing some appropriate test code that tests *all* of your methods. Double check all your classes, and make sure you have getters for all appropriate items in your class. For example, CarCompany should have a getName getter as well as its toString. Be sure to include proper javadoc for all public methods. Submit all your .java files, including your test class. Make sure you test any public methods as applicable. so double check your test and make sure you included something that shows how each public method works!

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

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

Develop a production-distribution chain for your business.

Answered: 1 week ago