Skip to content

Instantly share code, notes, and snippets.

@danielsimao
Created March 31, 2020 21:30
Show Gist options
  • Save danielsimao/929e8c43d4d9e1508e9c685ccb8e392b to your computer and use it in GitHub Desktop.
Save danielsimao/929e8c43d4d9e1508e9c685ccb8e392b to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Agency agency = new Agency();
System.out.println(agency.getName());
System.out.println("--- Menu ---");
Scanner sc = new Scanner(System.in);
System.out.println("-> Alojamento");
System.out.println(" - Reservar apartamento (1)");
System.out.println(" - Reservar quarto de hotel (2)");
System.out.println(" - Check-out de apartamento (3)");
System.out.println(" - Check-out de hotel (4)");
System.out.println("-> Aluguer de carros");
System.out.println(" - Levantar carro (5)");
System.out.println(" - Entregar carro (6)");
//NÃO DIZ QUE TEM ESTES
//PRINT DA LISTA MAL
Lodging apartment1 = new Apartment("A25", "SJA" , 3, "Aveiro");
Lodging apartment2 = new Apartment("A90", "BP" , 2, "Porto");
Lodging apartment3 = new Apartment("A290", "BL" , 5, "Lisboa");
Lodging hotelRoom1 = new HotelRoom("H34", "HSP", "Porto", "double");
Lodging hotelRoom2 = new HotelRoom("H001", "HIA", "Algarve", "twin");
agency.setOfLodgings.add(apartment1); agency.setOfLodgings.add(apartment2); agency.setOfLodgings.add(apartment3);
agency.setOfLodgings.add(hotelRoom1); agency.setOfLodgings.add(hotelRoom2);
CarRental car1 = new CarRental('A', "diesel");
CarRental car2 = new CarRental('D', "diesel");
CarRental car3 = new CarRental('F', "gasolina");
agency.setOfRentalCars.add(car1); agency.setOfRentalCars.add(car2); agency.setOfRentalCars.add(car3);
System.out.print("Opção ");
int option = sc.nextInt();
System.out.println(agency.setOfLodgings);
switch (option) {
case 1:
System.out.println("Código: ");
String code1 = sc.next();
agency.checkIn(code1);
case 3:
System.out.println("Código: ");
String code3 = sc.next();
agency.checkOut(code3);
default:
System.out.println(agency.toString());
}
sc.close();
}
}
class Agency {
private final String name = "Agência Travel Aveiro";
private final String address = "Rua Luís de Camões";
ArrayList<Lodging> setOfLodgings = new ArrayList<Lodging>();
ArrayList<CarRental> setOfRentalCars = new ArrayList<CarRental>();
public Agency() {}
public Lodging checkIn(String code) {
for(Lodging lodging : setOfLodgings) {
if(lodging.getCode().equals(code) && lodging.isAvailable() == true) {
lodging.toggleAvailability();
System.out.println("Check-in bem sucedido.");
System.out.println("Preço por noite: " + lodging.getPricePerNight() + "€");
return lodging;
}
}
System.out.println("Quarto com código " + code + " não existe.");
return null;
}
public Lodging checkOut(String code) {
for(Lodging lodging : setOfLodgings) {
if(lodging.getCode().equals(code) && lodging.isAvailable() == false) {
lodging.toggleAvailability();
Scanner sc = new Scanner(System.in);
System.out.println("Check-out bem sucedido");
System.out.print("Avaliação [1.0,5.0]: ");
double eval = sc.nextDouble();
lodging.setEvaluation(eval);
return lodging;
}
}
System.out.println("Quarto com código " + code + " não existe.");
return null;
}
public String getName() {return name;}
public String getAddress() {return address;}
@Override
public String toString() {
return "Agência " + name + ", \nendereço: " + address + "\nAlojamentos : " + setOfLodgings + "\nCarros de aluguer : " + setOfLodgings;
}
}
class Lodging extends Agency {
private String code;
private String lodgingName;
private String place;
private double pricePerNight = 10;
private boolean isAvailable = true;
private double evaluation;
public Lodging(String code, String lodgingName, String place) {
//super();
this.code = code;
this.place = place;
this.lodgingName = lodgingName;
}
public String getCode() {return code;}
public void setCode(String code) {
this.code = code;
}
public String getLodgingName() {return lodgingName;}
public void setLodgingName(String lodgingName) {
this.lodgingName = lodgingName;
}
public String getPlace() {return place;}
public void setPlace(String place) {
this.place = place;
}
public double getPricePerNight() {return pricePerNight;}
public void setPricePerNight(double pricePerNight) {
this.pricePerNight = pricePerNight;
}
public boolean isAvailable() {return isAvailable;}
public void setIsAvailable(boolean isAvailable) {
this.isAvailable = isAvailable;
}
public void toggleAvailability() {
this.isAvailable = !this.isAvailable;
}
public double getEvaluation() {return evaluation;}
public void setEvaluation(double evaluation) {
if(1.0 <= evaluation && evaluation <= 5.0) {
this.evaluation = evaluation;
}
}
@Override
public String toString() {
return "\nAlojamento -> Código = " + code + " Nome = " + lodgingName + " Local = " + place + " Preço por noite = "
+ pricePerNight + "€ Disponibilidade = " + isAvailable + " Avaliação = " + evaluation;
}
public void addLodging(Lodging lodging) {
setOfLodgings.add(lodging);
}
public void removeLodging(Lodging lodging) {
setOfLodgings.remove(lodging);
}
}
class CarRental extends Agency {
private char carClass;
private String fuelType;
private boolean isAvailable = true;
public CarRental(char carClass, String fuelType) {
//super();
if(carClass >= 'A' || carClass <= 'F') {
this.carClass = carClass;
}
if(fuelType.toLowerCase() == "gasolina" || fuelType.toLowerCase() == "diesel") {
this.fuelType = fuelType;
}
}
public char getCarClass() {return carClass;}
public void setCarClass(char carClass) {
if(carClass >= 'A' || carClass <= 'F') {
this.carClass = carClass;
}
}
public String getFuelType() {return fuelType;}
public void setFuelType(String fuelType) {
if(fuelType.toLowerCase() == "gasolina" || fuelType.toLowerCase() == "diesel") {
this.fuelType = fuelType;
}
}
public boolean isAvailable() {return isAvailable;}
public void setAvailable(boolean isAvailable) {
this.isAvailable = isAvailable;
}
public void toggleAvailability() {
this.isAvailable = !this.isAvailable;
}
public void addCar(CarRental car) {
setOfRentalCars.add(car);
}
public void removeCar(CarRental car) {
setOfRentalCars.remove(car);
}
public void pickUpRentalCar(CarRental car) {
if(setOfRentalCars.contains(car) == true) {
if(car.isAvailable == true) {
toggleAvailability();
System.out.println("Levantamento bem sucedido.");
}
} else {
System.out.println("Devolução interrompida");
}
}
public void returnRentalCar(CarRental car) {
if(setOfRentalCars.contains(car) == true) {
if(car.isAvailable == false) {
toggleAvailability();
System.out.println("Devolução bem sucedida.");
}
} else {
System.out.println("Devolução interrompida.");
}
}
@Override
public String toString() {
return "Carro -> Classe = " + carClass + " Combustível = " + fuelType + " Disponibilidade = " + isAvailable;
}
}
class HotelRoom extends Lodging {
private String type;
public HotelRoom(String code, String lodgingName, String type, String place) {
super(code, lodgingName, place);
String lowerCaseType = type.toLowerCase();
if(lowerCaseType == "single" || lowerCaseType == "double" || lowerCaseType == "twin" || lowerCaseType == "triple") {
this.type = type;
}
switch (type) {
case "single":
this.setPricePerNight(15.90);
case "triple":
this.setPricePerNight(25.50);
case "twin":
case "double":
default:
this.setPricePerNight(30.90);
}
}
public String getType() {return type;}
public void setType(String type) {
String lowerCaseType = type.toLowerCase();
if(lowerCaseType == "single" || lowerCaseType == "double" || lowerCaseType == "twin" || lowerCaseType == "triple") {
this.type = type;
}
}
}
class Apartment extends Lodging {
private int numberOfRooms;
public Apartment(String code, String lodgingName, int numberOfRooms, String place) {
super(code, lodgingName, place);
this.numberOfRooms = numberOfRooms;
switch (numberOfRooms) {
case 1:
this.setPricePerNight(15.90);
case 2:
this.setPricePerNight(30.90);
default:
this.setPricePerNight(40.90);
}
}
public int getNumberOfRooms() {return numberOfRooms;}
public void setNumberOfRooms(int numberOfRooms) {
this.numberOfRooms = numberOfRooms;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment