Big Java Late Objects
2nd Edition
ISBN: 9781119330455
Author: Horstmann
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 2, Problem 13RE
Consider the following code segment.
double purchase = 19.93;
double payment = 20.00;
double change = payment - purchase;
System.out.println(change);
The code segment prints the change as 0.07000000000000028. Explain why. Give a recommendation to improve the code so that users will not be confused.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Compare userNumber with compareNumber and display 'Numbers are not equal' if the numbers are different. Then, display 'Variables are not identical' if the variables are not identical (not strictly equal).
let compareNumber = 3; // Code will be tested with: 3, 8, 42let userNumber = '3'; // Code will be tested with: '3', 8, 'Hi'
Please leave the fixed code and comments, thank you!
1.
The following code should print out a random number between 1 and 10, why will it not function correctly?
from random import randintprint (randint(10, 1))
2.
Why does the following code not return the expected value?
def calcDiscountPrice(price, percentage):
discount = price * percentage
discountPrice = price - discount
return discount
3.
Why does the following code not return the expected value?
def main():value = int(input("Enter number:"))tenPercent(value)print ("Ten percent is ", result)def tenPercent(num):return num * .1main()
Program Specifications Write a FancyCar class to support basic operations such as drive, add gas, honk horn and start engine.
fancy_car.py is provided with function stubs. Follow each step to gradually complete all instance methods.
Note: This program is designed for incremental development. Complete each step and submit for grading before starting the next step. Only
a portion of tests pass after each step but confirm progress. The main program includes basic calls to the instance methods. Add
statements in the main program as instance methods are completed to support development mode testing.
**Step 0: Complete the constructor to initialize the model and miles per gallon (MPG) with the values of the parameters. Initialize the
odometer to five miles and the tank to be full of gas. By default, the model is initialized to "Old Clunker", and MPG is initialized to 24.0. Note
the provided constant variable indicates the gas tank capacity of 14.0 gallons.
Step 1 Complete the instance…
Chapter 2 Solutions
Big Java Late Objects
Ch. 2.1 - Declare a variable suitable for holding the number...Ch. 2.1 - What is wrong with the following variable...Ch. 2.1 - Declare and initialize two variables, unitPrice...Ch. 2.1 - Prob. 4SCCh. 2.1 - Some drinks are sold in four-packs instead of...Ch. 2.1 - Prob. 6SCCh. 2.1 - Prob. 7SCCh. 2.1 - Prob. 8SCCh. 2.1 - How would you explain assignment using the parking...Ch. 2.2 - A bank account earns interest once per year. In...
Ch. 2.2 - In Java, how do you compute the side length of a...Ch. 2.2 - The volume of a sphere is given by V=43r3 If the...Ch. 2.2 - Prob. 13SCCh. 2.2 - Prob. 14SCCh. 2.3 - Write statements to prompt for and read the users...Ch. 2.3 - What is wrong with the following statement...Ch. 2.3 - Prob. 17SCCh. 2.3 - What is problematic about the following statement...Ch. 2.3 - What is the output of the following statement...Ch. 2.3 - Using the printf method, print the values of the...Ch. 2.4 - Prob. 21SCCh. 2.4 - Suppose the architect specifies a pattern with...Ch. 2.4 - A robot needs to tile a floor with alternating...Ch. 2.4 - For a particular car, repair and maintenance costs...Ch. 2.4 - The shape of a bottle is approximated by two...Ch. 2.5 - What is the length of the string "Java Program"?Ch. 2.5 - Consider this string variable. String str = "Java...Ch. 2.5 - Use string concatenation to turn the string...Ch. 2.5 - Prob. 29SCCh. 2.5 - Prob. 30SCCh. 2 - Write declarations for storing the following...Ch. 2 - What is the value of mystery after this sequence...Ch. 2 - What is wrong with the following sequence of...Ch. 2 - Write the following mathematical expressions in...Ch. 2 - Write the following Java expressions in...Ch. 2 - What are the values of the following expressions?...Ch. 2 - What are the values of the following expressions,...Ch. 2 - What are the values of the following expressions?...Ch. 2 - Assuming that a and b are variables of type int,...Ch. 2 - Suppose direction is an integer angle between 0...Ch. 2 - Find at least five compile-time errors in the...Ch. 2 - Find three run-time errors in the following...Ch. 2 - Consider the following code segment. double...Ch. 2 - Explain the differences between 2, 2.0, 2, 2, and...Ch. 2 - Explain what each of the following program...Ch. 2 - Write pseudocode for a program that reads a word...Ch. 2 - Write pseudocode for a program that reads a name...Ch. 2 - Write pseudocode for a program that computes the...Ch. 2 - Modify the pseudocode for the program in How To...Ch. 2 - Prob. 20RECh. 2 - You are cutting off a piece of pie like this,...Ch. 2 - The following pseudocode describes how to obtain...Ch. 2 - Suppose you are given a string str and two...Ch. 2 - Prob. 24RECh. 2 - For each of the following computations in Java,...Ch. 2 - Prob. 26RECh. 2 - This chapter contains a number of recommendations...Ch. 2 - Write a program that displays the dimensions of a...Ch. 2 - Write a program that computes and displays the...Ch. 2 - Write a program that reads a number and displays...Ch. 2 - Write a program that prompts the user for two...Ch. 2 - Enhance the output of Exercise E2.4 so that the...Ch. 2 - Write a program that prompts the user for a...Ch. 2 - Write a program that prompts the user for a radius...Ch. 2 - Write a program that asks the user for the lengths...Ch. 2 - Improve the program discussed in How To 2.1 to...Ch. 2 - Write a program that helps a person decide whether...Ch. 2 - Write a program that asks the user to input The...Ch. 2 - File names and extensions. Write a program that...Ch. 2 - Write a program that reads a number between 1,000...Ch. 2 - Write a program that reads a number between 1,000...Ch. 2 - Printing a grid. Write a program that prints the...Ch. 2 - Write a program that reads in an integer and...Ch. 2 - Write a program that reads two times in military...Ch. 2 - Writing large letters. A large letter H can be...Ch. 2 - Write a program that transforms numbers 1, 2, 3, ,...Ch. 2 - Write a program that prints a Christmas tree:...Ch. 2 - Easter Sunday is the first Sunday after the first...Ch. 2 - In this project, you will perform calculations...Ch. 2 - The following pseudocode describes how a bookstore...Ch. 2 - The following pseudocode describes how to turn a...Ch. 2 - The following pseudocode describes how to extract...Ch. 2 - Giving change. Implement a program that directs a...Ch. 2 - An online bank wants you to create a program that...Ch. 2 - A video club wants to reward its best members with...Ch. 2 - Consider the following circuit. Write a program...Ch. 2 - The dew point temperature Td can be calculated...Ch. 2 - The pipe clip temperature sensors shown here are...Ch. 2 - Prob. 12PPCh. 2 - Consider the following tuning circuit connected to...Ch. 2 - According to the Coulomb force law, the electric...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Write an SQL statement to display the last name, first name, and email of any owners of cats. Use a subquery. T...
Database Concepts (8th Edition)
Write a Python statement that given an existing variable called bodyTemp in degrees Fahrenheit stores the equiv...
Computer Science: An Overview (12th Edition)
Write a program that accepts two integer values typed in by the user. Display the result of dividing the first ...
Programming in C
Assume the following variable definitions: int a = 5, b = 12; double x = 3.4, z = 9.1 ; What are the values of ...
Starting Out with C++ from Control Structures to Objects (9th Edition)
(Enhancing Class Rectangle) Create a more sophisticated Rectangle class than the one you created in Exercise 17...
C How to Program (8th Edition)
Pennies for Pay Write a program that calculates the amount a person would earn over a period of time if his or ...
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Knowledge Booster
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
- Reza Enterprises sells tickets for buses, tours, and other travel services. Because Reza frequently mistypes long ticket numbers, Reza Enterprises has asked his students to write an application that shows if a ticket is invalid. Your application/program tellsthe ticket agent to enter a six-digit ticket number. Ticket numbers are designed so that if you lose the last digit of the number, then divide by 7, the remainder of the division is exactly the same to the last dropped digit. This process is shown below: Step 1: Enter the ticket number; for example 123454 Step 2: Remove the last digit, leaving 12345 Step 3: Determine the remainder when the ticket number from step 2 is divided by 7. In this case, 12345 divided by 7 leaves a remainder of 4. Step 4: Display a message to the ticket agent indicating whether the ticket number is valid or not.. Test your application with the following ticket numbers: - 123454; is a valid ticket number - 147103; is a valid ticket number -…arrow_forwardI need help with this problem. Please help me, because I do not understand. if 14 > 7: print("Greater than 14") x = 2 print(x * 7) else: print("Less than") print(7)arrow_forwardWrite an expression that will cause the following code to print "Equal" if the value of sensorReading is "close enough" to targetValue. Otherwise, print "Not equal". Hint: Use epsilon value 0.0001. Ex: If targetValue is 0.3333 and sensorReading is (1.0/3.0), output is:arrow_forward
- In this problem you will calculate the area of a house and compare it with another house to see which one is bigger. House1 vs. House2 We need to have a struct that has width and length in it. This struct represents a rectangular room. From room we need to define: Bathroom, Livingroom, Bedroom and Kitchen. An example of the struct and Bathroom, Livingroom, Bedroom and Kitchen is shown below. Also, it is shown how to set value of Bathroom Length and Width- values are assumed in feet. House area is in Square Feet (sqrft) and can be calculated by adding all room areas together in sqrft. Program example: Struct room { Length; Width: }; Struct room Bathroom1 , Livingroom1, Kitchen1, Bedroom1; Bathroom1.Length=10; Bathroom1.Width=7; Now Given: House1 is comprised of: Bedroom1 (L=15,W=10) Bathroom1 (L=10,W=7) Kitchen1(L=15, W= 10) Livingroom1 (L=25,W=20) House2 is comprised of: Bedroom2_1 (L=10, W=10) Bedroom2_2(L=10, W=12) Kitchen2(L=16,W=10) Livingroom2 (L=15,W=12) Calculate each House area…arrow_forwardIN PYTHON PLEASE AND FLOWCHART DRAWING COMPUTERIZED PLEASE!! In many businesses across the country, people are buying food and goods using cash. Whenever a purchase is made with cash, it is usual that change must be back to the customer. Business point of sales software help to ensure that the correct change is return to a customer by providing detailed information of the change that should be returned to the customer. using the fewest number of bills and coins. In this assignment, you are asked to design and implement a program that writes out what bills (ones, fives, tens, twenties) and coins (pennies, nickels, dimes, and quarters) that should be returned to the customer given two inputs from the user: A total cost of a sale. The amount that was paid by the customer. Ensure that your output is grammatically correct. If the customer does not provide adequate payment, you should print the following statement, the program should end. Did not receive enough cash from the customer.…arrow_forwardJeff and Gern run a furniture company specializing in tables and chairs. To save time, when a new order comes in, a special shorthand is used to describe the order. The rules for their shorthand are as follows • The first character is "T" for a set of tables, or "C" for a set of chairs. If the order includes both tables and chairs, the order shorthand begins with "TC" • Next they indicate the number of tables or chairs for the order. If the order includes both tables and chairs, they'll write the number of table first, then the number of chairs, separated by a dash. An order comes in for three standard tables constructed using Oakwood. What would the order shorthand be for this order?arrow_forward
- JAVA Based Prgmarrow_forwardAnalyze the following code: int x = 0;int y = ((x < 100) && (x > 0)) ? 1: -1; The code has syntax error. y becomes 1 after the code is executed. y becomes -1 after the code is executed. The code has run time error.arrow_forwardFix the error(s) in the following lines of code.If (chkSpeedingTicket.Checked) = True ThendecTicket = 280End Ifarrow_forward
- JAVA Change the calendar printing program so it starts the week on a Sunday. Also make it print a newline at the end (but only one). The code itself would display the calendar and you would not have to use the println function as you would have to do that for every single month and year. The program would grab the month a year you selected and display it. How change this code? import java.time.DayOfWeek;import java.time.LocalDate;import java.time.Month; public class Calendar { public static void main(String arg []) { int month = 5;LocalDate date= LocalDate.of(year, month, 1);while (date.getMonthValue() == month) { System.out.println(date.getDayOfMonth()); date = date.plusDays(1); }} }arrow_forwardPlease note that on the last line of the code, we need to print out the 'and" with the smallest and the largest number for min and max functions in order to maximize our credit with the zyBooks lab assignment for 3.9. Code Hints: smallestnum = min(usernumbers) #The smallest number is printed out - for example 5, 10, 15 - 5 would be printed out largestnum = max(usernumbers) #The largest number is printed out - for example 5, 10, 15 - 15 would be printed out Write a program that reads a list of integers into a list as long as the integers are greater than zero, then outputs the list values and the smallest and largest integers in the list using min and max built-in functions . This code runs in zyBooks..... Ex: If the input is: 10 5 3 21 2 -6 the output is: [10, 5, 3, 21, 2] 2 and 21 user_numbers = [] user_input = int(input())while user_input > 0: user_numbers.append(user_input) user_input = int(input())print(user_numbers) ''' Complete code here.…arrow_forwardPlease note that on the last line of the code, we need to print out the 'and" with the smallest and the largest number for min and max functions in order to maximize our credit with the zyBooks lab assignment for 3.9. Code Hints: smallestnum = min(usernumbers) #The smallest number is printed out - for example 5, 10, 15 - 5 would be printed out largestnum = max(usernumbers) #The largest number is printed out - for example 5, 10, 15 - 15 would be printed out Write a program that reads a list of integers into a list as long as the integers are greater than zero, then outputs the list values and the smallest and largest integers in the list using min and max built-in functions . Ex: If the input is: 10 5 3 21 2 -6 the output is: [10, 5, 3, 21, 2] 2 and 21 user_numbers = [] user_input = int(input())while user_input > 0: user_numbers.append(user_input) user_input = int(input())print(user_numbers) ''' Complete code here. '''smallest_num=min(user_numbers)largest_num =…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY