Hello! I'm new to programming and I'm trying to do a basic hotel application using threads in java. Here is what i've already done:

//room class
public class Room {
    private  int idRoom;
    private  int etaj;
    private boolean empty;

    public Room()
    {
        this.idRoom = 0;
        this.etaj = 0;
        this.empty = false;
    }

    public Room(int idRoom, int etaj, boolean empty) {
        this.idRoom = idRoom;
        this.etaj = etaj;
        this.empty = empty;
    }

    public int getEtaj() {
        return etaj;
    }

    public void setEtaj(int etaj) {
        this.etaj = etaj;
    }

    public boolean isEmpty() {
        return empty;
    }

    public void setEmpty(boolean empty) {
        this.empty = empty;
    }

    public int getIdRoom() {
        return idRoom;
    }

    public void setIdRoom(int idRoom) {
        this.idRoom = idRoom;
    }



//Hotel class

import java.util.ArrayList;
import java.util.Random;


public class Hotel {
    private int nrOfRooms;
    private  ArrayList<Room> Rooms;

    public Hotel(int nrOfRooms, ArrayList<Room> rooms) {
        this.nrOfRooms = nrOfRooms;
        Rooms = rooms;
    }

    public int getNrOfRooms() {
        return nrOfRooms;
    }

    public void setNrOfRooms(int nrOfRooms) {
        this.nrOfRooms = nrOfRooms;
    }
    public void createRoom()
    {
        Room room = new Room();
        Rooms.add(room);
    }

//Client class

    public class Client {
    private int idClient;
    private String firstName;
    private  String lastName;


    public Client()
    {
        this.idClient=0;
        this.firstName = "";
        this.lastName = "";

    }
    public Client(int idClient, String nume, String prenume) {
        this.idClient = idClient;
        this.firstName = nume;
        this.lastName = prenume;

    }
    public int getIdClient() {
        return idClient;
    }
    public void setIdClient(int idClient) {
        this.idClient = idClient;
    }
    public String getNume() {
        return firstName;
    }
    public void setNume(String nume) {
        this.firstName = nume;
    }
    public String getPrenume() {
        return lastName;
    }
    public void setPrenume(String prenume) {
        this.lastName = prenume;
    }

Now I want to realize methods for booking rooms and unbooking rooms, I think it's better to put this methods in an interface....i've stoped here. Plese help me to contiunue! Thanks!

Recommended Answers

All 5 Replies

I'll give you some help with the Booking and Unbooking of rooms.
If you think about it logically, a room is inside a Hotel, yes? So let's put the booking methods in the Hotel Class.

public void bookRoom()
{

}

What do you need to know about the room being booked? Maybe a room number?

public void bookRoom(int roomNum)
{

}

Now, we need to use your methods to get and set the occupency state. Let's use your setEmpty(boolean empty) method from your Room class.

public void bookRoom(int roomNum)
{
    if(rooms[roomNum].isEmpty() == false)
    {
        rooms[roomNum].setEmpty(false);
    }
    else
        System.out.println("Room " + roomNum + " is Already Occupied.");
}

Looking a little bit better now. You need to add the information about who is occupying the room inside the Room class too. So, do that and try filling out the info for setting the clients information in there aswell, that goes in bookRoom(){}.
Good luck and if you get stuck, feel free to come back.

Before going into coding, I would want to take you back to building concept first. Think about it as if you are building a hotel and how you would create a simple management process. Each object (i.e. hotel, room, client) would be a class. Each class may have properties/attributes. Those properties/attributes would be represented as variables in your class. Once you get all of those concepts, we can then start to translate them into codes.

When you need to look at the code, you need to be able to explain the purpose of each variable. So look at your Room class. What each variable is for? How about Client class? How about your current Hotel class?

Next is to look at how you implement your constructor -- public ClassName { ... }. You should think as if you are building an object of the class. What should already been known before building and what are needed for assigning at the building time.

Then, you need to look at how you initialise each variable value if each of them makes sense. I can tell you right now that I am seeing that one of the variables in Room class is not correctly initialised. Also, it may look odd for Hotel constructor to have the rooms object passed into. Please think about it.

There are many other things to be done, but I would like you to build up your concept first. Please let us know on your progress.

why would you need an interface?

also:

Hello! I'm new to programming and I'm trying to do a basic hotel application using threads in java.

what has this to do with threads?

well, his teacher no doubt told him to "use threads to make a hotel application" :)

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.