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 plus MyProgrammingLab with Pearson eText -- Access Card Package (7th 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)
- In this exercise, you have to calculate the student's total marks using the concept of Classes Problem Statement# Write a Java class called Student with ● private fields: ○ name(String type) ○ mark1 and mark2 (double type) And methods: ● getMarks(int markNumber), a method which should return mark1 if markNumber equals 1 and mark2 otherwise. ● calcTotal() method should take the two marks entered and return their sum. Also define two constructors: ● A default constructor that takes no parameters and initializes the values to zeros and null. ● A constructor that takes the three variables and sets them as the values of the appropriate fields. Input# Name of the student and the marks obtained in the first and second tests Output# Sum of both marks Sample Input# Student student = new Student("Jack", 60, 70); Sample Output# getMarks(1) => 60 getMarks(2) => 70 calcTotal() => 130.0 Part of solution class Student { // Define private fields here public Student() { // Write…arrow_forwardclass Point with instance variables as: xCoordinate(int) and yCoordinate(int). Write public instance methods (getters & setters) for each instance variable. Now, write a class Circle with private instance variables as radius and Pi (value is 3.14). Write public setter, getter for radius, Area method for calculating Area, Draw method for radius. Formula for calculating area=pi*r^2 Formula for calculating radius=Math.sqrt(xCordinate^2+yCordinate^2) Extend a Circle class from Point class such as Class Circle extends Point Write a Default constructor in Circle class that sets radius, xCoordinate&yCoordinate to some default value e.g. -1; Write a Parameterized constructor in Circle class which takes xCoordinate, yCoordinate and radius as a parameter. E.g. Circle (int xCoordinate, int yCoordinate, double radius) { this.xCoordinate= xCoordinate; this.yCoordinate= yCoordinate;…arrow_forwardCLASS AND OBJECT WRITE! 1.) Write the main class of the given class Animal below that set the number of legs to “4” and display (get) the number of legs. class Animal { private int numberOfLegs; public void setNumberOfLegs(int numberOfLegs) { this.numberOfLegs = numberOfLegs; } public int getNumberOfLegs() { return numberOfLegs; } }arrow_forward
- The BankAccount class described below is used to represent a personal savings account with a yearly interest rate, (represented as a percentage, e.g., a 7% rate is represented by .07). The interest is applied monthly, (i.e., at the end of each month 1/12 of the interest is deposited into the account). public class BankAccount { public BankAccount(double rate) public BankAccount(double initBal, double rate) public double getBalance() public double getIntRate() public void setIntRate(double rate) public void deposit(double amount) public void withdraw(double amount) public void addMonthsInterest() private double balance; private double intRate; } Suppose a bank offers to its special customers a new type of savings account, called a “Credit Account”, that allows the customer to withdraw extra money if needed, so that the account balance is allowed to be negative at some times. These accounts award interest at the end of every month, as long as the balance is positive. If the…arrow_forwardHand-write two Java classes, Car and Truck. They are bothsubclasses of Vehicle.a. A car has an additional instance variable, number of doors.b. A truck has an additional instance variable, number of axlesc. Write a constructor that requires input for the instance variables of each class(including registration number and owner name).d. Write getters and setters for all instance variables for both classes.arrow_forward1) Write a class called Room, which has three private instance variables: a) a double width, representing the width of the room in feet, b) a double length, representing the length of the room in feet, and c) an int floor, representing the building floor that the room is on. 2) Write a default constructor for the class Room that sets the width to 10, the length to 12.5, and the floor to 1. 3) Write get and set methods (“getters” and “setters”) for the three instance variables. For the set methods for the width and length, only positive values should be set. If the input is 0 or a negative number, the variables should not be changed. 4) Write a constructor for the class Room that takes in two double parameters and an int, and sets length to the larger double, width to the smaller double, and floor to the int. Use the setters from part (b). 5) Override the default toString method for the class Room, so when called by an instance of Room created by the default constructor from part (a)…arrow_forward
- I tried to get this answered before but I couldn't get the code to work fully from what he gave me. " //Definition of class rectangle public class Rectangle { //Declare required variables private double w; private double h; //No-argument constructor public Rectangle() { //Assign "w" to "1" w = 1; //Assign "h" to "1" h = 1; } //Parameterized constructor public Rectangle(double wid, double ht) { //Assign "wid" to "w" this.w = wid; //Assign "ht" to "w" this.h = ht; } //Method definition for width public double getWidth() { //Return width return w; } //Method definition for height public double getHeight() { //Return height return h; } //Method definition for perimeter public double getPerimeter() { //Return the perimeter return 2.0*(w + h); } //Method definition for area public double getArea() { //Return the area return w*h; } }//Definition of test class public class Test { //Definition of main class public static void main(String[] args) { //Create an object for rectangle class…arrow_forwardIn the board game Scrabble, each tile contains a letter, which is used to spell words in rows and columns, and a score, which is used to determine the value of words. The point of this exercise is to practice the mechanical part of creating a new class definition: Write a definition for a class named Tile that represents Scrabble tiles. The instance variables should be a character named "letter" and an integer named "value". Write a constructor that takes parameters named letter and value, and initializes the instance variables. Create getters for both of the attributes. (No setters, so that a Tile is immutable.) Implement the .toString() and .equals methods for a Tile. Your completed Tile class should work with this Main program (Links to an external site.) so that it produces sample output like shown at the end of the program. You can Fork the program to make your own version in Replit, where you can add your Tile.java, or you can copy the program to your own Java development…arrow_forwardhello This is in java Create a class called RoomCarpet that has three private instance variables – room lengthand width in foot (double) and carpet cost per square foot (double). Additionally, the classshould have:a. A constructor that takes room length, room width and carpet cost per square foot. Theconstructor sets the class variables to these values and in case any of these values isnegative, set its instance variable to zero.b. A mutator method (set) and an accessor method (get) for the carpet cost variable only.c. A method getArea that returns the area of the room. The area of the room iscomputed by multiplying the room's length by the room's width.d. A method getTotalCost that returns the total cost of the carpet. The total cost iscomputed by multiplying the room area by the carpet cost per square foot. Part (2)Write a Java application that asks the user to enter the length and width of a room and thecost per square foot of the carpeting. Create an object from RoomCarpet…arrow_forward
- In Java Write a bank account program that handles bank account balances for an array of bank accounts. There aretwo types of bank accounts ─ checking and savings. Use this UML class diagram:BankAccountChecking SavingsImplement the following classes and methods.BankAccount class:Instance variable:balancedeposit method ─ add the given amount to the current balance.Withdraw method ─ subtract the given amount from the current balance. Don’t allow the balance togo below zero. If the balance does go below zero, change the balance to zero.display method ─ This must be an abstract method.Checking class:No new instance variables.writeACheck method ─ subtract the given amount from the current balance and then subtract anadditional $1 as part of a service fee.display method ─ print the type of account, checking, and then the balance (with standard currencyformat). Study the output for details.Savings class:Instance variable:intRate (interest rate)addInterest method ─ calculate the interest by…arrow_forwardUse Java Programming Language Loan Account Class: Create class LoanAccount. Use a static variable annualInterestRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable principal indicating the amount the person is borrowing. Provide method: public double calculateMonthlyPayment(int numberOfPayments) to calculate the monthly payment by using the following formula: double monthlyPayment = principal * ( monthlyInterest / (1 - Math.pow(1 + monthlyInterest, -numberOfPayments))); where monthly interest = annualInterestRate/12. Provide a static method setAnnualInterestRate that sets the annualInterestRate to a new value. Set the initial loan amount (Principal) for a new loan through the constructor. Write a program to test class LoanAccount. Instantiate two LoanAccount objects, loan1 and loan2, with principal loan amounts of $5000.00 and $31000.00, respectively. Set annualInterestRate to 1%, then calculate the monthly…arrow_forwardWrite a class Point with instance variables as: xCoordinate(int) and yCoordinate(int). Write public instance methods (getters & setters) for each instance variable. Now, write a class Circle with private instance variables as radius and Pi (value is 3.14). Write public setter, getter for radius, Area method for calculating Area, Draw method for radius. Formula for calculating area=pi*r^2 Formula for calculating radius= sqrt (xCordinate^2+yCordinate^2) Extend a Circle class from Point class such as Class Circle extends Point Write a Default constructor in Circle class that sets radius, xCoordinate & yCoordinate to some default value e.g. -1; Write a Parameterized constructor in Circle class which takes xCoordinate, yCoordinate and radius as a parameter. E.g. Circle (int xCoordinate, int yCoordinate, double radius) { this.xCoordinate= xCoordinate; this.yCoordinate= yCoordinate;…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning