Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Happy Hour Objective: Write a class called Beer in which it follows this format:

ID: 3766323 • Letter: H

Question

Happy Hour

Objective:  

Write a class called Beer in which it follows this format:

Instance Variables

Name

Alcohol content. Beer is around 0.05 or 5%

MethodsAccessors and Mutators for the instance variables

Make sure in the mutator for the alcohol content contains a check to make sure the value is between 0 and 1 exclusively.

Intoxicated

Takes in a parameter of type double corresponding to weight

Calculates the number of drinks required to make a person intoxicated based on this formula (0.08 + 0.015) x Weight / (12 x 7.5 x Alcohol)

Returns the number of beers it would take before they are intoxicated

Next write another class

Contains a main method

Creates two instances of the type Beer

Have the user enter in the names and alcohol contents for both

Next enter in a weight value and it calculates how many drinks it would take for a person at that weight to become intoxicated

Print out the results

Example Output:

Let’s Party! Responsibly...

What’s the name of the first beer?

Pabst Blue Hipster

What’s the alcoholic content?

0.05

What’s the name of the second beer?

Moo Brew

What’s the alcoholic content?

0.08

What’s the weight of the person consuming said beverages?

150

It would take 3.166 Pabst Blue Hipster beers to become intoxicated.

It would take 1.979 Moo Brew beers to become intoxicated.

Later Tater

Explanation / Answer


/**
* The java class Beer that sets the instance variables
* beer name, alcohlic percentage. The class has
* methods to return name and alchohlic percentage
* and number of drinks to intoxicated
* */
//Beer.java
public class Beer
{
   //instance variables
   private double BEER_PERCENT=0.05;
   private String name;
   private double alcoholPercent;
  
   //Set name of beer
   Beer(String name)
   {
       this.name=name;
   }
  
   //Sets alcohol percent
   public void setAlcholPercent
   (double alcoholPercent)
   {
       if(alcoholPercent>=0 &&alcoholPercent<=1)
           this.alcoholPercent=alcoholPercent;
       else
           //set default percent for beer 0.05
           this.alcoholPercent=BEER_PERCENT;
   }
  
   //Returns alcoholic percentage
   public double getAlcoholPercent()
   {
       return alcoholPercent;
   }
  
   //Returns name of beer
   public String getName()
   {
       return name;
   }
      
   //Returns number of number for intoxicated
   public double Intoxicated
   (double weight)
   {      
       return (0.08+0.015)*weight/(12*7.5*alcoholPercent);      
   }
}//end of the class

-----------------------------------------------------------------------------

/**
* The java class BeerTest that tests the Beer
* class by instantiage two beer objects
* The program prompts user to enter name, alcohol
* percentage of two beers and weight of person
* and returns number of drinks to intoxicated.
* */
//BeerTest.java
import java.util.Scanner;
public class BeerTest
{
   public static void main(String[] args)
   {
      
       //Scanner class object
       Scanner scanner=
               new Scanner(System.in);
      
       //Variables
       String beerName;
       double percent;
       double weight;
      
       System.out.println
       ("Let's Party! Responsibly...");
      
       System.out.println("What's the name of the first beer?");
       //Read name of beer
       beerName=scanner.nextLine();
      
       System.out.println("What's the alcholic content?");
       //read alcoholic percentage and parse to double
       percent=Double.parseDouble(scanner.nextLine());
      
      
       //Create an object of Beer
       Beer beer1=new Beer(beerName);
       beer1.setAlcholPercent(percent);
      
       System.out.println("What's the name of the first beer?");
       //Read name of beer
       beerName=scanner.nextLine();
      
       System.out.println("What's the alcholic content?");
       //read alcoholic percentage and parse to double
       percent=Double.parseDouble(scanner.nextLine());
      
       //Create an object of Beer,beer2
       Beer beer2=new Beer(beerName);
       beer2.setAlcholPercent(percent);
      
       System.out.println("What’s the weight of the person consuming said beverages?");
       weight=scanner.nextDouble();
      
       System.out.printf("It would take %.3f %s beers to become intoxicated. ",
               beer1.Intoxicated(weight),beer1.getName());
      
       System.out.printf("It would take %.3f %s beers to become intoxicated. ",
               beer2.Intoxicated(weight),beer2.getName());
      
       System.out.println("Later Tater");
   }
}


----------------------------------------------------------------------------------

Sample Output:

Let's Party! Responsibly...
What's the name of the first beer?
Pabst Blue Hipster
What's the alcholic content?
0.05
What's the name of the first beer?
Moo Brew
What's the alcholic content?
0.08
What’s the weight of the person consuming said beverages?
150
It would take 3.167 Pabst Blue Hipster beers to become intoxicated.
It would take 1.979 Moo Brew beers to become intoxicated.
Later Tater

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote