diff --git a/2020-2021/src/TD2/interactions/App.java b/2020-2021/src/TD2/interactions/App.java index 74ede4c..8603f41 100644 --- a/2020-2021/src/TD2/interactions/App.java +++ b/2020-2021/src/TD2/interactions/App.java @@ -8,10 +8,11 @@ public class App { public static void main( String[] args ) throws Exception { - Controleur controleur; + @SuppressWarnings("unused") + Controleur controleur; try { controleur = new Controleur(); - controleur.start(); + //controleur.start(); } catch (Exception e) { e.printStackTrace(); } diff --git a/2020-2021/src/TD4/cars/CarRental.java b/2020-2021/src/TD4/cars/CarRental.java index 7341d19..5610c2f 100644 --- a/2020-2021/src/TD4/cars/CarRental.java +++ b/2020-2021/src/TD4/cars/CarRental.java @@ -2,6 +2,8 @@ package TD4.cars; import java.time.LocalDate; +import TD4.core.PayingItem; + /** * * The Car Rental class represents the rental of a car, for a given duration and start date. @@ -14,7 +16,7 @@ import java.time.LocalDate; * @author blay * */ -public class CarRental { +public class CarRental implements PayingItem{ private Car car; private double dayPrice; diff --git a/2020-2021/src/TD4/cars/CarRentalService.java b/2020-2021/src/TD4/cars/CarRentalService.java index 7ec358a..7b1672f 100644 --- a/2020-2021/src/TD4/cars/CarRentalService.java +++ b/2020-2021/src/TD4/cars/CarRentalService.java @@ -2,8 +2,10 @@ package TD4.cars; import java.time.LocalDate; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; +import TD4.core.Service4PI; import TD4.util.DateTools; import TD4.util.NotPossibleCarRentalException; @@ -17,22 +19,14 @@ import TD4.util.NotPossibleCarRentalException; * * */ -public class CarRentalService { +public class CarRentalService extends Service4PI { //Set of cars for rent private List cars; - - //All registered car rentals - private List carRentals = new ArrayList<>(); - - - - - //To create a car rental service, you need to have cars. public CarRentalService(List cars) { - super(); + super(new ArrayList<>()); this.cars = cars; } @@ -55,7 +49,7 @@ public class CarRentalService { private boolean isAvailable(Car c, LocalDate[] dates) { - for (CarRental carRental : carRentals) { + for (CarRental carRental : super.payingItemList) { if (c.equals(carRental.getCar()) && (carRental.includeADate(dates)) ) { return false; @@ -81,11 +75,20 @@ public class CarRentalService { LocalDate[] dates = DateTools.getDays(fromDate, numberOfDays); if (isAvailable(c, dates)) { carRental = new CarRental(c, fromDate, numberOfDays); - carRentals.add(carRental); + super.payingItemList.add(carRental); } return carRental; } + public List sortedByPrice() { + super.payingItemList.sort(Comparator.comparing(CarRental::getPrice)); + return new ArrayList<>(super.payingItemList); + } + + public CarRental getCarRentalWithBestPrice() { + return this.sortedByPrice().get(0); + } + } diff --git a/2020-2021/src/TD4/flights/Flight.java b/2020-2021/src/TD4/flights/Flight.java index 03276a2..e0ff92e 100644 --- a/2020-2021/src/TD4/flights/Flight.java +++ b/2020-2021/src/TD4/flights/Flight.java @@ -4,6 +4,8 @@ import java.time.LocalDate; import java.time.LocalTime; import java.util.Random; +import TD4.core.PayingItem; + /** * * @@ -15,7 +17,7 @@ import java.util.Random; * * */ -public class Flight { +public class Flight implements PayingItem { private static final int NOT_ASSIGNED = -1; private static final String DEFAULT_DESTINATION= "Paris"; diff --git a/2020-2021/src/TD4/flights/FlightService.java b/2020-2021/src/TD4/flights/FlightService.java index 87df449..06e3df2 100644 --- a/2020-2021/src/TD4/flights/FlightService.java +++ b/2020-2021/src/TD4/flights/FlightService.java @@ -7,6 +7,8 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; +import TD4.core.Service4PI; + /** * This class allows the management of a set of flights * @@ -15,12 +17,12 @@ import java.util.stream.Stream; * */ -public class FlightService { +public class FlightService extends Service4PI { - private List flights = new ArrayList<>(); + //private List flights = new ArrayList<>(); public FlightService(List flights) { - this.flights = flights; + super(flights); } /** @@ -28,7 +30,7 @@ public class FlightService { * @return the list of flights available on a given date {@code LocalDate} */ public List getFlights(LocalDate aDate) { - Stream parallelStream = flights.parallelStream(); + Stream parallelStream = super.payingItemList.parallelStream(); Stream results = parallelStream.filter(f -> (f.getDepartDate().equals(aDate))); return results.collect(Collectors.toCollection(ArrayList::new)); } @@ -41,7 +43,7 @@ public class FlightService { * a place to another place */ public List getFlights(LocalDate d, String from, String to) { - Stream parallelStream = flights.parallelStream(); + Stream parallelStream = super.payingItemList.parallelStream(); Stream results = parallelStream.filter(f -> f.match(d, from, to)); return results.collect(Collectors.toCollection(ArrayList::new)); } @@ -51,8 +53,8 @@ public class FlightService { * not cloned. */ public List sortedByPrice() { - flights.sort(Comparator.comparing(Flight::getPrice)); - return new ArrayList<>(flights); + super.payingItemList.sort(Comparator.comparing(Flight::getPrice)); + return new ArrayList<>(super.payingItemList); } public Flight getFlyWithBestPrice() {