Forums Register Login

Problem building ArrayList for Hotel class

+Pie Number of slices to send: Send
I am building a hotel program with 2 classes. I am using an arraylist to store the room info, but when I print the room list I get strange characters that look like hex.
Any help would be appreciated.

This is the output:

Number of Rooms :
Number of Occupied Rooms :
Room Details are :
Room Number :
Smoking room :
Bed Type :
Rate :
Room@56f9659d
Room@f7e5307
Room@2e7cf883
Room@e9f784d
Room@7930ebb

It should look like this:

Hotel Name : Beach Marriot
Number of Rooms : 5
Number of Occupied Rooms : 1

Room Details are:

Room Number: 101
Occupant name: Not Occupied
Smoking room: s
Bed Type: queen
Rate: 100.0

+Pie Number of slices to send: Send
 

ed spithaler wrote:I am using an arraylist to store the room info, but when I print the room list I get strange characters that look like hex.


Nothing strange about it. Check out the source code for Object#toString()

To get your desired output, you need to
1) Provide appropriate getter methods in your Room class. eg.getRoomNum, isSmoking* etc
2) When you are iterating over theRooms, call these methods and print the values

*I notice you have defined smoking as a char. If it is going to indicate yes/no, then it would be a better idea to define it as a boolean like you have done for occupied

PS. You can also override the toString() in your Room class to return the appropriate text you want.
+Pie Number of slices to send: Send
What’s smoking? They don’t allow it in this country any more. Not in a hotel at least.
When you said to look up toString, I presume you meant this, which explains the problem quite nicely.
+Pie Number of slices to send: Send
look at the line 47 theRooms.add(newRoom);

Here you are storing objects in your array List . and when you are retreiving you are getting objects So what you have stored you are getting
The only cure for that is hours of television radiation. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4548 times.
Similar Threads
Adding JLabels to a vector
Stupid question naming for hotel room data.
Object trouble.
Database file reader
How to define the three fields?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:06:26.