Develop a Java program to assist a user in managing their daily calorieintake. Allow the user to input the calories consumed for breakfast, lunch,and dinner. Use control statements to calculate the total calories consumedthroughout the day. Implement operators to perform arithmetic calculationsto determine the total calories. Display the total calorie count to the userand provide feedback on whether they have exceeded or stayed within theirdaily calorie limit (e.g., 2000 calories). Utilize appropriate data types,operators, and control statements to help users track and manage their dailycalorie intake effectively.
Question
Develop a Java program to assist a user in managing their daily calorieintake. Allow the user to input the calories consumed for breakfast, lunch,and dinner. Use control statements to calculate the total calories consumedthroughout the day. Implement operators to perform arithmetic calculationsto determine the total calories. Display the total calorie count to the userand provide feedback on whether they have exceeded or stayed within theirdaily calorie limit (e.g., 2000 calories). Utilize appropriate data types,operators, and control statements to help users track and manage their dailycalorie intake effectively.
Solution
Here is a simple Java program that can help a user manage their daily calorie intake:
import java.util.Scanner;
public class CalorieCounter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the calories consumed for breakfast:");
int breakfast = scanner.nextInt();
System.out.println("Enter the calories consumed for lunch:");
int lunch = scanner.nextInt();
System.out.println("Enter the calories consumed for dinner:");
int dinner = scanner.nextInt();
int totalCalories = breakfast + lunch + dinner;
System.out.println("Total calories consumed today: " + totalCalories);
if (totalCalories > 2000) {
System.out.println("You have exceeded your daily calorie limit.");
} else if (totalCalories == 2000) {
System.out.println("You have reached your daily calorie limit.");
} else {
System.out.println("You are within your daily calorie limit.");
}
}
}
This program uses the Scanner class to get user input for the calories consumed for breakfast, lunch, and dinner. It then adds these values together to calculate the total calories consumed throughout the day.
The program then uses an if statement to check if the total calories is greater than, equal to, or less than the daily limit of 2000 calories, and prints a message to the user accordingly.
Similar Questions
Develop a Java program to help a user manage their daily water intake.Allow the user to input the amount of water consumed (in liters) for morning,afternoon, and evening. Use control statements to calculate the total waterconsumed throughout the day. Implement operators to perform arithmeticcalculations to determine the total water intake. Display the total water intaketo the user and provide feedback on whether they have met or exceeded therecommended daily water intake (e.g., 2.5 liters). Utilize appropriate datatypes, operators, and control statements to help users track and manage theirdaily water intake effectively.
Develop a Java program to assist a user in managing their daily exerciseroutine. Allow the user to input the duration (in minutes) of exercisesperformed for morning, afternoon, and evening. Use control statements tocalculate the total exercise time throughout the day. Implement operators toperform arithmetic calculations to determine the total exercise time. Displaythe total exercise time to the user and provide feedback on whether they havemet or exceeded their daily exercise goal (e.g., 60 minutes). Utilizeappropriate data types, operators, and control statements to help users trackand manage their daily exercise routine effectively
Write a program that helps users analyze the nutritional content of different foods. The program should prompt the user to enter the number of calories, protein grams, carbohydrate grams, fat grams, and fiber grams in a food item. Based on this information, the program should calculate and display the following:· The percentage of calories that come from protein.· The percentage of calories that come from carbohydrates.· The percentage of calories that come from fat.· The percentage of calories that come from fiber. Additionally, the program should determine the level of fat in the food item and display it as "low", "moderate", or "high" based on the percentage of calories from fat: · If the percentage of calories from fat is less than 30%, the food is considered low in fat.· If the percentage of calories from fat is between 30% and 60%, the food is considered moderate in fat.· If the percentage of calories from fat is greater than 60%, the food is considered high in fat.Ensure that the program handles input validation to prevent negative values for any of the nutritional components.Input:· Number of calories in the food (an integer)· Number of protein grams in the food (an integer)· Number of carbohydrate grams in the food (an integer)· Number of fat grams in the food (an integer)· Number of fiber grams in the food (an integer)Output:· Percentage of calories from protein (a floating-point number)· Percentage of calories from carbohydrates (a floating-point number)· Percentage of calories from fat (a floating-point number)· Percentage of calories from fiber (a floating-point number)· Level of fat in the food (a string: "low", "moderate", or "high")Constraints:· All input values are non-negative integers.· Each input value should fit within the range of an integer data type.
Star Fitness Club wants to calculate the Body Mass Index (BMI) for all its customers. Customers may enter their height and weight. Each customer should know their body mass index and weight loss or gain goals to be fit and healthy. Help them to achieve this with the help of a Java program. The formula for calculating BMI is weight/((height/100) *(height/100)).Display the bmi with respect to 2 decimal points.If bmi is greater than or equal to 25, print "You are overweight" and then print the number of kilograms to be reduced to become fit as "Reduce <<kgs>>kg to be fit".If bmi is less than 25 and greater than or equal to 18.5, print "You are fit and healthy".If bmi is less than 18.5, print "You are underweight" and then print the number of kilograms to be gained to become fit as "Gain <<kgs>>kg to be fit".Note:In the Sample Input / Output provided, the highlighted text in bold corresponds to the input given by the user, and the rest of the text represents the output.Ensure to follow the object-oriented specifications provided in the question description.Ensure to provide the names for classes, attributes, and methods as specified in the question description.Adhere to the code template, if provided.Please do not use System.exit(0) to terminate the program. Sample Input 1:Enter weight in kg108Enter height in cm168Sample Output 1:Your BMI is 38.27. You are overweightReduce 13.27 kg to be fitSample Input 2:Enter weight in kg68Enter height in cm172Sample Output 2:Your BMI is 22.99. You are fit and healthySample Input 3:Enter weight in kg42.7Enter height in cm158Sample Output 3:Your BMI is 17.10. You are underweightGain 1.40 kg to be fit
Tracking the CaloriesImagine you are training for a marathon, and you have decided to track the number of calories you burn each day for an entire week. Your goal is to understand your average calorie burn over the week to better tailor your training and nutrition plans.You need to create a program to help you with this task. Consider the user-input of day and no of calories burned in that day and store it into a dictionary datatype.Pass this dictionary to a function "Calculate" to calculate the average calories burned and find the day which recorded maximum calories burned.Constraints:Input Format:Day and no of calories burned should be taken for 7 daysOutput Format:First line of output displays the average calories burnedSecond line of output displays the maximum calories burned day.Example:Sample Input 1:Day1120Day2180Day3130Day480Day5167Day6290Day7239Sample Output 1:172Day6Explanation:Day and no of calories taken for 7 daysThe average calories burned is 172 in the weekSo, first line of output is 172The maximum calories burned is 290 on Day6So, the second line of output is Day6Public Test Cases:# INPUT EXPECTED OUTPUT1 Day1120Day2180Day3130Day480Day5167Day6290Day7239172 Day6
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.