• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Constructor Problem

 
Mervin Chan
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic