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

Extra Work Happy Hour Objective: Write a class called Beer in which it follows t

ID: 3769218 • Letter: E

Question

Extra Work

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

PROGRAM:

import java.util.*;
import java.io.*;
class Beer
{
   double alcohol_content;
   String name;
   void setName(String value)
   {
       name=value;
   }
   void setAlcoholContent(double value)
   {
       if(value<0 || value > 1)
       {
           System.out.println("The value of alcohol content should be between 0 and 1");
           System.exit(0); /* To exit when wrong alcohol value is given*/
       }
       else
       alcohol_content=value;  
   }
   double Intoxicated(double weight)
   {
       return (0.08 + 0.015) * weight / (12 * 7.5 * alcohol_content); /* Formula to calculate Intoxication */
   }
  
}
class Party
{
   public static void main (String[] args) throws java.lang.Exception
   {
       Scanner sc = new Scanner(System.in);
       Beer br =new Beer();
       Beer br1 = new Beer();
       System.out.println("Let’s Party! Responsibly...");
       System.out.println("What’s the name of the first beer?");
       br.setName(sc.nextLine());
       System.out.println("What’s the alcoholic content?");
       br.setAlcoholContent(sc.nextDouble());
       /* To take input with spaces in between words */
       sc.nextLine();          
       System.out.println("What’s the name of the second beer?");
       br1.setName(sc.nextLine());
       System.out.println("What’s the alcoholic content?");
       br1.setAlcoholContent(sc.nextDouble());
       System.out.println("What’s the weight of the person consuming said beverages?");
       double weight=sc.nextDouble();
       double num1=br.Intoxicated(weight);
       double num2=br1.Intoxicated(weight);
       System.out.print("It would take ");
       /* To show value upto 3 decimal points */
       System.out.printf("%.3f ",num1);
       System.out.println(br.name+ " beers to become intoxicated.");
       System.out.print("It would take ");
       System.out.printf("%.3f ",num2);
       System.out.println(br1.name+ " beers to become intoxicated. Later Tater");
      
   }
}