Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am running this code and everything is working but I keep getting the below error. Please help? import java.util.Scanner; public class Transaction { public
I am running this code and everything is working but I keep getting the below error. Please help?
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();
int totalCost = 0; if (numCookies >= 4) { totalCost = numCookies * 3; }
if (totalCost
if (numCookies > 22) { System.out.println("Restocking soon."); } else { System.out.println("Item still in stock."); }
} }
First, the first if statement checks the number of cookies purchased. If at least 4 cookies are purchased, then a nested if-else statement compares the cost of the cookies to the amount of read from input. Lastly, an if-else statement outputs "Restocking soon." if more than 22 cookies are purchased, and otherwise outputs "I stock." Not all tests passed. 1: Compare output Input Your output 2: Compare output A Output differs. See highlights below. Input Your output Expected output 3: Compare output Input
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