| Author |
Problem building ArrayList for Hotel class
|
ed spithaler
Greenhorn
Joined: Feb 29, 2012
Posts: 9
|
|
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
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8434
|
|
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.
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
|
|
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.
|
 |
Sunil Sunny
Ranch Hand
Joined: Oct 18, 2011
Posts: 41
|
|
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
|
 |
 |
|
|
subject: Problem building ArrayList for Hotel class
|
|
|