Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class LKM {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String name;
- double maxLoad;
- double litters;
- double regularGasMileage = 0;
- System.out.printf("Enter the brand of the car: ");
- name = sc.nextLine();
- System.out.printf("Enter how big is your car's fueltank(liters): ");
- maxLoad = sc.nextDouble();
- Car c1 = new Car(name, maxLoad);
- System.out.printf("Enter how many liters you want to load: ");
- litters = sc.nextDouble();
- System.out.println();
- Litters lit1 = new Litters(litters);
- c1.add(lit1);
- System.out.println("What is your car's gas mileage on regular gasoline (liters/100km) ");
- regularGasMileage = sc.nextDouble();
- double maxDistance = (litters / regularGasMileage) * 100;
- System.out.printf("You will be able to pass " + "%.0f", maxDistance);
- System.out.print(" km!");
- }
- }
- --------------------------------------------------------------------
- import java.util.ArrayList;
- public class Car {
- private String name;
- private double maxLoad;
- private ArrayList<Litters> cargo;
- public Car(String name, double maxLoad) {
- this.name = name;
- this.maxLoad = maxLoad;
- this.cargo = new ArrayList<Litters>();
- }
- public void add(Litters litri) {
- if (litri.getLiters() > this.maxLoad) {
- System.out.println(this.name + " can't load " + litri.getLiters() + " liters");
- } else {
- System.out.println(this.name + " loaded " + litri.getLiters() + " liters");
- this.cargo.add(litri);
- }
- }
- }
- --------------------------------------------------------------------
- public class Litters {
- private double litters;
- public Litters(double litters) {
- this.litters = litters;
- }
- public double getLiters() {
- return litters;
- }
- public void setLiters(double litters) {
- this.litters = litters;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement