Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What to do This lab has two parts. In Part 1 you will write a program that make change. IN Part 2 you will write

image text in transcribedimage text in transcribedimage text in transcribed

What to do This lab has two parts. In Part 1 you will write a program that make change. IN Part 2 you will write an program that determines the range of numbers entered by the user. Part 1 Change Maker Your task is to write a Java program to assist those with limited change-making skills. Your program should accept one double-precision floating-point number from the user. This number represents an amount of money to be returned to the customer in change. The input value is limited to non-negative numbers less than $20.00. After receiving the input, the program should print the number of bills and coins needed to make up that much money. Some important points: - Your program should use the following units of currency: ten-dollar bills, five-dollar bills, one-dollar bills, quarters, dimes, nickels, and pennies. - Use caution when dealing with floating-point to integer conversions. The printed result should be correct down to the last cent. A good approach converts the user's input value to integer cents and then computes the various denominations; for example, the input 3.41 is 341 cents. If d is a double and i is an int, the statement i=d;//Illegal,thisnarrows is illegal since it requires a narrowing conversion. We can force the conversion with a type cast. The following code i=(int)d;//Legal converts d's value to an integer to assign to i. Note that this a potentially dangerous operation because d's value may be outside the range of integers. - When reporting the result, your program should use the smallest number of currency units; for example, if the user enters 1.21, the program should report and 12.07 should produce 1 ten 2 ones 1 nickel 2 pennies - Do not display display a monetary unit if it is zero; for example, the input 11.07 should not print The program should continue to accept input from the user and display the change until the user enters the value 0.00 (or just 0 ). A common question is "Why am I sometimes off by 1 ?" Remember that many floating-point numbers do not have exact decimal representations. If a user enters the value 1.20, it actually may be represented internally as 1.20000001 or 1.19999999. In the first case, if you multiply the value by 100 and assign it to an integer (via a cast), the integer value will be 120 , which is what we want. In the second case, the same process produces 119 , which is off by one. You will need to devise a way via arithmetic that is capable of converting both 1.19999999 and 1.20000001 to 120 . It should work correctly for all such imprecision cases that can arise in this application. Part 2 Maximum Number Write a program that accepts an arbitrary number of non-negative integer values from the user. When the user enters an integer less than zero, the program then prints the largest non-negative number the user entered. The program should print only the answer; it should not print a prompt for the user. The following shows a sample run of the program: 101752178561 In this example, the user entered the numbers on the first line, and the program printed 17, the largest non-negative integer entered. If the user enters a negative number first, the program should print nothing; for example: 1 Here the user entered 1, and the program terminated without printing anything. Be sure your program handles ties properly

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 And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions

Question

Discuss consumer-driven health plans.

Answered: 1 week ago