Problem

We can improve the Beer class from the previous Practice Program by using principles of in...

We can improve the Beer class from the previous Practice Program by using principles of information hiding. The instance variable percent holds thepercent 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 thevariable 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 setting the percent alcohol to 5.0 and to 0.05. The results should be unchanged.

Do Practice Program but add a constructor that allows the user to initialize the name and alcoholic content of the beer.

Define a Beer class that contains the following instance variables with accessors/ mutators:

Write code in a main method that creates two Beer objects with different alcohol percentages. Invoke the intoxicated method for a light individual and a heavy individual and output the estimated number of drinks to become legally intoxicated.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT