GithubHelp home page GithubHelp logo

shouryaj98 / hotel-management-project-java Goto Github PK

View Code? Open in Web Editor NEW
309.0 11.0 402.0 15 KB

It is a Hotel Management tool which can be used to manage activites like storing customer details, booking rooms of four different types, ordering food for particular rooms, unbooking rooms and showing the bill.

License: MIT License

Java 100.00%
hotel-management object-oriented-programming java-project java oop

hotel-management-project-java's Introduction

Hotel-Management-OOP-Project

This is a Hotel Management tool which can be used to manage activites like storing customer details, booking rooms of four different types, ordering food for particular rooms, unbooking rooms and showing the bill. It can also be used to see different room features and room availibility. It is a menu driven program and it runs until the user exits. File handling has been used to store the current status of the hotel(customer details, booked rooms, food ordered) in a file once the program exits so that when we restart the program, the old details are not lost. The program reads the file when it restarts to know the previous status of the hotel. Writing of file has been done in a separate thread as it can be done parallely. User defined exception is thrown if the user tries to book an already allotted room. Exception handling is properly done to deal with any kind of unexpected exception.

Topics Covered-

Classes and Objects, Inheritance, File Handling with Objects, ArrayList, implementing Interface, User defined exception and Exception handling.

hotel-management-project-java's People

Contributors

anushac07 avatar shouryaj98 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hotel-management-project-java's Issues

SF_SWITCH_NO_DEFAULT

report name: DM_DEFAULT_ENCODING
description:

To reproduce:
Eclipse development env:
SpotBugs
Expected Behavior:
Should have a default for the following code:

Food(int itemno,int quantity)
{

  this.itemno=itemno;
    this.quantity=quantity;
    switch(itemno)v
    {
        case 1:price=quantity*50;
            break;
        case 2:price=quantity*60;
            break;
        case 3:price=quantity*70;
            break;
        case 4:price=quantity*30;
            break;
    }
}

}

enviorment:
eclipse env:
Possible solution: shoulde have default for the code above
Impact: low
Severity: low

Implement Creational Pattern: Singleton

Hi, I noticed another issue that can be solved with the use of a pattern. The thing is that for your program you just need one instance of the hotel, having multiple instance can end in a disaster for booking, etc. So the suggestion is simple, keep all your variables in the class Hotel static and private (you already have them static), but also create a new variable for storing the singleton instance, and create a new public method for getting this instance. I hope this helps you :) .

Desing Pattern

Se recomienda el uso de Factory Method para la creación de nuevos tipos de habitaciones en el caso de que se necesiten en un futuro, esto da flexibilidad al código y nos ayuda a entenderlo de una mejor manera.

Violation of Liskov Substitution Principle

Hello, this message is part of an assignment held by a software design class im taking.

According to the LSP, it states that an object of a superclass should be replaceable by objects of its subclasses without causing issues in the application. The violation of the principle is visible in the class Singleroom and DoubleRoom.
I will suggest writing a superclass Room, from which singleroom and doubleroom can extend, this will give more flexibility in the design.

Exception is caught when Exception is not thrown in Main.main

Bug report: Exception is caught when Exception

Decription: Hotel-Management-Project-Java/Main.java:591 Exception is caught when Exception is not thrown in Main.main(String[]) [Of Concern(15), High confidence]

Tools usage: SpotBugs

To Repoduce:
using eclispe for Java develomet:
using the PMD to check the bugs
line : 591-595
expeced Behavior
catch(Exception e)
{
System.out.println("Not a valid input");
}

for catch the Exception e, we should throw the exception.

enviroment:
Eclipse ;

possible solution
catch(Exception e)
{
System.out.println("Not a valid input"+e.toString());
}

Severity:
low

Open-Close Principle

Hello!
I communicate to you about a violation with Open-Close Principle inside of Hotel Class because of possibilities in add different services given by hotel, is necessary to implement an interface which doing these works due to variety of rooms and avoid risk in constantly modifications on principal class.

Implement Behavioral Pattern: Chain of Responsibility

Hi, I was checking your code for a homework and I wanted to suggest you a better way to handle room types. As you can see in the title is the pattern Chain of Responsibility, using this pattern with the types of rooms will allow you to have a better organization of the code and in case it needs maintenance or to add a new feature/service it will be easier. The first thing you need to do is create an interface Room and then create different classes for each type of room, as a result you wont need to do a switch statement to look for the type of room, you will simply create an object of the type of room. Hope this can help you, thanks.

SOLID violations and OOP misuse

This message is for educational purposes:

The class model that you propose does not reflect the actual interaction between a Hotel, its Rooms and its Food services. This lack of a proper model also causes a series of SOLID violations, which limits the program's flexibility and expansion.

SOLID violation:

  • A monolithic Hotel class that, violation of SRP
  • Abuse of switch in the Hotel functions, violation of OCP
  • Lack of abstraction for the customer, violation of DIP
  • Lack of abstraction for the gender, violation of DIP
  • Poorly implemented inheritance, LSP violation

These violations also reflect misuse of OOP, instead of storing data as classes itself. instead of using switches for saving these properties like the price of only 4 food items and only for types of bedroom, burning ta values in code instead of depending on variables and abstractions.

Tarea_SOLID

The proposed new model separates the responsibilities of the Hotel into the classes Floor, Reception and Restaurant breaking down the monolithic Hotel class. The abstraction of the customer as the class Client provides an abstraction that also supports the use of the collection for saving n number of customer in the new Booking class, which take care of all services related to the customer time in the Hotel like its Room and the Food order from the restaurant. This last service is supported by Food_order, which provides an abstraction for every food service used by the Client.

The class Floor allows easy management of Rooms, which now contain all the attributes of an actual room and every single one can be configured with the necessary price, capacity and luxury or not luxury. This also eliminates the use of inheritance for the room, which in a real Hotel will not make sense.

A reflector version of the code applying this model can be found here: https://github.com/gabreilAlexKH/Tarea_SOLID.git
This just incorporates the new model and gets rid of the overuse of switches in the methods. The logic of the methods is kept, but now they accept the Room or the Room´s Floor or its current Booking as parameters. But it does not support Exception handling as the original one and the long-term storage has been eliminated, because it did not work in the original.
image
image
image
image
image

The main class has suffered minor modifications, just eliminating the switches for options 4 and 5:
image

If you have any questions, please refer to the above-mentioned repository.

Code Smells

Switch Statement
I found a switch on the bookroom method wich is too large
image
You can solve it applying the Replace Type Code with State/Strategy refactoring
image
Dead Code
On the class Singleroom you have a parameter which is not used by the class
image
You can solve it applying Remove Parameter refactoring
image
Large Class
The class Hotel is too large and has too many responsabilities. More than 5 methods.
image
You can solve it creating new classes and group those methods
image
image
image
image
image

Code design and Implementation.

There is an issue in this project as it is taking any number of digits contact number and I can type anything on the gender field.

Food works only for a fixed amount of items

The Food class wouldn't be able to handle a different item that the ones listed there, and if an indefinite amount of items were added this code wouldn't be able to handle it.

Food(int itemno,int quantity)
    {
        this.itemno=itemno;
        this.quantity=quantity;
        switch(itemno)
        {
            case 1:price=quantity*50;
                break;
            case 2:price=quantity*60;
                break;
            case 3:price=quantity*70;
                break;
            case 4:price=quantity*30;
                break;
        }
    }

This is a violation to the Open Closed Principle of SOLID design, because this is not open for extension.

Create a Website for this Repo

Hi there.

Is there a website for this repo?

Because if you don't have, well, this repo can simply be turned into a website right away. Others will discover this project in that website.

Steps:

  1. Go to Settings and look for GitHub Pages, scroll down. That's almost at the bottom.

  2. You will see there: Branch:none, so you should change that to master because you have a README.md file in the master repo. This will be your page. Click Save first.

  3. Then click Choose a theme, you select a predefined theme of your site.

  4. Visit your site now! The URL will be https://shouryaj98.github.io/Hotel-Management-Project-Java.

If you were amazed by that, simply read the documentation about GitHub Pages.

Refactoring Suggestion - Addressing Primitive Obsession

Hi shoryaj98,

I trust this message finds you well. In my recent review of your code, I observed a potential instance of "Primitive Obsession" in the bill method, specifically with the use of primitive type codes to represent room types. I'd like to propose a refactoring using the "Replace Type Code with Class" technique.

Why Refactor?

Code Clarity: Using primitive type codes for room types can lead to confusion and makes the code less self-explanatory.
Maintainability: By replacing type codes with a dedicated class, the code becomes more maintainable and adaptable to future changes.

Refactoring Proposal:

public class Room {
    private double roomCharge;

    public Room(double roomCharge) {
        this.roomCharge = roomCharge;
    }

    public double getRoomCharge() {
        return roomCharge;
    }
}

public class BillProcessor {
    public static void bill(Room room, int roomNumber) {
        double amount = room.getRoomCharge();
        // ... rest of the billing logic
    }
}

// Usage:
Room luxuryDoubleRoom = new Room(4000);
Room deluxeDoubleRoom = new Room(3000);
// ... create instances for other room types

BillProcessor.bill(luxuryDoubleRoom, roomNumber);

In this refactoring, I did a rework to the Room class that encapsulates the behavior related to room types. Each room type is represented by an instance of the Room class with its specific room charge.

Feel free to consider this suggestion and adapt it to your specific needs. If you have any questions or need further clarification, please don't hesitate to reach out.

Best regards,
[Your Name]

Violation of SRP

The class Hotel is implementing too many static methods, implying a lot of responsibility in a single class.

Refactoring Suggestion - Addressing Long Method

Hi shouryaj98,

I trust this message finds you well. During my recent code review, I noticed a potential improvement opportunity in the bookroom method. It exhibits characteristics of a "Long Method," which can impact code readability and maintainability. I'd like to propose a refactoring using the "Preserve Whole Object" technique.

Why Refactor?

Readability: Long methods can be challenging to read and understand. Breaking them into smaller, focused methods enhances code readability.
Maintainability: Smaller methods are easier to maintain and update, promoting a more agile development process.
Refactoring Proposal:

public class RoomBooking {
    private static Scanner sc = new Scanner(System.in);

    public static void bookroom(int roomType) {
        int roomNumber = displayAvailableRooms(roomType);

        if (roomNumber != -1) {
            try {
                CustDetails(roomType, roomNumber);
                System.out.println("Room Booked");
            } catch (Exception e) {
                System.out.println("Invalid Option");
            }
        } else {
            System.out.println("Enter valid option");
        }
    }

    private static int displayAvailableRooms(int roomType) {
        int roomNumberOffset = 0;
        Room[] rooms;

        switch (roomType) {
            case 1:
                rooms = hotel_ob.luxury_doublerrom;
                break;
            case 2:
                rooms = hotel_ob.deluxe_doublerrom;
                roomNumberOffset = 10;
                break;
            case 3:
                rooms = hotel_ob.luxury_singleerrom;
                roomNumberOffset = 30;
                break;
            case 4:
                rooms = hotel_ob.deluxe_singleerrom;
                roomNumberOffset = 40;
                break;
            default:
                return -1;
        }

        System.out.println("\nChoose room number from : ");
        for (int j = 0; j < rooms.length; j++) {
            if (rooms[j] == null) {
                System.out.print(j + roomNumberOffset + ",");
            }
        }

        System.out.print("\nEnter room number: ");
        return sc.nextInt() - roomNumberOffset;
    }
}

By breaking down the bookroom method into smaller, focused methods, we improve the overall readability and maintainability of the code. Each method now has a clear and specific responsibility.

Feel free to incorporate this suggestion, and if you have any questions or need further assistance, please don't hesitate to reach out.

Report of SOLID

HI! this message is for educational purpose.

The Hotel class is full of static methods, maybe you need share those methods. Single Responsibility Principle.

The whole program don't have extension for rooms, if the manager hotel needs change the rules business of rooms, he cannot. For this problem, I would create a interface "rooms" which contains a method that allow keep the extension. Open-Close Principle.

A DoubleRoom doesn't have polymorphism. Liskov Substitution Principle.

The Food class could be used for more of one service, better create a interface "Services" and then microservices for any room in the hotel. Interface Segregation Principle

Rooms store a previously set amount of guests

After solving #3 and applying #4 there was a violation to the Open Closed Principle of SOLID design, because the rooms store a set amount of guests, this is not open for extension in case a room that allows three o six persons opens at the hotel. The non-compliant code is the following:

