implements ok
This commit is contained in:
parent
5da7508ac7
commit
9de6cd5cd6
@ -8,10 +8,11 @@ public class App
|
|||||||
{
|
{
|
||||||
public static void main( String[] args ) throws Exception
|
public static void main( String[] args ) throws Exception
|
||||||
{
|
{
|
||||||
|
@SuppressWarnings("unused")
|
||||||
Controleur controleur;
|
Controleur controleur;
|
||||||
try {
|
try {
|
||||||
controleur = new Controleur();
|
controleur = new Controleur();
|
||||||
controleur.start();
|
//controleur.start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package TD4.cars;
|
|||||||
|
|
||||||
import java.time.LocalDate;
|
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.
|
* 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
|
* @author blay
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class CarRental {
|
public class CarRental implements PayingItem{
|
||||||
|
|
||||||
private Car car;
|
private Car car;
|
||||||
private double dayPrice;
|
private double dayPrice;
|
||||||
|
@ -2,8 +2,10 @@ package TD4.cars;
|
|||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import TD4.core.Service4PI;
|
||||||
import TD4.util.DateTools;
|
import TD4.util.DateTools;
|
||||||
import TD4.util.NotPossibleCarRentalException;
|
import TD4.util.NotPossibleCarRentalException;
|
||||||
|
|
||||||
@ -17,22 +19,14 @@ import TD4.util.NotPossibleCarRentalException;
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class CarRentalService {
|
public class CarRentalService extends Service4PI<CarRental> {
|
||||||
|
|
||||||
//Set of cars for rent
|
//Set of cars for rent
|
||||||
private List<Car> cars;
|
private List<Car> cars;
|
||||||
|
|
||||||
//All registered car rentals
|
|
||||||
private List<CarRental> carRentals = new ArrayList<>();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//To create a car rental service, you need to have cars.
|
//To create a car rental service, you need to have cars.
|
||||||
public CarRentalService(List<Car> cars) {
|
public CarRentalService(List<Car> cars) {
|
||||||
super();
|
super(new ArrayList<>());
|
||||||
this.cars = cars;
|
this.cars = cars;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +49,7 @@ public class CarRentalService {
|
|||||||
|
|
||||||
|
|
||||||
private boolean isAvailable(Car c, LocalDate[] dates) {
|
private boolean isAvailable(Car c, LocalDate[] dates) {
|
||||||
for (CarRental carRental : carRentals) {
|
for (CarRental carRental : super.payingItemList) {
|
||||||
if (c.equals(carRental.getCar()) &&
|
if (c.equals(carRental.getCar()) &&
|
||||||
(carRental.includeADate(dates)) ) {
|
(carRental.includeADate(dates)) ) {
|
||||||
return false;
|
return false;
|
||||||
@ -81,11 +75,20 @@ public class CarRentalService {
|
|||||||
LocalDate[] dates = DateTools.getDays(fromDate, numberOfDays);
|
LocalDate[] dates = DateTools.getDays(fromDate, numberOfDays);
|
||||||
if (isAvailable(c, dates)) {
|
if (isAvailable(c, dates)) {
|
||||||
carRental = new CarRental(c, fromDate, numberOfDays);
|
carRental = new CarRental(c, fromDate, numberOfDays);
|
||||||
carRentals.add(carRental);
|
super.payingItemList.add(carRental);
|
||||||
}
|
}
|
||||||
return carRental;
|
return carRental;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<CarRental> sortedByPrice() {
|
||||||
|
super.payingItemList.sort(Comparator.comparing(CarRental::getPrice));
|
||||||
|
return new ArrayList<>(super.payingItemList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarRental getCarRentalWithBestPrice() {
|
||||||
|
return this.sortedByPrice().get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ import java.time.LocalDate;
|
|||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.util.Random;
|
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 int NOT_ASSIGNED = -1;
|
||||||
private static final String DEFAULT_DESTINATION= "Paris";
|
private static final String DEFAULT_DESTINATION= "Paris";
|
||||||
|
@ -7,6 +7,8 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import TD4.core.Service4PI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class allows the management of a set of flights
|
* 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<Flight> {
|
||||||
|
|
||||||
private List<Flight> flights = new ArrayList<>();
|
//private List<Flight> flights = new ArrayList<>();
|
||||||
|
|
||||||
public FlightService(List<Flight> flights) {
|
public FlightService(List<Flight> 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}
|
* @return the list of flights available on a given date {@code LocalDate}
|
||||||
*/
|
*/
|
||||||
public List<Flight> getFlights(LocalDate aDate) {
|
public List<Flight> getFlights(LocalDate aDate) {
|
||||||
Stream<Flight> parallelStream = flights.parallelStream();
|
Stream<Flight> parallelStream = super.payingItemList.parallelStream();
|
||||||
Stream<Flight> results = parallelStream.filter(f -> (f.getDepartDate().equals(aDate)));
|
Stream<Flight> results = parallelStream.filter(f -> (f.getDepartDate().equals(aDate)));
|
||||||
return results.collect(Collectors.toCollection(ArrayList::new));
|
return results.collect(Collectors.toCollection(ArrayList::new));
|
||||||
}
|
}
|
||||||
@ -41,7 +43,7 @@ public class FlightService {
|
|||||||
* a place to another place
|
* a place to another place
|
||||||
*/
|
*/
|
||||||
public List<Flight> getFlights(LocalDate d, String from, String to) {
|
public List<Flight> getFlights(LocalDate d, String from, String to) {
|
||||||
Stream<Flight> parallelStream = flights.parallelStream();
|
Stream<Flight> parallelStream = super.payingItemList.parallelStream();
|
||||||
Stream<Flight> results = parallelStream.filter(f -> f.match(d, from, to));
|
Stream<Flight> results = parallelStream.filter(f -> f.match(d, from, to));
|
||||||
return results.collect(Collectors.toCollection(ArrayList::new));
|
return results.collect(Collectors.toCollection(ArrayList::new));
|
||||||
}
|
}
|
||||||
@ -51,8 +53,8 @@ public class FlightService {
|
|||||||
* not cloned.
|
* not cloned.
|
||||||
*/
|
*/
|
||||||
public List<Flight> sortedByPrice() {
|
public List<Flight> sortedByPrice() {
|
||||||
flights.sort(Comparator.comparing(Flight::getPrice));
|
super.payingItemList.sort(Comparator.comparing(Flight::getPrice));
|
||||||
return new ArrayList<>(flights);
|
return new ArrayList<>(super.payingItemList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Flight getFlyWithBestPrice() {
|
public Flight getFlyWithBestPrice() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user