Question

Please write a Java program that ask the user how many beers he or she expects...

Please write a Java program that ask the user how many beers he or she expects to consume each day, on average, as well as the average amount of money he or she spends on a single 12-ounce can of beer. Studies have shown that, on average, someone who consumes a single 12-ounce can of beer every day without compensating for the calorie intake through diet modifications or extra exercise, will gain approximately 15 pounds in one year. You can assume this ratio of beer-to-weight-gain is constant. (For example, doubling the beer consumption to two 12-ounce cans per day will lead to 30 pounds of extra weight in one year.)

Using this information, your goal is to write a program to determine the following:

  1. How many beers will the user consume over the course of the year?
  2. Assuming a beer is 150 calories, how many calories will the user take in from beer alone over the course of the year?
  3. How much weight can the user expect to gain in one year based on the number of 12-ounce beers they consume every day?
  4. How much the user will spend on beer this year?

All output should be displayed using 2 digits of precision after the decimal point!

You may assume that there are 365 days in a year (ignoring leap years).

Output Sample

Here is one sample output of running the program. Note that this test is NOT a comprehensive test. You should test your program with different data than is shown here based on the specifications given. The user input is given in italics while the program output is in bold.

Sample Run #1

On average, how many beers will you consume each day?

2.5

On average, how much will you pay for each can of beer?

1.25

That is approximately 912.50 beers in one year.

In one year, you will consume approximately 136875.00 calories from beer alone.

Without diet or exercise to counter these calories, you can expect to gain 37.50 pounds from drinking that much beer this year.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOURCE CODE IN JAVA:

import java.util.Scanner; //to use Scanner class for input

class Main

{

public static void main(String[] args)

{

Scanner in=new Scanner(System.in); //Scanner object for input

System.out.print("On average, how many beers will you consume each day? "); //input prompt

double beerPerDay=in.nextDouble(); //input

System.out.print("On average, how much will you pay for each can of beer? "); //input prompt

double costPerbeer=in.nextDouble(); //input

//calculating

double totalBeers=beerPerDay*365;

double totalCost=totalBeers*costPerbeer;

double calories=totalBeers*150;

double weightGained=beerPerDay*15;

//output

System.out.println("That is approximately "+String.format("%.2f",totalBeers)+" beers in one year.");

System.out.println("In one year, you will consume approximately "+String.format("%.2f",calories)+" calories from beer alone.");

System.out.println("Without diet or exercise to counter these calories, you can expect to gain "+String.format("%.2f",weightGained)+" pounds from drinking that much beer this year.");

System.out.println("You will spend $"+String.format("%.2f",totalCost)+" on beer alone in one year.");

}

}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Please write a Java program that ask the user how many beers he or she expects...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
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
ADVERTISEMENT
ADVERTISEMENT