Java: An Introduction to Problem Solving and Programming (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 6.3, Problem 28STQ

Consider the variable allCents in the method writePositive in Listing 6.14. It holds an amount of money as if it were all cents. So for the amount $12.95, the int variable allCents would be set to 1295. Using an int variable is somewhat limiting. The largest value of type int is 2147483647, meaning that the largest amount the method can handle a $21,474,836.47. That is more than $21 million, a nice large sum, but we often need to consider larger amounts, such as the national budget or even the salary for the CEO of a large company. How can you easily change the definitions of the methods in the class DollarFormat so that they handle larger amounts of money?

Blurred answer
Students have asked these similar questions
Write a Java program that implements static method roundSum() so that given 3 ints: a, b, and c; return the sum of their rounded values. We'll round an int value up to the next multiple of 10 if its rightmost digit is 5 or more, so 15 rounds up to 20. Alternately, round down to the previous multiple of 10 if its rightmost digit is less than 5, so 12 rounds down to 10. roundSum(16, 17, 18) → 50roundSum(12, 13, 14) → 40roundSum(6, 4, 4) → 10   The examples of input and output you can see in the picture. (the code structure should be as in the second picture)
Define a method findEmployeeTax() that takes two integer parameters as a person's salary and the number of dependents, and returns the person's tax percent as a double. The tax percent is returned as follows: Salary ≤ 1 dependent 2 - 5 dependents ≥ 6 dependents < 450000 0.15 0.05 0 450000 - 824999 0.25 0.15 0.15 ≥ 825000 0.4 0.25 0.25 Ex: If the input is 425000 0, then the output is: 0.15 import java.util.Scanner; public class TaxFinder { public static double findEmployeeTax(int salary, int numDepen) {   double i;   if (salary < 450000) {      if(numDepen <= 1)         i = 0.15;      else if (numDepen >= 2 && numDepen <= 5)         i = 0.05;      else if (numDepen >= 6)          i = 0;   }       else if (salary >= 450000 && salary <= 824999) {      if(numDepen <= 1)         i = 0.25;      else if (numDepen >= 2 && numDepen <= 5)         i = 0.15;      else if (numDepen >= 6)          i = 0.15;   }    else if…
Write in Java: Given main(), complete the Car class (in file Car.java) with methods to set and get the purchase price of a car (setPurchasePrice(), getPurchasePrice()), and to output the car's information (printInfo()). Ex: If the input is: 2011 18000 2018   where 2011 is the car's model year, 18000 is the purchase price, and 2018 is the current year, the output is: Car's information:      Model year: 2011     Purchase price: 18000     Current value: 5770 Car.java: public class Car {private int modelYear; // TODO: Declare purchasePrice field (int) private int currentValue;public void setModelYear(int userYear){modelYear = userYear;}public int getModelYear() {return modelYear;}// TODO: Define setPurchasePrice() method// TODO: Define getPurchasePrice() methodpublic void calcCurrentValue(int currentYear) {double depreciationRate = 0.15;int carAge = currentYear - modelYear;// Car depreciation formulacurrentValue = (int) Math.round(purchasePrice * Math.pow((1 - depreciationRate),…

Chapter 6 Solutions

Java: An Introduction to Problem Solving and Programming (8th Edition)

Ch. 6.2 - Can you reference an instance variable by name...Ch. 6.2 - Is the following valid, given the class...Ch. 6.2 - Prob. 13STQCh. 6.2 - Prob. 14STQCh. 6.2 - Prob. 15STQCh. 6.2 - Is the following valid, given the class...Ch. 6.2 - What values are returned by each of the following?...Ch. 6.2 - Suppose that speed is a variable of type double...Ch. 6.2 - Repeat the previous question, but instead assign...Ch. 6.2 - Suppose that nl is of type int and n2 is of type...Ch. 6.2 - Define a class CircleCalculator that hat only two...Ch. 6.2 - Which of the following statements are legal?...Ch. 6.2 - Write a Java expression to convert the number in...Ch. 6.2 - Consider the variable 5 of type String that...Ch. 6.2 - Repeat the previous question, but accommodate a...Ch. 6.2 - Write Java code to display the largest and...Ch. 6.3 - Prob. 27STQCh. 6.3 - Consider the variable allCents in the method...Ch. 6.3 - What is wrong with a program that starts as...Ch. 6.3 - Prob. 30STQCh. 6.3 - In your definition of the class OutputFormat. In...Ch. 6.4 - Prob. 32STQCh. 6.4 - Prob. 33STQCh. 6.4 - Prob. 34STQCh. 6.4 - Consider the class Species in Listing 5.19 of...Ch. 6.4 - Repeat the previous question for a method...Ch. 6.4 - Still considering the class Species in Listing...Ch. 6.4 - Rewrite the method add in Listing 6.16 so that it...Ch. 6.4 - In Listing 6.16, the set method that has a String...Ch. 6.5 - Give the definitions of three accessor methods...Ch. 6.6 - If cardSuit is an instance of Suit and is assigned...Ch. 6.7 - Suppose you want to use classes in the package...Ch. 6.7 - Prob. 43STQCh. 6.7 - Can a package have any name you might want, or are...Ch. 6.7 - On your system, place the class Pet (Listing 6.1)...Ch. 6.8 - The previous section showed you how to change the...Ch. 6 - Prob. 1ECh. 6 - Prob. 2ECh. 6 - Write a default constructor and a second...Ch. 6 - Write a constructor for the class...Ch. 6 - Consider a class characteristic that will be used...Ch. 6 - Create a class RoomOccupancy that can be used to...Ch. 6 - Write a program that tests the class RoomOccupancy...Ch. 6 - Sometimes we would like a class that has just a...Ch. 6 - Create a program that tests the class Merlin...Ch. 6 - In the previous chapter, Self-Test Question 16...Ch. 6 - Create a class Android whose objects have unique...Ch. 6 - Prob. 12ECh. 6 - Modify the definition of the class Species in...Ch. 6 - Prob. 2PCh. 6 - Using the class Pet from Listing 6.1, write a...Ch. 6 - Do Practice Program 4 from Chapter 5 except define...Ch. 6 - The following class displays a disclaimer every...Ch. 6 - Do Practice Program 5 from Chapter 5 but add a...Ch. 6 - We can improve the Beer class from the previous...Ch. 6 - Define a utility class for displaying values of...Ch. 6 - Write a new class TruncatedDollarFormat that is...Ch. 6 - Complete and fully test the class Time that...Ch. 6 - Complete and fully test the class Characteristic...Ch. 6 - Write a Java enumeration LetterGrade that...Ch. 6 - Complete and fully test the class Per n that...Ch. 6 - Write a Temperature class that represents...Ch. 6 - Repeat Programming Project 8 of the previous...Ch. 6 - Write and fully test a class that represents...Ch. 6 - Write a program that will record the votes for one...Ch. 6 - Repeat Programming Project 10 from Chapter 5, but...Ch. 6 - Create a JavaFX application that displays a button...

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Java Math Library; Author: Alex Lee;https://www.youtube.com/watch?v=ufegX5o8uc4;License: Standard YouTube License, CC-BY