PDA

View Full Version : Need help due tomorrow afternoon! Lost


Somecuban
03-16-2010, 02:17 AM
Write a program that simulates a vending machine. Products can be purchased by inserting coins with a value at least equal to the cost of the product. A user selects a product from a list of available products, adds coins, and either gets the product or gets the coins returned if insufficient money was supplied or if the product is sold out. The machine does not give change if too much money was added. Products can be restocked and money removed by an operator. Follow the design process that was described in this chapter. Your solution should include a class VendingMachine that is not coupled with the Scanner or PrintStream classes.


Here is a sample program run:

S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
A
Description:
Candy bar
Price:
0.55
Quantity:
10
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
A
Description:
Fruit drink
Price:
0.65
Quantity:
10
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
S
Candy bar @ $0.55
Fruit drink @ $0.65
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
I
A) nickel @ 0.05
B) dime @ 0.1
C) quarter @ 0.25
D) dollar @ 1.0
C
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
I
A) nickel @ 0.05
B) dime @ 0.1
C) quarter @ 0.25
D) dollar @ 1.0
C
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
I
A) nickel @ 0.05
B) dime @ 0.1
C) quarter @ 0.25
D) dollar @ 1.0
A
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
B
A) Candy bar @ $0.55
B) Fruit drink @ $0.65
A
Purchased: Candy bar @ $0.55
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
I
A) nickel @ 0.05
B) dime @ 0.1
C) quarter @ 0.25
D) dollar @ 1.0
D
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
B
A) Candy bar @ $0.55
B) Fruit drink @ $0.65
B
Purchased: Fruit drink @ $0.65
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
R
Removed: $1.55
S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit
Q
Your main class should be called VendingMachineSimulation.


This is what i have so far


public class VendingMachineSimulation {

public static void main(String[] args) {
Scanner a = new Scanner(System.in);
product p = new product("name",10.0,10);
vendingMachine v = new vendingMachine();

System.out.println("S)how products I)nsert coin B)uy A)dd product R)emove coins Q)uit");
String b = a.next();
char choice = b.charAt(0);




do{


switch(choice){
case 'S':
System.out.println(v);

break;
case 'I':
break;
case 'B':
break;
case 'A':
System.out.println("Description:");
String desc = a.next();
System.out.println("Price:");
double pri = a.nextDouble();
System.out.println("Quantity:");
int qty = a.nextInt();
product userMadeProduct = new product(desc, pri, qty);
v.newproduct(userMadeProduct);
break;
case 'R':
break;
}

}while(choice != ('Q')||choice != ('q'));

}








}



Separate Class


public class vendingMachine {
ArrayList<product> p = new ArrayList<product>();

public void newproduct(product p1){
p.add(p1);
}



//add new product to vending machine
//display information of a product


}
class product{

public product(String productname, double productprice, int productqty) {
this.productname = productname;
this.productprice = productprice;
this.productqty = productqty;
}
String productname;

public String getProductname() {
return productname;
}

public void setProductname(String productname) {
this.productname = productname;
}

public double getProductprice() {
return productprice;
}

public void setProductprice(double productprice) {
this.productprice = productprice;
}

public int getProductqty() {
return productqty;
}

public void setProductqty(int productqty) {
this.productqty = productqty;
}
double productprice;
int productqty;

}


YOU CAN CHANGE MY CODE OR JUST DO YOUR OWN BUT I NEED HELP PLXX

tomws
03-16-2010, 02:55 AM
YOU CAN CHANGE MY CODE OR JUST DO YOUR OWN BUT I NEED HELP PLXX

You're not asking for help. You're asking for someone to do your work for you. From the forum rules (http://www.codingforums.com/rules.htm):
1.5) No homework assignments - Do not post your entire homework assignment and request that other members do it for you. This is considered cheating, and your thread may even be used by your school to prove your guilt. Now, you may ask for advice or help on a specific aspect of your assignment that you're having trouble with. Use common sense as far as what's acceptable in terms of soliciting help with homework assignments.