madhuv-sharma / hotel-reservation-system Goto Github PK
View Code? Open in Web Editor NEWHotel Reservation System, in Java, having all basic functionalities, following Object Oriented Programming and having easy-to-use interface.
Hotel Reservation System, in Java, having all basic functionalities, following Object Oriented Programming and having easy-to-use interface.
Greetings,
After examining the code for your Hotel Reservation System project, I have pinpointed several areas where improvements can be made to boost efficiency, address specific errors and even some code improvements following SOLID design principles.
interface Service {
void setDetails();
int getTotalCost();
boolean getStatus();
}
interface Room {
int getRate();
void setDetails(int rate, boolean wifi, boolean status);
boolean getStatus();
boolean getWifi();
void changeStatus();
}
abstract class AbstractRoom implements Room {
protected int rate;
protected boolean wifi;
protected boolean status;
public int getRate() {
return rate;
}
public void setDetails(int rate, boolean wifi, boolean status) {
this.rate = rate;
this.wifi = wifi;
this.status = status;
}
public boolean getStatus() {
return status;
}
public boolean getWifi() {
return wifi;
}
public void changeStatus() {
this.status = !this.status;
}
}
class StandardRoom extends AbstractRoom {
public StandardRoom() {
this.rate = 5000;
this.wifi = false;
this.status = true;
}
}
class DeluxeRoom extends AbstractRoom {
public DeluxeRoom() {
this.rate = 7000;
this.wifi = true;
this.status = true;
}
}
class SuperDeluxeRoom extends AbstractRoom {
public SuperDeluxeRoom() {
this.rate = 9000;
this.wifi = true;
this.status = true;
}
}
class LaundryService implements Service {
private int type;
private int cost;
private int quantity;
private boolean status;
public LaundryService() {
this.type = 0;
this.cost = 0;
this.quantity = 0;
this.status = false;
}
@Override
public void setDetails() {
Scanner in = new Scanner(System.in);
System.out.println("Enter type of wash (1/2/3): ");
type = in.nextInt();
System.out.println("Enter quantity of clothes: ");
quantity = in.nextInt();
if (type == 1)
cost = 100;
else if (type == 2)
cost = 200;
else if (type == 3)
cost = 300;
else
cost = 0;
status = true;
}
@Override
public int getTotalCost() {
return quantity * cost;
}
@Override
public boolean getStatus() {
return status;
}
}
class TransportationService implements Service {
private int type;
private int cost;
private int quantity;
private boolean status;
public TransportationService() {
this.type = 0;
this.cost = 0;
this.quantity = 0;
this.status = false;
}
@Override
public void setDetails() {
Scanner in = new Scanner(System.in);
System.out.println("Enter type of transportation (1/2/3): ");
type = in.nextInt();
System.out.println("Enter number of people: ");
quantity = in.nextInt();
if (type == 1)
cost = 100;
else if (type == 2)
cost = 200;
else if (type == 3)
cost = 300;
else
cost = 0;
status = true;
}
@Override
public int getTotalCost() {
return quantity * cost;
}
@Override
public boolean getStatus() {
return status;
}
}
public class HRS_Main {
private Room room;
private List<Service> services;
public HRS_Main(Room room) {
this.room = room;
this.services = new ArrayList<>();
}
public void addService(Service service) {
services.add(service);
}
public double calculateTotalCost() {
double totalCost = room.getRate();
for (Service service : services) {
totalCost += service.getTotalCost();
}
double gst = totalCost * 0.18;
return totalCost + gst;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Room room = null;
System.out.println("Select room type (1: Standard, 2: Deluxe, 3: Super Deluxe): ");
int roomType = sc.nextInt();
switch (roomType) {
case 1:
room = new StandardRoom();
break;
case 2:
room = new DeluxeRoom();
break;
case 3:
room = new SuperDeluxeRoom();
break;
default:
System.out.println("Invalid room type selected.");
System.exit(0);
}
HRS_Main booking = new HRS_Main(room);
System.out.println("Do you want laundry service? (Y/N): ");
char laundryOption = sc.next().charAt(0);
if (laundryOption == 'Y' || laundryOption == 'y') {
Service laundryService = new LaundryService();
laundryService.setDetails();
booking.addService(laundryService);
}
System.out.println("Do you want transportation service? (Y/N): ");
char transportOption = sc.next().charAt(0);
if (transportOption == 'Y' || transportOption == 'y') {
Service transportationService = new TransportationService();
transportationService.setDetails();
booking.addService(transportationService);
}
double totalCost = booking.calculateTotalCost();
System.out.println("Total cost: " + totalCost);
System.out.println("**********Thank you for your visit.**********\n**********We hope to see you again!**********");
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.