Java ONLY please I am a new programmer and have question abo

Java ONLY please. I am a new programmer and have question about this program. Please help me and make sure it can compile and run

Implement a vending machine that holds cans of soda. To buy a can of soda, the customer needs toinsert a token into the machine. When the token is inserted, a can drops from the can reservoir intothe product delivery slot. The vending machine can be filled with more cans. The goal is to determinehow many cans and tokens are in the machine at any given time. What methods would you supplyfor a VendingMachine class? Give the names, parameter variables, and return types of the methods.For example I can think of insertToken, fillUp, getCanCount and getTokenCount methods.What instance variables do the methods need to do their work? Hint: You need to track the numberof cans and tokens. Declare them with their type and access modifier.Consider what happens when a user inserts a token into the vending machine. The number of tokensis increased, and the number of cans is decreased. Implement a method:

public void insertToken(){   

// Instructions for updating the token and can counts

}

Now implement a method fillUp(int cans) to add more cans to the machine. Simply add thenumber of new cans to the can count.

Answer:

public void fillUp(int cans){   

numCans = numCans + cans;

}

Next, implement two methods, getCanCount and getTokenCount, that return the current values ofthe can and token counts.After You have implemented all methods of the VendingMachine class. Use exception handlingwherever applicablePut them together into a class, like this and submit on Canvas:

public class VendingMachine{

private your first instance variable

private your second instance variable

public your first method

public your second method   . . .}

Solution

public class VendingMachine
{
private int numCans=0; //Initialization
private int numTokens=0; //Initialization
public int getCanCount()
{
   return numCans;
}
public int getTokenCount()
{
   return numTokens;
}
public void fillUp(int cans)
{   
numCans = numCans + cans;
}
public void insertToken()
{   
numCans = numCans - 1;
numTokens = numTokens + 1;
}
public static void main(String args[])
{
VendingMachine vm = new VendingMachine();
System.out.println(\"Vending Machine\");
System.out.println(\"Current can count \");
System.out.println(vm.getCanCount());

//Similarly call other functions

}
}

Java ONLY please. I am a new programmer and have question about this program. Please help me and make sure it can compile and run Implement a vending machine th
Java ONLY please. I am a new programmer and have question about this program. Please help me and make sure it can compile and run Implement a vending machine th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site