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
  • Problem C: Walking off the Calories Suppose a person can burn off the 150 calories from...

    Problem C: Walking off the Calories Suppose a person can burn off the 150 calories from a beer by walking for 40 minutes at a moderate pace of 3 miles per hour. Based on the number of beers the user consumes each day, as well as the number of minutes he or she walks each day, determine how much longer the user must walk (both in minutes as well as in hours) in one year to counter the rest of...

  • I need help to write a program in Java. If a moderately active person cuts their...

    I need help to write a program in Java. If a moderately active person cuts their calorie intake by 500 calories a day, they can typically lose about 4 pounds a month. Write a program that lets the user enter their starting weight, then creates and displays a table showing what their expected weight will be at the end of each month for the next 6 months if they stay on this diet.

  • Write a program and flowchart. The program should ask the user how many customers they want...

    Write a program and flowchart. The program should ask the user how many customers they want to track. Then, it asks for customer numbers, and sales by customer. At the end, it prints out the customer number, the customer sales, and then the total sales and average sales. You must use two different arrays, one for customer number, and one for sales. These are, in effect, parallel arrays.   You must use a "while" loop to gather customer number and sales....

  • Write a program in Java. Ask the user how many integers that he/she wants to enter....

    Write a program in Java. Ask the user how many integers that he/she wants to enter. Using a for loop, ask the user for that many integers. Then, display all those integers. view required output Standard Input                 20ENTER 500ENTER 400ENTER 300ENTER 550ENTER 600ENTER 700ENTER -3ENTER 0ENTER 50ENTER 60ENTER 40ENTER 13ENTER 14ENTER 80ENTER 90ENTER 100ENTER 777ENTER 1024ENTER 20ENTER 22 How many integers do you have? (Max 20)\n Enter element for subscript 0\n Enter element for subscript 1\n Enter element for...

  • The Yukon Widget Company manufactures widgets that weigh 9.2 pounds each. Write a Java program that calculates how many...

    The Yukon Widget Company manufactures widgets that weigh 9.2 pounds each. Write a Java program that calculates how many widgets are stacked on a pallet, based on the total weight of the pallet. The program should ask the user how much the pallet weighs by itself and with the widgets stacked on it. It should then calculate and display the number of widgets stacked on the pallet. (you can have partial widgets)

  • Create a Python program that asks the user how many miles they think they may run....

    Create a Python program that asks the user how many miles they think they may run. The program should also ask them how much they weight. The program should then use a loop to calculate and print the number of calories burnt while running each mile. o Assume that a person burns 1 calorie per pound during each mile of running

  • Sylvia wants to lose 40 pounds. How many kcalories does this represent? Group of answer choices 105,000 85,000 140,000 3...

    Sylvia wants to lose 40 pounds. How many kcalories does this represent? Group of answer choices 105,000 85,000 140,000 3500 Flag this Question Question 2 1 pts If Paul eats 350 kcals less every day, how many kcalories does he not consume each week? Group of answer choices 2450 4000 3500 2280 Flag this Question Question 3 day? Group of answer choices 3.5 pounds 1.4 pounds 2.8 pounds 4.2 pounds Move To... This element is a more accessible alternative to...

  • Write a Java program that calculates how much a person would earn after a period of...

    Write a Java program that calculates how much a person would earn after a period of time, according to the following rules: 1. The starting salary for the first day is $1. 2. The salary will double each day. Ask the user to input the number of days worked. The output should display how much the salary was for each day worked, and show the total pay at the end of the work period. Get output similar to the sample...

  • Write a program and flowchart. The program should ask the user how many customers they want to track. Then, it asks for customer numbers, and sales by customer. At the end, it prints out the customer...

    Write a program and flowchart. The program should ask the user how many customers they want to track. Then, it asks for customer numbers, and sales by customer. At the end, it prints out the customer number, the customer sales, and then the total sales and average sales. You must use two different arrays, one for customer number, and one for sales. These are, in effect, parallel arrays.   You must use a "while" loop to gather customer number and sales....

  • 3,4, and 5 please! 15 points Answer the following questions. Please show your work to help...

    3,4, and 5 please! 15 points Answer the following questions. Please show your work to help justify your Show critical thinking skills Narrative. J.R is a 27-year-old male. He is 5 feet, 9 inches tall. He weights 187 pounds. He runs three days a week, a moderate pace, for 20 minutes. On the weekends, he enjoys doing yardwork, walking his dog, and hanging out with his friends. J.R. would like to improve his overall diet, and he has the following...

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