هذا طبعا ً حل دكتوره غاده معانا زمان
Solution:
Problem Analysis Chart:
Given Data Required Results
weight
height
age
numCaloriesChocolateBar numChocolateBarsForFemale
Processing Required Solution Alternatives
caloriesMale= 655 + (4.3 * weight) + (4.7 * height) - (4.7 * age);
numChocolateBarsForMale = caloriesMale / numCaloriesChocolateBar
caloriesFemale = 66 + (6.3 * weight) + (12.9 * height) - (6.8 * age);
numChocolateBarsForWoman = caloriesFemale / numCaloriesChocolateBar
caloriesMale = 655 + (4.3 * weight) + (4.7 * height) - (4.7 * age);
System.out.println("A male with those measurements should eat " +
(caloriesMale / 230) + “candy bars per day to maintain her weight.");
caloriesFemale = 66 + (6.3 * weight) + (12.9 * height) - (6.8 * age);
System.out.println("A female with those measurements should eat " +
(caloriesFemale / 230) + “candy bars per day to maintain her weight.");
Algorithm:
1. Read Weight from user.
2. Read Height from user.
3. Read Age from user.
4. Calculate number of calories a male person can consume without gaining weight.
5. Calculate number of chocolate bars a male person can consumer without gaining weight.
6. Calculate number of calories a female person can consume without gaining weight.
7. Calculate number of chocolate bars a female person can consumer without gaining weight.
8. Displaynumber of calories a male person can consume without gaining weight.
9. Display number of calories a female person can consume without gaining weight.
Sample Code Solution:
import java.util.Scanner;
public class CandyCalculator
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int age;
int weight;
int height;
System.out.println("This program will calculate the number of 230 calorie");
System.out.println("candy bars to eat to maintain your weight.");
System.out.println("What is your age in years?");
age = keyboard.nextInt();
System.out.println("What is your total height in inches?");
height = keyboard.nextInt();
System.out.println("What is your weight in pounds?");
weight = keyboard.nextInt();
double caloriesMale, caloriesFemale;
caloriesMale = 655 + (4.3 * weight) + (4.7 * height) - (4.7 * age);
caloriesFemale = 66 + (6.3 * weight) + (12.9 * height) - (6.8 * age);
System.out.println("A female with those measurements should eat " +
(caloriesFemale / 230) +
" candy bars per day to maintain her weight.");
System.out.println("A male with those measurements should eat " +
(caloriesMale / 230) +
" candy bars per day to maintain her weight.");
}
}