|
Ok well I just started learning java using the blue j enviroment not sure you heard of this or used it. I have got assignment to build a vending machine. What is only gonna be used in blue j, so it dont have visual appearence.
and so far I have created the three classes it will use.
Vending machine
Dispenser
Coinbox
in the vending machine i have been told to use a javamap is it? so far I have got this
public void createDispenser(String sProductName, float fPrice, int iInitialStock)
{
Dispenser objX;
objX = new Dispenser();
// Initialise the dispensers
createDispenser("Coke", 90, 5);
createDispenser("Dr_Pepper", 65, 5);
createDispenser("Pepsi", 75, 5);
createDispenser("Sprite", 80, 5);
createDispenser("Water", 70, 5);
createDispenser("Fanta", 85, 5);
createDispenser("Lilt", 65, 5);
createDispenser("7up", 70, 5);
createDispenser("Oasis", 90, 5);
createDispenser("Ice Tea", 95, 5);
createDispenser("apple Juice", 90, 5);
Then what I need to do in the dispenser class. I need to tell the dispenser class, what item to dispense so I have this so far.
public class Dispenser
{
// instance variables also know as fields
// Constructor for objects of class Dispenser
public Dispenser()
{
// initialise instance variables
}
//returns the item name
public String getName()
{
return sProductName;
}
What I want know is how can I call sProductName from the vending class to display in the getName method ?
so when it returns sProductName it say coke so on......
Hope that clean any problem let me know thanks again
|