Gregory Desrosiers Montreal

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Sunday, 18 November 2012

Java Program : Fat Gram Calculator

Posted on 18:06 by Unknown
Here's another program I want to share with you guys, which is simply a program that multiplies the number of grams of fat in food by nine, which gives off how many calories you earn upon eating a serving of that snack or provision. You need to enter the number of calories in the actual serving in that calculator and the number of grams of fat, and what will do is it will calculate the percentage and determine whether the food has a high amount of fat, at least 30%, or not.

This time, there are no notes taken on how this works.

import javax.swing.JOptionPane;
import java.text.DecimalFormat;

public class FatGramCalculator
{
    public static void main(String[] args)
    {
        String inputString;
        float totalCalories,
            fatGrams,
            caloriesFromFat,
            ratio,
            percent;
       
        DecimalFormat formatter = new DecimalFormat("##");
       
        inputString =
                JOptionPane.showInputDialog("How many calories are in the food item you want to study?");
        totalCalories = Float.parseFloat(inputString);
       
        inputString =
                JOptionPane.showInputDialog("How much fat is in the food item, in grams?");
        fatGrams = Float.parseFloat(inputString);
       
        caloriesFromFat = fatGrams * 9;
       
        ratio = caloriesFromFat / totalCalories;
       
        percent = ratio * 100;
       
        if (percent > 100)
            JOptionPane.showMessageDialog(null, "Invalid entry.");
       
        if (percent <= 100)
            JOptionPane.showMessageDialog(null, "Number of calories in food item: " + totalCalories +
                                        "\nNumber of grams of fat in food item: " + fatGrams +
                                        "\n\nPercent of calories of fat to total calories: " +
                                        (formatter.format(percent)) + "%");
       
        if (percent < 30)
            JOptionPane.showMessageDialog(null, "The food item is low in fat.");
       
        System.exit(0);
           
    }
}
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • The Quebec Ministerial Exam of College English (English Exit Exam)
    Hello, everyone. How you doing? I'm good. There is some unfortunate news for me to deliver, though I am planning to try to work myself a...
  • JAVA Program: Military Time to Real Time
    Hello, people. How you doing? I'm really busy with my college homework, but I am working so hard to pass my courses and continue in my s...
  • JAVA Code for the Rock Paper Scissors Program
    Hello, people. How are you doing? I want to show off the code for the game of Rock Paper Scissors where it's just one player against the...
  • String Letter Counter (JAVA Program)
    Hello, guys. This is another JAVA Program I want to share with you guys. It's a counter for a specific letter in an entered string strai...
  • DOS Games to Play
    Hello, people. If there's one thing that I want to do when I have lots of money, it's to play full version DOS Games on my Windows P...
  • JAVA Program: Circle Cannon Shooter (Shooting Game, Experimental Program on Graphics and Event Listeners)
    Hello , everyone. This is the last blog I will write that contains code I wrote myself but from one of my three JAVA courses that is shared ...
  • Java Programming : For Loop Example
    Here's an example of using a for loop in JAVA. This program uses a loop inside another to create a list of integers where the number on ...
  • The Asperger Computer: A Self-Published Guide on Asperger's Syndrome and Multimedia
    The Asperger Computer - A Self-Published Guide on Asperger's Syndrome and Multimedia by Gregory Desrosiers How is Asperger’s syndrome li...
  • Best VGM Series
    Hello, guys. I want to present to you a series of YouTube imports of video game music, with some of them already recorded but in a form that...
  • Computer Game Collection
    Hello, people! Before I happen to leave this very foundation of Champlain College Saint-Lambert (that's where I'm learning to get wh...

Blog Archive

  • ►  2013 (38)
    • ►  August (2)
    • ►  July (9)
    • ►  June (12)
    • ►  May (12)
    • ►  April (2)
    • ►  January (1)
  • ▼  2012 (24)
    • ►  December (13)
    • ▼  November (3)
      • Java Programming : For Loop Example
      • Java Program : Fat Gram Calculator
      • JAVA Program: Military Time to Real Time
    • ►  October (5)
    • ►  September (1)
    • ►  August (2)
Powered by Blogger.

About Me

Unknown
View my complete profile