One
1.
public class Vendingmachine {//defines class vendingmachine//attribute (variable) int price=60;//commodity price int balance;//balance int total;//Total amount//action void Showprompt ()//initial Welcome {SYSTEM.OUT.PRINTLN ("Welcome");} void Insertmomey (int amount)//Invest in Money {balance+=amount;} void Showbalance ()//Display total amount invested (System.out.println (balance);} void Getfood () {if (balance >=price)//Total amount is greater than commodity price {SYSTEM.OUT.PRINTLN ("here is");//Get Goods balance=balance-price;// Change Money total=total+price;//Total turnover}}void Saybye () {System.out.println ("Welcome next Visit");} Main function public static void main (string[] args) {//TODO auto-generated method Stubvendingmachine vm1= new Vendingmachine (); VM 1.showPrompt (); Vm1.insertmomey (); vm1.showbalance ();//input of 50vm1.insertmomey (); vm1.showbalance ();// Put 100vm1.getfood ();//Get commodity vm1.showbalance ();//Change Vm1.saybye ();}}
Note The local variables and the member variables in the class.
Java Classes and objects