I need help understanding how i can link variables from a class to my main class, it seems to work during certain instances of code I've used before but I'm not clear on how it works. in this case, the Dollar variable needs to pull in an integer from my main method in the tester class that comes from a scanner input. Also how do I implement my while loop and have it call other methods so that it prints the desired variable. the point of this program is too find out the max bars you can get with a fixed amount of money, assuming each is 1 dollar, each bar has one coupon, and 6 coupons get you a free bar(with the 1 coupon inside). Im a beginner and I cant figure out where to go next.
public class VendingMachine
{
public static int dollars;
public static int coupons = dollars;
public static int bars = dollars;
public VendingMachine (int x)
{
dollars = x;
}
public VendingMachine()
{
this (0);
}
public static void Bars()
{
int newbars;
newbars = coupons/6;
bars = bars + newbars;
}
public static void Coupons()
{
int newcoupons;
newcoupons = (coupons % 6) +(coupons/6);
coupons = newcoupons + coupons;
}
}
import java.util.*;
public class VendMachineTest{
public static void main(String[]args, int coupons)
{
Scanner user_input = new Scanner(System.in);
int dollars;
System.out.println("Amount of Cash?");
dollars = user_input.nextInt();
VendMachineTest totalbars = new VendMachineTest();
while ( coupons >= 6)
{
VendMachineTest.Bars();
VendMachineTest.Coupons();
}
}
System.out.println( dollars +""+coupons+""+bars+"");
}