I've been struggling with this for almost a week in Java class This is the description of it A soda machine contains Pepsi, Root Beer, Gatorade, and Poland Spring Water. The machine, when it is full contains 25 of each. The cost of Pepsi and Root Beer is $1.50, Gatorade is $2.25 and Poland Spring Water is $1.25. The machine will dispense the drink and keep track of how much money is in the machine when the user inputs the password. Additionally the user should be able to change the password.
This is my server class
This is my cleint
Now this all works fine but trying to do the GUI here is what I have so far
The problem right now is that I'm allowed to buy unlimited drink and the amount of money in the machine always comes out to $0. I think my getMeDrink(int drinktype) method isnt working correctly. Can anyone help me fix it??
having a quick read of your code, I'd be inclined to structure your GUI a bit like this
1) a Drink class, with name and price variables 2) a DrinkPanel class, with Drink and quantity variables, a JButton to display the drink name/price, possibly a JRadioButton for quantity status. in the button's actionListener quantity--; if(quantity == 0) { JRadioButton.setSelected(true) JRadioButton.setText(*Empty*) JButton.setEnabled(false) } the DrinkPanel class would also have a method addQuantity(int n) which will increase the quantity by 'n', and reverse the above actions
now, in your SodaMachine gui, you create a mainpanel (gridLayout) and add new DrinkPanel(new Drink(name,price),quantity) as many times as you have drinks. then you add all your other stuff, maintenance, password, coins etc
You know it is dark times when the trees riot. I think this tiny ad is their leader:
a bit of art, as a gift, the permaculture playing cards