Luron31
07-08-2009, 09:18 PM
Hello everyone,
im doing a project and im really stuck on it...
i dont want answers. i have a very guilty conscience. i just need some hints as to what im doing wrong or what i could do right...
"A VendingMachine object represents a vending machine that sells products like candy or soda. It has a fixed number of slots, each of which can hold one kind of product for sale. For example, a machine might have 10 Snickers bars in slot 0 and 7 cans of Pepsi in slot 1, but it cannot have some Snickers and some Pepsi in the same slot. There is a maximum number of items that can fit into any one slot - for example, if the maximum was 10, no more Snickers could fit into slot 0. The same kind of product can be in more than one slot, however. The machine must keep track of the name, price, and current quantity of each product, as well as the amount of cash in the machine.
Slots of the vending machine are be numbered starting at zero.
Define appropriate fields, and complete the following methods of VendingMachine:
VendingMachine(int numslots, int maxperslot, double cash) (constructor): Takes the number of slots in the vending machine, the maximum number of items that can fit into any one slot, and the amount of cash in the machine initially. This is the constructor method.
void setProduct(int slot, String product, double price): Make the given slot hold items of the specified kind of product, sold for the given price. The initial quantity of the product in this slot should be zero. If the slot already held another kind of product, the old product should be removed from this slot.
void restockProduct(String product, int quantity): Add the given quantity of the specified product to the vending machine. Put as many of the items as possible into the first slot that has been designated to hold that particular kind of product (using setProduct()). If not all of the items will fit into the first slot, put as many of the rest as possible into the second slot that holds that kind of product, etc. For partial credit, your method should at least be able to find the first slot designated for the specified product and put all of the items there.
double getCashOnHand(): Return the amount of cash now in the vending machine (this amount should increase whenever an item is purchased).
int getQuantity(int slot): Return the number of items in the given slot.
int getQuantity(String product): Return the total number of items of the specified kind of product that are in the vending machine. Remember that this product may be in more than one slot. If the product is not in the vending machine at all, simply return zero.
boolean buyItem(int slot): Attempt to buy one item from the given slot. Return true if successful. "
public class VendingMachine
{
//fields?
public int numslots;
public int maxperslot;
public double cash;
double amountcash;
string quantity;
double quant;
//is this supposed to be a different word than below?
public VendingMachine(int numslots, int maxperslot, double cash)
{
//the constructor
//whats supposed to go in front of the equals sign?
int numberOfSlots = numslots;
int maxItemsInSlot = maxperslot;
double totalCashInMachine = cash;
// complete this method
}
public class setProduct(int slot, String product, double price)
{
//this.product= price;
}
//int[] slot = {String product};
//String[] product;
//String[] product = {double price};
}
public class restockProduct(String product, int quantity)
{
if (quantity <= maxperslot)
{System.out.println("This is the " + quantity);}
}
public double getCashOnHand()
{
return amountcash; // replace this line with your code
}
public int getQuantity(int slot)
{
return quant; // replace this line with your code
}
public int getQuantity(String product)
{
return quantity; // replace this line with your code
}
public boolean buyItem(int slot)
{
return false; // replace this line with your code
}
}
im doing a project and im really stuck on it...
i dont want answers. i have a very guilty conscience. i just need some hints as to what im doing wrong or what i could do right...
"A VendingMachine object represents a vending machine that sells products like candy or soda. It has a fixed number of slots, each of which can hold one kind of product for sale. For example, a machine might have 10 Snickers bars in slot 0 and 7 cans of Pepsi in slot 1, but it cannot have some Snickers and some Pepsi in the same slot. There is a maximum number of items that can fit into any one slot - for example, if the maximum was 10, no more Snickers could fit into slot 0. The same kind of product can be in more than one slot, however. The machine must keep track of the name, price, and current quantity of each product, as well as the amount of cash in the machine.
Slots of the vending machine are be numbered starting at zero.
Define appropriate fields, and complete the following methods of VendingMachine:
VendingMachine(int numslots, int maxperslot, double cash) (constructor): Takes the number of slots in the vending machine, the maximum number of items that can fit into any one slot, and the amount of cash in the machine initially. This is the constructor method.
void setProduct(int slot, String product, double price): Make the given slot hold items of the specified kind of product, sold for the given price. The initial quantity of the product in this slot should be zero. If the slot already held another kind of product, the old product should be removed from this slot.
void restockProduct(String product, int quantity): Add the given quantity of the specified product to the vending machine. Put as many of the items as possible into the first slot that has been designated to hold that particular kind of product (using setProduct()). If not all of the items will fit into the first slot, put as many of the rest as possible into the second slot that holds that kind of product, etc. For partial credit, your method should at least be able to find the first slot designated for the specified product and put all of the items there.
double getCashOnHand(): Return the amount of cash now in the vending machine (this amount should increase whenever an item is purchased).
int getQuantity(int slot): Return the number of items in the given slot.
int getQuantity(String product): Return the total number of items of the specified kind of product that are in the vending machine. Remember that this product may be in more than one slot. If the product is not in the vending machine at all, simply return zero.
boolean buyItem(int slot): Attempt to buy one item from the given slot. Return true if successful. "
public class VendingMachine
{
//fields?
public int numslots;
public int maxperslot;
public double cash;
double amountcash;
string quantity;
double quant;
//is this supposed to be a different word than below?
public VendingMachine(int numslots, int maxperslot, double cash)
{
//the constructor
//whats supposed to go in front of the equals sign?
int numberOfSlots = numslots;
int maxItemsInSlot = maxperslot;
double totalCashInMachine = cash;
// complete this method
}
public class setProduct(int slot, String product, double price)
{
//this.product= price;
}
//int[] slot = {String product};
//String[] product;
//String[] product = {double price};
}
public class restockProduct(String product, int quantity)
{
if (quantity <= maxperslot)
{System.out.println("This is the " + quantity);}
}
public double getCashOnHand()
{
return amountcash; // replace this line with your code
}
public int getQuantity(int slot)
{
return quant; // replace this line with your code
}
public int getQuantity(String product)
{
return quantity; // replace this line with your code
}
public boolean buyItem(int slot)
{
return false; // replace this line with your code
}
}