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

Videos

Textbook Question
Book Icon
Chapter 6, Problem 7P

We can improve the Beer class from the previous Practice Program by using principles of information hiding. The instance variable percent holds the percent of alcohol in the beer. If this variable is public, then someone might enter the alcohol percentage the wrong way. For example, if the alcohol percentage is 5% then someone might set the variable to 5.0 instead of 0.05 that the program expects. As a result, the program would compute that someone would be legally intoxicated after a miniscule sip of beer.

Address this problem by adding or modifying the mutator method, setAlcohol. If the variable that is being set is over 1 then set the alcohol variable to the incoming value divided by 100. Otherwise set the alcohol variable to the incoming value. You should also do this check for the percentage set by the constructor Test your program by sett1ng the percent alcohol to 5 0 and to 0 05 The results should be unchanged.

Blurred answer
Students have asked these similar questions
For your first program, you are to write a simple Dodgeball simulation. In this simulation, we will have nplayers, and one ball. One player, the "thrower," will have the ball. The thrower will throw the ball at anotherplayer, the "target." The target could catch the ball, could be hit by the ball, or the ball could completely missthe target. If the target catches the ball, then the thrower is out of the game (and the target becomes the nextthrower.) If the ball hits the target, then the target is out of the game. If the ball misses the target, neitherplayer is out. In the latter two cases, any one can pick up the ball and become the next thrower. The game isover when only one player is left.In this simple version, the players (initially n players) will stand in a circle. The thrower will always countthe players to his/her right, and then throw the ball at the dth player, who becomes the target. The target willalways catch the ball, so that the thrower will be out of the game (and will…
This may make more sense if I show you a sample run of a program that implements the wizard shown above: Do you want to buy a snowboard? no Do you want to buy downhill skis? yes Have you gone skiing before? yes Are you an expert? no Buy the ZR200 model. Notice how a series of questions is asked by the wizard and answered by the shopper. When there are no more questions to be asked, the conclusion is printed by the wizard and the program exits. The series of questions asked by the wizard closely follows the rules in the flow chart.   A Decision object represents a triangle in the flow cart. The Decision object asks a question and then returns either the next decision in the flow chart, or a message that should be printed before the program terminates. This is an example of the Composite design pattern because a Decision object contains other Decision objects. Here is a description of the methods in the IDecision interface: public void setYes(IDecision yes): Specifies the IDecision that…
Write a simulation of T20 match. There are two teams, Team A and Team B. For every balldelivered generate a random number from -1 to 6 (both inclusive). A -1 means that batsmanis out, any other number is the runs scored on that delivery. A 0 in this case represent a dot ball.After every 12 balls, generate a random value which represents the weather conditions.Random Number Weather Condition Score Limits0 Sunny 0-61 Cloudy 0-42 Windy 0-33 Drizzle 0-24 Rain Match stoppedTeam A plays continuously until all players are out or 120 balls are delivered or match is stoppeddue to the rain.Team B plays continuously until all players are out or 120 balls are delivered they have scoredmore than Team A or match is stopped due to rain. Every time a rain event occurs, deduct 12balls from both innings. A match result should be draw if any of the innings is less than 18 balls.You have to maintain 2d array, store player id and player score. Count total scores of teamsdepending upon preceding…

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...
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 random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY