Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem building ArrayList for Hotel class

 
ed spithaler
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Posts: 48404
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic