aspose file tools*
The moose likes Beginning Java and the fly likes Problem building ArrayList for Hotel class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem building ArrayList for Hotel class" Watch "Problem building ArrayList for Hotel class" New topic
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: 10535
    
    9

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem building ArrayList for Hotel class