Giter Club home page Giter Club logo

hotel-reservation-system's Issues

Code suggestion using SOLID principles

Introduction

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.

UML Diagram

UML Diagram Hotel Reservation System

Modified Code

Interfaces

Service


interface Service { 

    void setDetails(); 

    int getTotalCost(); 

    boolean getStatus(); 

} 

Room

interface Room { 

    int getRate(); 

    void setDetails(int rate, boolean wifi, boolean status); 

    boolean getStatus(); 

    boolean getWifi(); 

    void changeStatus(); 

} 

Abstract Class

AbstractRoom

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; 

    } 

} 

Classes

StandartRoom

class StandardRoom extends AbstractRoom { 

    public StandardRoom() { 

        this.rate = 5000; 

        this.wifi = false; 

        this.status = true; 

    } 

} 

DeluxeRoom

class DeluxeRoom extends AbstractRoom { 

    public DeluxeRoom() { 

        this.rate = 7000; 

        this.wifi = true; 

        this.status = true; 

    } 

} 

SuperDeluxeRoom

class SuperDeluxeRoom extends AbstractRoom { 

    public SuperDeluxeRoom() { 

        this.rate = 9000; 

        this.wifi = true; 

        this.status = true; 

    } 

} 

LaundryService

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; 

    } 

} 

TransportationService

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; 

    } 

} 

HRS_Main

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!**********"); 

    } 

} 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.