Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 4.2, Problem 25STQ
Suppose that you did not have assertion checking in Java. (Earlier versions of Java did not.) Write some code to simulate the following assertion check, where balance is a variable of type double:
assert balance > 0;
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In JAVA
ASSIGNMENT DESCRIPTION:
A half-life is the amount of time it takes for a substance or entity to fall to half its original value. Caffeine has a half-life of about 6 hours in humans. Given caffeine amount (in mg) as input, output the caffeine level after 6, 12, and 24 hours.
Output each floating-point value with two digits after the decimal point, which can be achieved as follows:System.out.printf("After 6 hours: %.2f mg\n", yourValue);
Ex: If the input is:
100
the output is:
After 6 hours: 50.00 mg After 12 hours: 25.00 mg After 24 hours: 6.25 mg
Note: A cup of coffee has about 100 mg. A soda has about 40 mg. An "energy" drink (a misnomer) has between 100 mg and 200 mg.
THE CODE I HAVE SO FAR:
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
double caffeineMg; // "double" supports floating-point like 75.5, versus int for integers like 75.
caffeineMg = scnr.nextDouble();
System.out.printf("After…
Correct the following wrong statements.
In Java, once a variable is declared in a method as local variable, it will be visible and could be used in any other method in the program.
Use java and classes
Chapter 4 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 4.1 - What output is produced by the following code? int...Ch. 4.1 - Can the body of a while loop execute zero times?...Ch. 4.1 - What output is produced by the following code? int...Ch. 4.1 - Revise the following code so that it uses a while...Ch. 4.1 - What output is produced by the following code? int...Ch. 4.1 - Imagine a program that reads the population of a...Ch. 4.1 - Prob. 7STQCh. 4.1 - What output is produced by the following code? int...Ch. 4.1 - What output is produced by the following code? for...Ch. 4.1 - What output is produced by the following code? for...
Ch. 4.1 - Prob. 11STQCh. 4.1 - Write a for statement that displays the even...Ch. 4.1 - Prob. 13STQCh. 4.2 - Write a Java loop that will display the phrase One...Ch. 4.2 - Write a Java loop that will set the variable...Ch. 4.2 - Write a Java loop that will read a list of numbers...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - Revise the loop shown in Listing 4.6 to use a...Ch. 4.2 - What is the bug in the code in the section Tracing...Ch. 4.2 - Add some suitable output statements to the...Ch. 4.2 - What is the bug in the code in the previous...Ch. 4.2 - Prob. 24STQCh. 4.2 - Suppose that you did not have assertion checking...Ch. 4.3 - Prob. 26STQCh. 4 - Write a fragment of code that will read words from...Ch. 4 - Develop an algorithm for computing the...Ch. 4 - Develop an algorithm for a simple game of guessing...Ch. 4 - Write a fragment of code that will compute the sum...Ch. 4 - Convert the following code so that it uses nested...Ch. 4 - Write a for statement to compute the sum 1 + 22 +...Ch. 4 - (Optional) Repeat the previous question, but use...Ch. 4 - Write a loop that will count the number of blank...Ch. 4 - Write a loop that will create a new string that is...Ch. 4 - Write a program that will compute statistics for...Ch. 4 - Suppose we attend a party. To be sociable, we will...Ch. 4 - Define an enumeration for each of the months in...Ch. 4 - Write a fragment of code that computes the final...Ch. 4 - Suppose that you work for a beverage company. The...Ch. 4 - Suppose that we want to compute the geometric mean...Ch. 4 - Prob. 16ECh. 4 - Create an applet that draws a pattern of circles...Ch. 4 - Prob. 18ECh. 4 - What does the following fragment of code display?...Ch. 4 - Repeat Practice Program 4 of Chapter 3, but use a...Ch. 4 - Write a program that implements your algorithm...Ch. 4 - Repeat Practice Program 5 of Chapter 3, but use a...Ch. 4 - Write a program to read a list of nonnegative...Ch. 4 - Write a program to read a list of exam scores...Ch. 4 - Combine the programs from Programming Projects 5...Ch. 4 - Write a program that simulates the Magic 8 Ball...Ch. 4 - Whats for dinner? Let the computer decide. Write a...Ch. 4 - Write a program that implements your algorithm...Ch. 4 - Prob. 2PPCh. 4 - Write a program that reads a bank account balance...Ch. 4 - Modify Programming Project 5 from Chapter 2 to...Ch. 4 - Write a program that asks the user to enter the...Ch. 4 - Write a program that simulates a bouncing ball by...Ch. 4 - You have three identical prizes to give away and a...Ch. 4 - Prob. 9PPCh. 4 - Holy digits Batman! The Riddler is planning his...Ch. 4 - Your country is at war and your enemies are using...Ch. 4 - Prob. 12PPCh. 4 - Prob. 13PPCh. 4 - Prob. 14PPCh. 4 - (Challenge) Repeat the previous project, but...Ch. 4 - Write a JavaFx application that displays a series...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
How many cells can be in a computers main memory if each cells address can be represented by two hexadecimal di...
Computer Science: An Overview (12th Edition)
(Population growth) A certain city had a population of 25000 in 1960 and a population of 30,000 in 1970. Assume...
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
Fill in the blanks in each of the following statements: Thestatement, when executed in an iteration statement, ...
Java How To Program (Early Objects)
A sentence is in disjunctive normal form (DNF) if it is the disjunction of conjunctions of literals. For exampl...
Artificial Intelligence: A Modern Approach
Repair Bill Suppose automobile repair customers are billed at the rate of per hour for labor. Also, suppose co...
Introduction To Programming Using Visual Basic (11th Edition)
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
- 1.Explain encapsulation and inheritance with suitable examples. 2.Write a program that prompts the user to enter the minutes and displays the number of years and days for the minutes. For simplicity, assume a year has 365 days. 3.What is the purpose of Static variable in Java? Give example. Why is main function in a Java program static and public? 4.Write a program that prompts the user to enter a point (x, y) and checks whether the point is within the circle centered at (0, 0) with radius 10. For example, (4, 5) is inside the circle and (9, 9) is outside the circle.arrow_forwardIn c++. Read all instructions.arrow_forwardSolve those: ( please don't copy from online): source code:arrow_forward
- Hi... I am trying the Gladis Java (Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science) ISBN: 9780134787961) chapter programming challenges (Chapter 6, 2PC, 17PC, and 18PC in particular) in java in netbeans and every time I have "public class Main", it throws an error, "class Main is public, should be declared in a file named Main.java" It asks to rename the file "Main". How do I get around this? Thanks, Scottarrow_forwardQUESTION 21 Java uses early binding for all methods except for a few cases. O False O Truearrow_forwardsubject: java programingarrow_forward
- Question: Your task is to find the number of ways that you can put those brackets in such a way that they will be always balanced after taking the n pair of brackets from the user in Java Language.arrow_forwardTrue or False A Java method can be defined to accept a varying number of parameters.arrow_forwardIn JAVA please help with the following: You are asked to write a discount system for a beauty salon, which provides services and sells beauty products. It offers 3 types of memberships: Premium, Gold and Silver. Premium, gold and silver members receive a discount of 20%, 15%, and 10%, respectively, for all services provided. Customers without membership receive no discount. All members receive a flat 10% discount on products purchased (this might change in future). Your system shall consist of three classes: Customer, Discount and Visit, as shown in the class diagram. It shall compute the total bill if a customer purchases $x of products and $y of services, for a visit. Also write a test program to exercise all the classes. The class DiscountRate contains only static variables and methods (underlined in the class diagram). You should write JUnit tests for all your methods except constructors, getters and setters.arrow_forward
- Need dry run for the following code in java language This question is from the book absolute java 5th edition by savitch w mock k Ch 13 question 10arrow_forwardjavaarrow_forward3. Write Java program that will calculate the amount to be paid for electrical consurmption This problem is to handle electric billing for customers. The billing is depending on the type of the customer account There are two types of customer account, 1) fixed rate method and 2) variable rate method In the case of fixed rate method, the minimum monthly charge of RM20 00 is assessed if the consumption is less than or equal 100 KWh (kilowatt hours). Otherwise the rate of RMO 22 per kWh is charged for the first 100 KWh and the rate of RMO 33 per kWh is charged for the additional consumption. In the case of variable rate method, the rate of RMO.22 per kWh is charged for the consumption less than or equal to 100 kWh. Any additional consumption is charged at RM0.35 per kWharrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Files & File Systems: Crash Course Computer Science #20; Author: CrashCourse;https://www.youtube.com/watch?v=KN8YgJnShPM;License: Standard YouTube License, CC-BY
UNIX Programming (Part - 10) The File System (Directories and Files Names); Author: ITUTEES;https://www.youtube.com/watch?v=K35faWBhzrw;License: Standard Youtube License