a guest Feb 27th, 2020 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- Create public class CAR. It should have:
- 1. Attributes: String NAME, float consumption, String fuel,
- 2. Constructor with 3 parameters that will assign values to the appropriate attribute. For Fuel use: GASOLINE, DIESEL and GAS.
- 3. Methods getNAME() , getFUEL()– these method return the appropriate attribute value
- 4. Method COST (int km) that returns the amount of money you’ll need to buy fuel in order to pass distance of km kilometers, with the car that has fuel consumption of consumption liters per kilometer and fuel that has some price per liter.
- price: If the car uses GASOLINE, the price= 69.50
- If the car uses DISEL, the price= 57.50
- If the car uses GAS, the price= 37
- (Use the proportion)
- X= (consumption * km) /100
- //X- fuel liters for passing km kilometers
- COST= X * price
- In the main() method of the public class
- o Create an array of 5 cars
- o Create manual instance for every array element
- o Using the FOR loop, for every array element, display the name, fuel and car consumption
- o Find the car that will spent 800 km with least cost. The output message should be similar to this example:
- You will pass 800 km with least money if you drive Citroen c1.
- It will cost you 2350 den.
RAW Paste Data