Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.text.DecimalFormat;
- public class Car {
- private String carModel;
- private long fuelAmount;
- private double fuelForOneKm;
- private int distance;
- public Car(String carModel, long fuelAmount, double fuelForOneKm) {
- this.carModel = carModel;
- this.fuelAmount = fuelAmount;
- this.fuelForOneKm = fuelForOneKm;
- this.distance = 0;
- }
- public String getCarModel() {
- return carModel;
- }
- public void Drive(int kmToDrive){
- if(kmToDrive * fuelForOneKm <= fuelAmount){
- this.distance += kmToDrive;
- this.fuelAmount -= (kmToDrive * fuelForOneKm);
- }
- else
- {
- System.out.println("Insufficient fuel for the drive");
- }
- }
- @Override
- public String toString() {
- String fuelInTheTank = new DecimalFormat("#.00").format(fuelAmount);
- return carModel + " " + fuelInTheTank + " " + distance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement