Rewrite Listing 2.10, ComputeChange .java, to fix the possible loss of accuracy when converting a double value
Question:
Rewrite Listing 2.10, ComputeChange .java, to fix the possible loss of accuracy when converting a double value to an int value. Enter the input as an integer whose last two digits represent the cents. For example, the input 1156 represents 11 dollars and 56 cents.
Listing 2.10
Transcribed Image Text:
1 import java.util.Scanner; 2 import class 3 public class ComputeChange { 4. public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner (System.in); // Receive the amount System.out.print( "Enter an amount in double, for example 11.56: "); double amount = input.nextDouble(); 10 11 12 13 14 enter input int remainingAmount = (int) (amount * 100); // Find the number of one dollars int number0fOneDo1lars = remainingAmount / 100; remainingAmount = remainingAmount % 100; 15 16 dollars 17 18 // Find the number of quarters in the remaining amount int numberOfQuarters = remainingAmount / 25; 19 20 quarters 21 remainingAmount = remainingAmount % 25; 22 // Find the number of dimes in the remaining amount int numberofDimes = remainingAmount / 10; remainingAmount = remainingAmount % 10; 23 24 25 26 // Find the number of nickels in the remaining amount int number0fNickels = remainingAmount / 5; remainingAmount = remainingAmount % 5; 27 28 29 30 // Find the number of pennies in the remaining amount int number0fPennies = remainingAmount; 31 32 33 // Display results System.out.printın("Your amount " + amount + System.out.println(" System.out.println(" System.out.println(" System.out.println(" System.out.println(" 34 consists of"); 35 36 + numberofOneDollars + " dollars"); + number0fQuarters + " quarters "); + numberofDimes + + numberofNickels + 37 dimes"); nickels"); pennies"); 38 39 40 + numberofPennies + 41 { 42
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 46% (15 reviews)
Output Enter an amount as integer for example 1156 3456 Your amount 1156 consists of 34 do...View the full answer
Answered By
Ali Khawaja
my expertise are as follows: financial accounting : - journal entries - financial statements including balance sheet, profit & loss account, cash flow statement & statement of changes in equity -consolidated statement of financial position. -ratio analysis -depreciation methods -accounting concepts -understanding and application of all international financial reporting standards (ifrs) -international accounting standards (ias) -etc business analysis : -business strategy -strategic choices -business processes -e-business -e-marketing -project management -finance -hrm financial management : -project appraisal -capital budgeting -net present value (npv) -internal rate of return (irr) -net present value(npv) -payback period -strategic position -strategic choices -information technology -project management -finance -human resource management auditing: -internal audit -external audit -substantive procedures -analytic procedures -designing and assessment of internal controls -developing the flow charts & data flow diagrams -audit reports -engagement letter -materiality economics: -micro -macro -game theory -econometric -mathematical application in economics -empirical macroeconomics -international trade -international political economy -monetary theory and policy -public economics ,business law, and all regarding commerce
4.00+
1+ Reviews
10+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Rewrite Listing 2.10, ComputeChange. java, to fix the possible loss of accuracy when converting a float value to an int value. Read the input as a string such as "11.56". Your program should extract...
-
A hospital administrator worries about the possible loss of electric power as a result of a power blackout. The hospital, of course, has a standby generator, but it too is subject to failure, having...
-
When two measurements originate from different sources, converting them to the z scale helps to draw a sensible interpretation of their relative magnitudes. For instance, suppose a student scored 65...
-
2. The beam in the figure is made of material having modulus of elasticity E = 200 GPa . The moment of inertia of segments AB and CD of the beam is I = 6.77 10-6 m, while the moment of inertia of...
-
If an object in linear motion (but with changing velocity) covers s meters in t seconds, then its average velocity is v0 = s / t m/s. Show that it would cover the same distance if it traveled at...
-
Convert metric units 5.62 m to cm
-
The codon change (Gly-12 to Val-12) in human H-ras that converts it to oncogenic H-ras has been associated with many types of cancers. For this reason, researchers would like to develop drugs to...
-
A company manufactures a liquid product called Glitter. The basic ingredients are put into process in Department 1. In Department 2, other materials are added that increase the number of units being...
-
v = [-21 0]T V = [101]T V1 Are the basis vectors v and v orthogonal? (Provide proof of your answer) the current basis vectors are not orthogonal, use projection to find v, the component of v...
-
Consider the following 0x86 program: .data array DWORD 1,2,3,4,5,6,7,8,9 aravSize -(S-array)/4 ; array .code main PROC mov ecx,arraySize-1 mov esi.OFFSET array L1: mov eax. [esi] sda mov bx,2 idiv bx...
-
Write a program that reads in investment amount, annual interest rate, and number of years, and displays the future investment value using the following formula: futureInvestmentValue =...
-
Write a program that prompts the user to enter the distance to drive, the fuel efficiency of the car in miles per gallon, and the price per gallon, and displays the cost of the trip. Here is a sample...
-
Software filters rely heavily on "blacklists" (lists of known "phishing" URLs) to detect fraudulent e-mails. But such filters typically catch only 20 percent of phishing URLs. Jason receives 16...
-
Write out the first few terms of the geometric series, n=0 express the inequality, |r| < 1, in terms of x and find the values of x for which the inequality holds and the series converges. 1 The...
-
Determine the minimum cost for distribution of goods using North-West Corner, Minimum Cell Cost and Vogel Approximation methods, Min Z = 16x11 + 13x12 + 22x13 + 17x14 + 14x21 + 13x22 + 19x23 + 15x24...
-
Evaluate the function f(x) = -2x + 7 at the indicated values. a) Find f(3). b) Find f(-7). a) f(3) = (Simplify your answer.)
-
Peter Parker and Miles Morales are told that there are some additional Alchemax labs in the city a miles away, where 0 < x < 2. Answer the following questions to determine how far Peter and Miles are...
-
Writing a new or an updated version of a previously published On Terms paper. On Terms papers are short communications devoted to a single behavior analytic term. A formal description of these kinds...
-
The income statement and account balances for Charron Inc. are presented in E17-4. Instructions Prepare the operating section of a cash flow statement using the direct method. CHARRON INC Comparative...
-
Outline a general process applicable to most control situations. Using this, explain how you would develop a system to control home delivery staff at a local pizza shop.
-
Rewrite Programming Exercise 14.10 so the cylinders width and height are automatically resized when the window is resized. Data from Programming Exercise 14.10 Write a program that draws a cylinder,...
-
Write a program that enables the user to drag the vertices of a triangle and displays the angles dynamically as the triangle shape changes, as shown in Figure 15.32a. The formula to compute angles is...
-
Write a program that displays a circle of radius 10 pixels filled with a random color at a random location on a pane, as shown in Figure 15.31b. When you click the circle, it disappears and a new...
-
Do you think agencies have been given too many powers, for example, the FCC? Should there be more judicial review of these entities? https://youtu.be/ow5hZmU7Yfw (Business law course)
-
can you write summary of chapter 4 - the emergence of modern price theory book- the history of economic ideas by BRANDON DUPONT write summary in about 600-1200 words
-
What insights can be gained from comparative genomics studies across species, shedding light on evolutionary relationships, genome evolution, and the functional significance of conserved sequences?
Study smarter with the SolutionInn App