Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions

Question

Are requirements stated clearly? Can they be misinterpreted?

Answered: 1 week ago