Commit 8a8212b0 authored by Eskil Helgesen Schjølberg's avatar Eskil Helgesen Schjølberg
Browse files

Uferdig oppgave

parent a1f0c15b
public class Booking {
private int numberOfPersons;
private int bookingDate;
private int room_id;
public Booking(int room_id, int numberOfPersons, int bookingDate){
this.room_id = room_id;
this.numberOfPersons = numberOfPersons;
this.bookingDate = bookingDate;
}
public int getRoom_id() {
return room_id;
}
public int getBookingDate() {
return bookingDate;
}
public int getNumberOfPersons() {
return numberOfPersons;
}
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Controller {
String[] roomTypeList = {"Bryllupssuite", "Businessuite", "Kvalitetsrom", "Lavprisrom"};
private List<Room> registreredRoomList = new ArrayList<>();
private List<Booking> bookedRoomList = new ArrayList<>();
public boolean registerRoom(int capasity, int price, String type) {
for (int i = 0; i < roomTypeList.length; i++) {
if (type.equalsIgnoreCase(roomTypeList[i])) {
Room room = new Room(capasity, price, type);
return registreredRoomList.add(room);
}
}
System.out.println("Type rom finnes ikke");
return false;
}
public boolean bookRoom(int room_id, int numberOfPersons, int bookingDate ) {
if (room_id <= registreredRoomList.size()) {
if (numberOfPersons <= registreredRoomList.get(room_id-1).getCapasity()) {
for (Booking booking : bookedRoomList) {
if (booking.getRoom_id() == room_id && booking.getBookingDate() == bookingDate ) {
System.out.println("Rommet er allerde reservert paa denne datoen");
return false;
}
}
Booking booking = new Booking(room_id, numberOfPersons, bookingDate);
bookedRoomList.add(booking);
return true;
}
else{
System.out.println("Ikke nok plasser paa dette rommet");
return false;
}
}
else{
System.out.println("Rom finnes ikke");
return false;
}
}
public int fetchTotalRoomIncome(int room_id) {
int totalBookingsByRoom = 0;
int roomPrice = registreredRoomList.get(room_id-1).getPrice();
for (Booking booking : bookedRoomList) {
if (booking.getRoom_id() == room_id) {
totalBookingsByRoom ++;
}
}
int totalIncome = totalBookingsByRoom * roomPrice;
return totalIncome;
}
public List<Room> allRoomsByIncome() {
List<Room> roomsSortedByIncome = new ArrayList<>();
Collections.copy(roomsSortedByIncome, registreredRoomList);
roomsSortedByIncome.sort(new IncomeSorter().reversed());
return roomsSortedByIncome;
}
public class IncomeSorter implements Comparator<Room> {
@Override
public int compare(Room o1, Room o2) {
Integer a = Integer.valueOf(fetchTotalRoomIncome(o2.getRoom_id()));
Integer b = Integer.valueOf(fetchTotalRoomIncome(o1.getRoom_id()));
return a.compareTo(b);
}
}
public int nrOfDaysBookedStraight(int room_id) {
int nrOfDays = 0;
List<Integer> bookedRoomListById = new ArrayList<>();
for (Booking booking : bookedRoomList) {
if (booking.getRoom_id() == room_id) {
bookedRoomListById.add(booking.getBookingDate());
}
}
Collections.sort(bookedRoomListById);
int temp1 = 0;
for (Integer integer : bookedRoomListById) {
if (integer == temp1+1) {
nrOfDays++;
}
temp1 = integer;
}
return nrOfDays;
}
}
public class ControllerTest {
static Controller controller = new Controller();
public static void main(String[] args) {
boolean registerdRoom1 = controller.registerRoom(3, 1000, "Kvalitetsrom");
boolean registerdRoom2 = controller.registerRoom(2, 2000, "Bryllupssuite");
boolean registerdRoom3 = controller.registerRoom(2, 3000, "Businessuite");
boolean registerdRoom4 = controller.registerRoom(4, 500, "Lavprisrom");
boolean registerdRoom5 = controller.registerRoom(3, 1000, "Kvalitetsrom");
boolean registerdRoom6 = controller.registerRoom(3, 5000, "Businessuite");
boolean registerdRoom7 = controller.registerRoom(4, 2000, "Kvalitetsrom");
boolean registerdRoom8 = controller.registerRoom(2, 10000, "Bryllupssuite");
boolean registerdRoom9 = controller.registerRoom(2, 2000, "Kvalitetsrom");
boolean registerdRoom10 = controller.registerRoom(4, 5000, "Businessuite");
boolean registerdRoom11 = controller.registerRoom(3, 500, "Lavprisrom");
System.out.println(controller.bookRoom(3, 1, 10497));
System.out.println(controller.fetchTotalRoomIncome(3));
}
}
public class Room {
private static int room_id_generator = 0;
private int room_id;
private int capasity;
private int price;
private String type;
public Room(int capasity, int price, String type){
room_id_generator ++;
room_id = room_id_generator;
this.capasity = capasity;
this.price = price;
this.type = type;
}
public int getCapasity() {
return capasity;
}
public int getPrice() {
return price;
}
public String getType() {
return type;
}
public int getRoom_id() {
return room_id;
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment