Define a Beer class that contains the following instance variables with accessors/mutators:
String name; // The name of the beer
doub alcohol; // The percent alcohol of the beer, e.g. // 0.05 for 5%
Add the following method:
// This method returns the number of drinks that a person
// of (weight) pound s can drink using the alcohol percentage
// in the beer, assuming a drink of 12 ounces. This is an
// estimate. The method assumed that the legal limit is 0.08 blood
// alcohol
public double intoxicated (double weight)
{
double numDrinks;
// This is a simplification of the Widmark formula
numDrinks = (0. 08 + 0. 015) *weight / (12 * 7.5 * alcohol);
return numDrinks;
}
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.
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Additional Engineering Textbook Solutions
Web Development and Design Foundations with HTML5 (8th Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Concepts of Programming Languages (11th Edition)
Software Engineering (10th Edition)
Modern Database Management (12th Edition)
Introduction to Programming Using Visual Basic (10th Edition)
- #pyhton programing topic: Introduction to Method and Designing class Method overloading & Constructor overloading ------------------ please find the attached imagearrow_forwardWrite a member method for the Team class named : calculatePercentage that it will calculate and return the winning percentage of a team. The winning percentage is calculated as follows: wins / ( wins + losses)arrow_forward//Todo write test cases for SimpleCalculator Class // No need to implement the actual Calculator class just write Test cases as per TDD. // you need to just write test cases no mocking // test should cover all methods from calculator and all scenarios, so a minimum of 5 test // 1 for add, 1 for subtract, 1 for multiply, 2 for divide (1 for normal division, 1 for division by 0) // make sure all these test cases fail public class CalculatorTest { //Declare variable here private Calculator calculator; //Add before each here //write test cases here }arrow_forward
- public class Accumulator { private int total private String name; public Accummulator (string name , int total) { this .name = name; this .total=total; } } 3. In a main method, create an object of Accumulator with the name as "Mary" and total as 100.arrow_forwardJava programarrow_forward2019 AP® COMPUTER SCIENCE A FREE-RESPONSE QUESTIONS 2. This question involves the implementation of a fitness tracking system that is represented by the StepTracker class. A StepTracker object is created with a parameter that defines the minimum number of steps that must be taken for a day to be considered active. The StepTracker class provides a constructor and the following methods. addDailySteps, which accumulates information about steps, in readings taken once per day activeDays, which returns the number of active days averageSteps, which returns the average number of steps per day, calculated by dividing the total number of steps taken by the number of days tracked The following table contains a sample code execution sequence and the corresponding results. Statements and Expressions Value Returned Comment (blank if no value) StepTracker tr StepTracker(10000); Days with at least 10,000 steps are considered active. Assume that the parameter is positive. new tr.activeDays () ; No…arrow_forward
- This is the tester of two classesarrow_forwardArea of a rectangle = length * width Create a Class that calculates and prints out the area of a rectangle. Then write code that creates an object of this Class in which given the length and width, it calculates and prints out the area of a rectangle. Your output should look like this: Area of rectangle: 87arrow_forward#pyhton programing topic: Introduction to Method and Designing class Method overloading & Constructor overloading ------------------ please find the attached imagearrow_forward
- JAVA PROGRAM Chapter 7. PC #1. Rainfall Class Write a RainFall class that stores the total rainfall for each of 12 months into an array of doubles. The program should have methods that return the following: • the total rainfall for the year • the average monthly rainfall • the month with the most rain • the month with the least rain Demonstrate the class in a complete program. Main class name: RainFall (no package name) NOTE, THE MAIN CLASS NAME needs to be Rainfall as mentioned above AND IT HAS TO PASS ALL THE TEST CASES WHEN I UPLOAD IT TO HYPERGRADE. THANK YOU Enter the rainfall amount for month 1:\n1.2ENTEREnter the rainfall amount for month 2:\n2.3ENTEREnter the rainfall amount for month 3:\n3.4ENTEREnter the rainfall amount for month 4:\n5.1ENTEREnter the rainfall amount for month 5:\n1.7ENTEREnter the rainfall amount for month 6:\n6.5ENTEREnter the rainfall amount for month 7:\n2.5ENTEREnter the rainfall amount for month 8:\n3.3ENTEREnter the…arrow_forwardjava programming Robot Class : a robot has a name , located at a point with integer coordinates , faces north , east , south , or west and keeps a record of all its movements positions . The class has the following methods : A default constructor that initializes robot's name to " Unknown ” , location to ( 0,0 ) , direction to North , and travelled distance to 0 , and simulated movements to null . A constructor that given robot's name , starting location , and facing direction , Accessor methods to access all the instance variables and the simulated movements of the robot Mutator methods that change the instance variables to given values and they made the change for only suitable values . tumLeft and turn Right methods that change the direction of the robot but not the location move method that moves the robot by one unit in the direction it is facing . get Travelled Distance method that retums how many units has the robot moved .arrow_forwardShape Classes Design classes Square, RightTriangle , and Triangle that encapsulate three geometric shapes. Each class should implement a method void draw (int x, int y) that “draws" a square, a right triangle, or an equilateral triangle (a triangle with three equal sides), respectively. See Figure 2. The parameters x and y specify the relative position of the figure: y lines down and x spaces acro from the current position of the screen cursor. The instance variables of each class are: int rows , the number of rows that comprise the figure, and char character , the keyboard character used for drawing the figure. Each shape of Figure 2 consists of five rows. The drawing characters are *** for the square, %' for the right triangle, and #' for the equilateral triangle. Shape (abstract) int rows char character Shape() Shape(int x, char c) int get rows() char getCharacter() void setRows(int x) void setCharacter(int x) void draw(int x, int y) (abstract) Square() Square(int x, char ch) void…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,