| Author |
Constructor Problem
|
Mervin Chan
Greenhorn
Joined: Dec 03, 2004
Posts: 24
|
|
I have a problem. I am modelling a factory environment. I have 3 classes, Machine and Store and Product. In my program, a "Machine" Object is supposed to pass an "Product" object to a "Buffer" Object. In my Machine constructor, i have indicated which Buffer to pass the Product to. ie Store A = new Store(); then, Machine aMachine= new Machine(A); //Send output of Machine to Store A Constructor for Machine : Machine (Store aStoreName) { ..... } the problem is this, I intend to read a string from a textfile indicating the Buffer that Machine is targeting. ie String aStoreName. How to i convert String aStoreName, so that i can be used in the Machine Constructor? I tried casting, did not work! I hope I've described my problem well... thanks for the help!
|
 |
Joel McNary
Bartender
Joined: Aug 20, 2001
Posts: 1815
|
|
Did you post this before and then delete the topic? I seem to remember answering this not 5 minutes ago...but I can't find the other topic Anyway, this sounds like a job for a java.util.Map. Simply store the String bufferName as the key and then the Buffer object as the value. Whenever you get a string, just look up that string in the Map and get the correct Buffer object.
|
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
|
 |
 |
|
|
subject: Constructor Problem
|
|
|