Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not sure what your program is supposed to do but....</p> <ol> <li><p>You shouldn't be using "static", this is really used for constant variables.</p> <pre><code>public static int dollars; public static int coupons = dollars; public static int bars = dollars; </code></pre></li> <li><p>This constructor has no function in your program</p> <pre><code>public VendingMachine() { this (0); } </code></pre></li> <li><p>"%" is the modulo operator this is used to get the remainder...I don't think thats what your are wanting to do here.</p> <pre><code>newcoupons = (coupons % 6) +(coupons/6); </code></pre></li> <li><p>Here you want to create an instance of "VendingMachine" not the tester class.</p> <pre><code>VendMachineTest totalbars = new VendMachineTest(); </code></pre></li> </ol> <p>Perhaps you were trying to achieve something along the lines of this?</p> <pre><code>public class VendingMachine { public int dollars; public int coupons; public int mybars = 0; public VendingMachine (int d,int c) { dollars = d; coupons = c; } public void buy_One_Bar() { if(coupons &gt;5) //I get a free bar? { mybars++; // mybars = mybars + 1; coupons = coupons - 6; }else{ dollars--; //Decrease amount of dollars by 1 mybars++; //You gain a bar coupons++; //You gain a coupon } } public int getBars() { return mybars; } public int getDollars() { return dollars; } public int getCoupons() { return coupons; } } </code></pre> <hr> <pre><code>import java.util.Scanner; public class VendMachineTest{ public static void main(String[]args) { Scanner user_input = new Scanner(System.in); int starting_dollars; int starting_coupons; System.out.println("Amount of Cash?"); starting_dollars = user_input.nextInt(); System.out.println("How many coupons do you have?"); starting_coupons = user_input.nextInt(); VendingMachine vm = new VendingMachine(starting_dollars, starting_coupons); vm.buy_One_Bar(); //Buy some bars //Print out what you have... System.out.println("Your Dollars :"+ vm.getDollars()); System.out.println("Amount of Coupons:"+ vm.getCoupons()); System.out.println("Amount of Bars you have:"+ vm.getBars()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload