• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling a class that calls another file reading class  RSS feed

 
Yves Talbot
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody.

Here is my current conundrum.
I used a piece of code from the Book: Beginning Programming with Java for Dummies 3rd Edition(Barry Burd, PhD.).

I modified the code to add some functionality so I could stretch my "code".
Here is the class DisplayHotelData.



The file hotelData contains numbers that represent how many people are in each rooms, in this example there are 9 floors and 20 rooms per floors.
These two files are working flawlessly.

Now I am trying to create a new class that would call this existing class (DisplayHotelData).

Current code:



When I execute the class EmptySingleRoom all I get is the message "fileAccess.DisplayHotelData@63bed674", I noticed that the hex code after the @ symbol varies from various run of the code.

My question is how can I call the class DisplayHotelData and see the output that that class usually gives.
(Hopefully I am in the right forum to ask this - new to this forum).

Thanks for any pointer / help.
Yves T.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your DisplayHotelData class doesn't have any instance methods or data so there is no point in creating an instance of it as it currently is. You would need to change this class so the contents of the main method are put into instance method(s). The question is though why would a class called EmptySingleRoom be calling a class called DisplayHotelData?

BTW The reason you get the strange output you do is because each DisplayHotelData instance inherits a toString() method from the Object class which prints the class name followed by '@' then the unsigned hexadecimal representation of the hash code of the object.
 
Yves Talbot
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Tony,

my reasoning was to display the hotel guest list for all room and then asking the attendant which room he or she wanted to update to a vacant (0 occupant) value.
I figured that I could learn how to call one class from within another class.

If I understand the answer the "static" in the class DisplayHotelData would be part of my problem.
Thanks for your help.

 
Yves Talbot
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Tony,

I figure I should give you the whole idea. from start to problem.
So First I created the file "hotelData" by using the class below:



this code creates the data file that tracks which room has how many people in.

Then if I run "DisplayHotelData" so that the clerk would see the current room usage.

In the last class I figured I could display the data from "DisplayHotelData" and then ask the clerk which room needs to be updated. Since I wanted to first do the display and then after this works then I could add the next part which would be to ask the question and get the clerk's answer then figure the next part on how to update the data file on the disk and create a second file to track the file changes.

Maybe I am trying to challenge myself too much.

 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I am trying to challenge myself too much.

I don't know your skill level so it's hard to say if this is too much for you at the moment or not but I would say it's good to push yourself, that's how you learn new things.

My advice at this stage is to stop writing code, put away your computer and get out a pencil and paper. Write out the problem in detail (ie how your hotel booking system works) so you have an accurate description of the problem. Now read through your description and identify the classes (normally nouns/noun phrases) and then identify the associations between these classes. Only once you have a coherent model should you start writing code.

Edit: I'm going to move this thread to the beginners forum as you will get better help there.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yves Talbot wrote:I figure I should give you the whole idea. from start to problem.
So First I created the file "hotelData" by using the class below:

Hi Yves,

That's quite a mouthful. Could you not make it a bit easier to read with some formatting?
Maybe something like:
Room 1: occupants=2
Room 2: occupants=0
Room 3: occupants=4

etc.

I think you might then find it easier to "read" your data; and a program can easily strip out the stuff that it doesn't need when it's reading it.

It's not absolutely necessary, but I think it might help you - especially if you run into problems and need to check things.

Winston
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!