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: 52% (17 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...
-
Why has the need for additional metrics grown so fast?
-
Describe the distinguishing characteristics of the four approaches currently used to provide automobile liability insurance to drivers who are unacceptable to insurers in the normal course of...
-
The following information comes from the accounting records for Santa Cruz, Inc., for March: Direct material inventory, March 1 . . . . . . . . . . . . . . . . . . . . . . $6,000 Direct material...
-
only 4 Crane Electronics issues a $ 366,500, 5%, 10-year mortgage note on December 31, 2021. The proceeds from the note are to be used in financing a new research laboratory. The terms of the note...
-
Listed below are nine technical accounting terms introduced in this chapter: Each of the following statements may (or may not) describe one of these technical terms. For each statement, indicate the...
-
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...
-
Find the sum of the series. 00 n=0 (1)"" 32n (2n)!
-
1 . Journalize the following transactions: ( a ) Issued 1 , 0 0 0 shares of $ 1 0 par common stock at $ 5 9 for cash. ( b ) Issued 1 , 4 0 0 shares of $ 1 0 par common stock in exchange for equipment...
-
Using alpha .05, determine if moving to a larger enclosure decreased tiger anxiety levels. You should first calculate the difference (After - Before) Tiger Before Anthony 45 45 Banthony 56 After 38...
-
Cyclohexane (C 6 H 12 ) is produced by mixing Benzene and hydrogen. A process including a reactor, separator, and recycle stream is used to produce Cyclohexane. The fresh feed contains 260L/min C 6 H...
-
Suppose the city is undergoing severe ination. Specifically, both goods prices have risen by 10%. What percentage of a raise in the wage rate should Alex request from her boss, for her to maintain...
-
1. An iron cube of mass 0.55 kg is raised to a temperature of 100C by being placed in boiling water for 5 minutes. It is then removed and transferred immediately to an aluminium calorimeter filled...
-
Draw the shear and moment diagrams for the simplysupported beam. 2wo Wo A B L/2- L/2 -L/2-
-
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...
-
Marietta Marine, Inc., has a traditional Section 401(k) plan. The actual deferral percentage (ADP) for all eligible non-highly compensated employees (non-HCEs) is 4%. What is the maximum ADP for the...
-
How long does a seller have to cure after shipping non-conforming goods?
-
Forward exchange contract designated as a fair value hedge of a foreign-currency-denominated accounts payable, strengthening $US On October 20, 2018, our company purchased from a company located in...
Study smarter with the SolutionInn App