Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use Fill IN the OUTLINE BELOW: Program Goal The goal of this program is to make change. Generate a random Price between 0 and 1000.

Use Fill IN the OUTLINE BELOW:

Program Goal

The goal of this program is to make change.

  1. Generate a random "Price" between 0 and 1000.
    1. Print that Price Formatted with 2 Decimal Places and a Dollar Sign.
      1. The number must be greater than 0
      2. The number should not be more than 1000.
  2. Wait for a "Payment"
    1. Accept Console Input of type Double
      1. You can be assured that the autograder will always submit enough payment the first time.
  3. Calculate "Change" based on the Payment and the Price values
    1. Print that Change Value Formatted with 2 Decimal Places and a Dollar Sign.
  4. Calculate the minimum number of dollars, quarters, dimes, nickels, and pennies required to make that Change

Attached is a program template, Main.java. Modify and submit this file to GradeScope. DO NOT CHANGE THE NAME.

If you are using an IDE which requires package headers, remove them before uploading to GradeScope.

No D2L Submission is required! The only thing you will be graded on is your GradeScope Submission!

Example

$15.67
Enter a payment: 25.15
$9.48
9
1
2
0
3

Colour Key:

Program Output Black
User Input Green

AutoGrader Assumptions

General

  1. The Autograder will use the exact change value, mind internal rounding errors of type double in your own program
  2. The Autograder will pay a random amount more than price given

Output Format

General

For parsing purposes the autograder assumes that the only decimal points (periods), dollar signs, and numbers in a line correspond to the value.

For Example, the line "1. Number of $s: 9" will be interpreted as "1.$9", and throw an error.

Please keep this in mind when generating your output.

Consider instead, "Dollars: 9", or "The number of Dollars needed to make the change is: 9" which are both interpreted as "9".

Note: "9.0" does not equal "9"

Line by Line Breakdown

  • Line 1 Contains the Price (Expecting Dollar Sign and Decimal Point with Precision 2)
  • Line 2 Contains a Prompt to Enter a payment amount
  • Line 3 Contains Change (Expecting Dollar Sign and Decimal Point with Precision 2)
  • Line 4 Contains the Number of Dollars (Expecting a Whole Number)
  • Line 5 Contains the Number of Quarters (Expecting a Whole Number)
  • Line 6 Contains the Number of Dimes (Expecting a Whole Number)
  • Line 7 Contains the Number of Nickels (Expecting a Whole Number)
  • Line 8 Contains the Number of Pennies (Expecting a Whole Number)

Input Format

  • The input value with be a properly formatted double.
  • Input will not contain a dollar sign.

Useful Libraries, Methods, and Links

  • Random
  • Scanner
  • DecimalFormat
  • Math.round(double a)
  • %

OUTLINE :

// IMPORT ANY CLASSES YOU NEED HERE

public class Main { public static void main(String[] args) { double price = 0.0; // Place Holder Value /* TODO 1 GENERATE RANDOM PRICE * Condition: The random number must be greater than 0 */ // TODO 2 Print out your random price with a Dollar Sign and Rounded 2 Decimal Places System.out.println(price); // Place Holder Print Statement may need updated to format the number correctly

// TODO 3 Read in Double Value from Keyboard As Payment // Prompt System.out.println("Please enter your payment: "); double payment = 0.0; // Place Holder Value

// TODO 4 Calculate the TOTAL change amount double change = 0.0; // Place Holder Value // TODO 5 Print Out the Change Value formatted with a Dollar Sign and Rounded 2 Decimal Places

System.out.println(change); // Place Holder Print Statement may need updated to format the number correctly

//NOTICE THESE ARE INTs THEY SHOULD CONTAIN WHOLE NUMBERS ONLY int dollars = 0, quarters = 0, dimes = 0, nickels = 0, pennies = 0; // Place Holder Values

// Hint: Consider Multiplying away the Decimal Place in Change to use whole number modulus // Consider Rounding after multiplying to mitigate inaccuracies introduced by the double datatype // TODO 6 Calculate the Number of Dollars Needed to Make the Change // TODO 7 Calculate the Number of Quarters Needed to Make the Change // TODO 8 Calculate the Number of Dimes Needed to Make the Change // TODO 9 Calculate the Number of Nickels Needed to Make the Change // TODO 10 Calculate the Number of Pennies Needed to Make the Change

// Dollars System.out.println(dollars); // Quarters System.out.println(quarters);

//Dimes System.out.println(dimes);

// Nickels System.out.println(nickels);

// Pennies System.out.println(pennies);

}

}

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

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago