Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Is this adequate pseudocode for this program?
Here's the program's first part:
import java.util.Scanner;
import java.text.DecimalFormat;
public class FatGramCalculator
{
public static void main (String [] args)
{
DecimalFormat formatter = new DecimalFormat("#0.0");
Scanner keyboard = new Scanner (System.in);
// variable declarations
double calories; // number of calories
double fatGrams; // number of fat grams
double caloriesFromFat; // number of calories from fat
double percentageCaloriesFromFat; // percentage of calories from fat
// Get calories and fat grams from user
System.out.println("How many calories are there in the food item?");
calories = keyboard.nextDouble();
System.out.println(); // for empty line
System.out.println("How many grams of fat are there in the food item?");
fatGrams = keyboard.nextDouble();
System.out.println(); // for empty line
Here's the second:
// calculate the percentage of calories from fat
caloriesFromFat = fatGrams * 9;
if (caloriesFromFat > calories)
{
System.out.println("The amount of calories and/or fat grams you entered is invalid.");
}
else
{
percentageCaloriesFromFat = caloriesFromFat / calories;
System.out.println("The percentage of calories from fat in this item is " + formatter.format(percentageCaloriesFromFat * 100) + "%.");
if ( percentageCaloriesFromFat < .3 )
{
System.out.println("This item is low in fat");
}
}
}
}
Here's the pseudocode:
Have user enter the calories and the fat grams.
Calculate the caories from fat by multiplying the fat grans by 9.
If the calories from fat are more than the total calories then stop program and tell user.
If the calories from fat are less than the total calories then find the percentage of calories from fat by dividing the calories from fat by the total calories.
Output the percentage of calories from fat to the user.
If the percentage of calories from fat is less than 30% the output that the food is low in fat.
2 Answers
- 1 decade agoFavorite Answer
That is not Pseudocode but an algorithm. http://en.wikipedia.org/wiki/Pseudocode <-- this link will you with, what is Psudocode?
- Anonymous1 decade ago
it seems to be ok.