Question
Totally lost on how to start this code. Integers numCookies and numDollars are read from input. A cookie costs 3 dollars. If numCookies is greater
Totally lost on how to start this code.
Integers numCookies and numDollars are read from input. A cookie costs 3 dollars.
If numCookies is greater than or equal to 4, then declare and initialize int variable totalCost with the product of numCookies and 3.
If totalCost is less than or equal to numDollars, output "Successful purchase!"
Otherwise, output "Need more money to purchase all."
If numCookies is greater than 22, output "Restocking soon." Otherwise, output "Item still in stock."
End with a newline.
Ex: If the input is 11 54, then the output is:
Successful purchase! Item still in stock.
import java.util.Scanner;
public class Transaction { public static void main (String[] args) { Scanner scnr = new Scanner(System.in); int numCookies; int numDollars; numCookies = scnr.nextInt(); numDollars = scnr.nextInt();
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started