You are on page 1of 2

2. 1.

      Bread Butter Jam


Fuji likes bread so much. She eats bread daily. She eats bread with butter and jam or
sometimes jam alone. Rarely she eats bread alone. But she wants to know which gives her
more energy. So she want to calculate how much energy she gains from the bread that she
eats. Help her in finding the amount of energy gained from given calories.
1 kcal = 4.1868 kJ
Bread  = 74 calories
Butter  = 102 calories
Jam = 26 calories
Write a java program to calculate the energy and implement it using Method overloading
concept. Print energy with three decimal places.
Method Overloading is a feature that allows a class to have two or more methods having
same name, but their arguments type or the return type of the method or the number of
arguments are different.
 
i.                    Create two class namely, Main and Calories.
ii.                  Get all details in Main class.
iii.                Include a method called, calculateCalories() which is overloaded three
times.
iv.                First calculateCalories() is to calculate the calorie when she eats only
bread.
v.                  Second calculateCalories() is to calculate the calorie when she eats bread
and jam.
vi.                Third calculateCalories() is to calculate the calorie when she eats bread,
butter and Jam.
vii.              Include a method called returnCalories() that returns the calculated
calories.
viii.            Include a method called calculateEnergy() that calculates the energy and
returns the energy value.
Sample input and output 1:
1.Bread only
2.Bread+Jam
3.Bread+Jam+Butter
Enter the choice
2
Enter the number of Slice of bread
2
Enter the number of teaspoon of Jam
4
1055.074 kJ of energy generated from 252.0 calories
 
Sample input and output 2:
1.Bread only
2.Bread+Jam
3.Bread+Jam+Butter
Enter the choice
1
Enter the number of Slice of bread
2
619.646 kJ of energy generated from 148.0 calories
 
Sample input and output 3:
1.Bread only
2.Bread+Jam
3.Bread+Jam+Butter
Enter the choice
3
Enter the number of Slice of bread
3
Enter the number of teaspoon of Jam
4
Enter the number of teaspoon of Butter
6
3927.219 kJ of energy generated from 938.0 calories

You might also like