From f4268522f4ad2f25912fecabb659253fd7b7a59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A9=E1=84=89=E1=85=A6=E1=84=8B=E1=85=B3?= =?UTF-8?q?=E1=86=AB?= Date: Thu, 12 Dec 2024 18:16:36 +0900 Subject: [PATCH] =?UTF-8?q?Mission1-SSEN=20=EB=B8=8C=EB=9E=9C=EC=B9=98?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=9E=91=EC=97=85=20=EB=82=B4=EC=9A=A9=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/car/Avante.java | 24 +++++++++++++++++ src/main/java/car/Car.java | 11 ++++++++ src/main/java/car/K5.java | 24 +++++++++++++++++ src/main/java/car/Sonata.java | 24 +++++++++++++++++ src/main/java/company/RentCompany.java | 31 ++++++++++++++++++++++ src/test/java/company/RentCompanyTest.java | 28 +++++++++++++++++++ 6 files changed, 142 insertions(+) create mode 100644 src/main/java/car/Avante.java create mode 100644 src/main/java/car/Car.java create mode 100644 src/main/java/car/K5.java create mode 100644 src/main/java/car/Sonata.java create mode 100644 src/main/java/company/RentCompany.java create mode 100644 src/test/java/company/RentCompanyTest.java diff --git a/src/main/java/car/Avante.java b/src/main/java/car/Avante.java new file mode 100644 index 0000000..db2e93e --- /dev/null +++ b/src/main/java/car/Avante.java @@ -0,0 +1,24 @@ +package car; + +public class Avante extends Car { + private final double tripDistance; + + public Avante(double tripDistance) { + this.tripDistance = tripDistance; + } + + @Override + public double getDistancePerLiter() { + return 15.0; + } + + @Override + public double getTripDistance() { + return tripDistance; + } + + @Override + public String getName() { + return "Avante"; + } +} diff --git a/src/main/java/car/Car.java b/src/main/java/car/Car.java new file mode 100644 index 0000000..594b62f --- /dev/null +++ b/src/main/java/car/Car.java @@ -0,0 +1,11 @@ +package car; + +public abstract class Car { + public abstract double getDistancePerLiter(); + public abstract double getTripDistance(); + public abstract String getName(); + + public double getChargeQuantity() { + return getTripDistance() / getDistancePerLiter(); + } +} diff --git a/src/main/java/car/K5.java b/src/main/java/car/K5.java new file mode 100644 index 0000000..eb996aa --- /dev/null +++ b/src/main/java/car/K5.java @@ -0,0 +1,24 @@ +package car; + +public class K5 extends Car { + private final double tripDistance; + + public K5(double tripDistance) { + this.tripDistance = tripDistance; + } + + @Override + public double getDistancePerLiter() { + return 13.0; + } + + @Override + public double getTripDistance() { + return tripDistance; + } + + @Override + public String getName() { + return "K5"; + } +} diff --git a/src/main/java/car/Sonata.java b/src/main/java/car/Sonata.java new file mode 100644 index 0000000..6aef450 --- /dev/null +++ b/src/main/java/car/Sonata.java @@ -0,0 +1,24 @@ +package car; + +public class Sonata extends Car { + private final double tripDistance; + + public Sonata(double tripDistance) { + this.tripDistance = tripDistance; + } + + @Override + public double getDistancePerLiter() { + return 10.0; + } + + @Override + public double getTripDistance() { + return tripDistance; + } + + @Override + public String getName() { + return "Sonata"; + } +} diff --git a/src/main/java/company/RentCompany.java b/src/main/java/company/RentCompany.java new file mode 100644 index 0000000..2050d8f --- /dev/null +++ b/src/main/java/company/RentCompany.java @@ -0,0 +1,31 @@ +package company; + +import car.Car; +import java.util.ArrayList; +import java.util.List; + +public class RentCompany { + private final List cars = new ArrayList<>(); + + private RentCompany() {} + + public static RentCompany create() { + return new RentCompany(); + } + + public void addCar(Car car) { + cars.add(car); + } + + public String generateReport() { + StringBuilder report = new StringBuilder(); + for (Car car : cars) { + report.append(car.getName()) + .append(" : ") + .append((int) Math.ceil(car.getChargeQuantity())) + .append("리터") + .append(System.lineSeparator()); + } + return report.toString(); + } +} diff --git a/src/test/java/company/RentCompanyTest.java b/src/test/java/company/RentCompanyTest.java new file mode 100644 index 0000000..0bd8347 --- /dev/null +++ b/src/test/java/company/RentCompanyTest.java @@ -0,0 +1,28 @@ +package company; + +import car.Avante; +import car.K5; +import car.Sonata; +import company.RentCompany; + +public class RentCompanyTest { + private static final String NEWLINE = System.getProperty("line.separator"); + + public static void main(String[] args) { + RentCompany company = RentCompany.create(); + company.addCar(new Sonata(150)); + company.addCar(new K5(260)); + company.addCar(new Sonata(120)); + company.addCar(new Avante(300)); + company.addCar(new K5(390)); + + String report = company.generateReport(); + System.out.println(report); + // 예상 결과: + // Sonata : 15리터 + // K5 : 20리터 + // Sonata : 12리터 + // Avante : 20리터 + // K5 : 30리터 + } +}