0% found this document useful (0 votes)
69 views2 pages

U0 Assign Truck AP

The document provides instructions to create a Truck class with private fields for make, model, miles, and value, and various methods like constructors, accessors, modifiers, driveToWork(), and demolish(). It then instructs to create a client class TruckSales that gets user input to create old and new Truck objects, calls methods on them like driveToWork() and demolish(), and outputs information about the Trucks. It also notes to format monetary values with currency formatting.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views2 pages

U0 Assign Truck AP

The document provides instructions to create a Truck class with private fields for make, model, miles, and value, and various methods like constructors, accessors, modifiers, driveToWork(), and demolish(). It then instructs to create a client class TruckSales that gets user input to create old and new Truck objects, calls methods on them like driveToWork() and demolish(), and outputs information about the Trucks. It also notes to format monetary values with currency formatting.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Truck Assignment

Note: There is no inheritance in this program.

Create a class called Truck in your Unit 0 Folder. The Truck class should contain the following:
● Four private fields: make (String), model (String), miles (int), value (double)
● A default constructor that creates a default Truck that is a Chevrolet (the make) Colorado (the model)
with 35 miles on it and a current value of $27,000.
● A constructor that takes four parameters, one for each of the fields.
● An accessor for each field.
● A modifier for the miles and value fields only.
● A public void method named driveToWork() that increases miles by 20 (the distance from your home to
work) and reduces the value by .05%.
● A public void method named demolish() that sets the value to 0.
● Do not add any other methods!!!

Create a client class called TruckSales.

● Ask the user for the make, model, miles, and value of their current Truck.
● Create a new Truck object called oldTruck that puts this information into the constructor. This is the
Truck that the user wants to sell.
● Instantiate another Truck object called newTruck using the default constructor. This is the Truck that
the user wants to buy.
● Print out the make, model, miles, and value of each of the Trucks using the accessors from the Truck
class.
● Print out the amount the user will pay for the new Truck. You should subtract the value of the old Truck
from the new Truck value, as the user will be trading in the old Truck.
● However, the dealer decides not to salvage the old Truck, so you need to demolish it.
● Next, the user will drive to work and back home. You should not create another method for this, and
you should not change the driveToWork() from the instructions I originally gave you.
● Print out the make, model, miles, and value of each of the Trucks again using the accessors.

You need to put all monetary values in currency format.


● You need to import java.text.*.
● On the line after you declare the Scanner, type the following line:
○ NumberFormat fmt=NumberFormat.getCurrencyInstance();
● Whenever you output a value, put fmt.format around the value.
○ Example: System.out.println(fmt.format(price));

Example output is on the next page.


Example Output (input is in italics and blue):

What is the make of your Truck?


Ford
What is the model of your Truck?
F150
How many miles are on your Truck?
206000
What is the current value of your Truck?
3000

Information about your old Truck:


Make: Ford
Model: F150
Miles: 206000
Value: $3,000.00

Information about your new Truck:


Make: Chevrolet
Model: Colorado
Miles: 35
Value: $27,000.00

Your new Truck will cost $24,000.00.

The dealer decided to demolish your old Truck.


You drove your new Truck to work and back home.

Information about your old Truck:


Make: Ford
Model: F150
Miles: 206000
Value: $0.00

Information about your new Truck:


Make: Chevrolet
Model: Colorado
Miles: 75
Value: $26,973.01

Turn in the java files only (or a web url if using an online IDE) in Canvas when you are done.

You should turn in 2 files.

You might also like