Respuesta :
Answer:
import java.util.Scanner;
class Main {
public static void main (String args[])
{
Scanner input = new Scanner(System.in);
VendingMachine machine = new VendingMachine(20);
System.out.print("Enter nr to purchase: ");
int nrPurchased = input.nextInt();
System.out.print("Enter nr to re-stock: ");
int nrRestock = input.nextInt();
machine.Transaction(nrPurchased, nrRestock);
input.close();
}
}
class VendingMachine {
private int inventory;
public VendingMachine(int initialInventory) {
inventory = initialInventory;
}
public void Transaction(int nrToBuy, int nrToRestock) {
inventory += nrToRestock - nrToBuy;
System.out.printf("Inventory: %d bottles.\n", inventory);
}
}
The program is an illustration of a sequential program, and it does not require loops, iterations and branches.
The program in java, where comments are used to explain each line is as follows:
import java.util.Scanner;
class Main {
public static void main (String args[]){
//This creates a scanner object
Scanner input = new Scanner(System.in);
//This gets input for the number of purchases
int Purchased = input.nextInt();
//This gets input for the number of restocks
int Restock = input.nextInt();
//This calculates and prints the inventory
System.out.print("Inventory: "+(20 - Purchased + Restock)+" bottles");
}
}
At the end of the program, the net inventory is printed.
Read more about similar programs at:
https://brainly.com/question/22851981