class Singleroom implements Serializable
{
    Guest guest;
class Doubleroom extends Singleroom implements Serializable
{ 
    Guest guest2;  

Rooms store unnecesary values

In the following code there's a violation to the Single Responde Principle of SOLID design.

public class Singleroom implements Serializable{
    String name;
    String contact;
    String gender;   
    ArrayList<Food> food =new ArrayList<>();`

class Doubleroom extends Singleroom implements Serializable
{ 
    String name2;
    String contact2;
    String gender2;  

The room stores the people that stay in the room, but doesn't need to store the personal info, there should be a new class of Guest that stores these values and the rooms only need to have this as their instance variable.

OS_OPEN_STREAM

report name: OS_OPEN_STREAM

To reproduce:
Eclipse development env:
SpotBugs
Expected Behavior:
the file open the stream and without a close stream, which will make the application memory leaking and crash

    try
    {           
    File f = new File("backup");
    if(f.exists())
    {
        FileInputStream fin=new FileInputStream(f);
        ObjectInputStream ois=new ObjectInputStream(fin);
        Hotel.hotel_ob=(holder)ois.readObject();
    }
    Scanner sc = new Scanner(System.in);
    int ch,ch2;
    char wish;
    x:
    do{

    System.out.println("\nEnter your choice :\n1.Display room details\n2.Display room availability \n3.Book\n4.Order food\n5.Checkout\n6.Exit\n");
    ch = sc.nextInt();
    switch(ch){
        case 1: System.out.println("\nChoose room type :\n1.Luxury Double Room \n2.Deluxe Double Room \n3.Luxury Single Room \n4.Deluxe Single Room\n");
                ch2 = sc.nextInt();
                Hotel.features(ch2);
            break;
        case 2:System.out.println("\nChoose room type :\n1.Luxury Double Room \n2.Deluxe Double Room \n3.Luxury Single Room\n4.Deluxe Single Room\n");
                 ch2 = sc.nextInt();
                 Hotel.availability(ch2);
            break;
        case 3:System.out.println("\nChoose room type :\n1.Luxury Double Room \n2.Deluxe Double Room \n3.Luxury Single Room\n4.Deluxe Single Room\n");
                 ch2 = sc.nextInt();
                 Hotel.bookroom(ch2);                     
            break;
        case 4:
             System.out.print("Room Number -");
                 ch2 = sc.nextInt();
                 if(ch2>60)
                     System.out.println("Room doesn't exist");
                 else if(ch2>40)
                     Hotel.order(ch2-41,4);
                 else if(ch2>30)
                     Hotel.order(ch2-31,3);
                 else if(ch2>10)
                     Hotel.order(ch2-11,2);
                 else if(ch2>0)
                     Hotel.order(ch2-1,1);
                 else
                     System.out.println("Room doesn't exist");
                 break;
        case 5:                 
            System.out.print("Room Number -");
                 ch2 = sc.nextInt();
                 if(ch2>60)
                     System.out.println("Room doesn't exist");
                 else if(ch2>40)
                     Hotel.deallocate(ch2-41,4);
                 else if(ch2>30)
                     Hotel.deallocate(ch2-31,3);
                 else if(ch2>10)
                     Hotel.deallocate(ch2-11,2);
                 else if(ch2>0)
                     Hotel.deallocate(ch2-1,1);
                 else
                     System.out.println("Room doesn't exist");
                 break;
        case 6:break x;
            
    }
       
        System.out.println("\nContinue : (y/n)");
        wish=sc.next().charAt(0); 
        if(!(wish=='y'||wish=='Y'||wish=='n'||wish=='N'))
        {
            System.out.println("Invalid Option");
            System.out.println("\nContinue : (y/n)");
            wish=sc.next().charAt(0); 
        }
        
    }while(wish=='y'||wish=='Y');    
    
    Thread t=new Thread(new write(Hotel.hotel_ob));
    t.start();
    }        
        catch(Exception e)
        {
            System.out.println("Not a valid input");
        }
}

}

enviorment:
eclipse env:
Possible solution: should close the file stream without making the application crash
Impact: high
Severity: high

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.