1,105,427 Community Members

Check my math please

Member Avatar
juan92
Newbie Poster
11 posts since Nov 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

so i am trying to learn java on my own as a hobby, because well i didn't see my self doing this for a living, and i did terrible in the class, so i am going over the text book again, and starting from scratch.

i am not sure if i did this exercise correctly, it runs, but i want to make sure its the logical answer.

il summarize

A government research lab has conducted an artificial sweetner in diet soda has killed mice, you friend wishes to loose weight and wants to know how much he an drink. the program has no input. make sure to define the following constants, the amount of sweetner needed to kill the mouse, the weight of the mouse, starting weigh of your friend, and desired weight of your friend. to ensure his safety use the weight at which your friend will sop dieting. also 0.1% of the soda is sweetener, use another constant for this. if you don't use a defined constant its fine.


and here is my code

public class Exercise_4
{
    public static void main(String[] args)
    {
        //declare variables
        int AMOUNT_SODA;
        int MOUSE_WEIGHT;
        int START_WEIGHT;
        int DESIRED_WEIGHT;
        double SWEETNER_PERCENT_SODA;
        double sweetnerKillMouse; // amount of sweetner that will kill mouae
        double sweetnerKillHuman;//amount of soda that will kill a human
        double newAmountSoda;
        
        //assigne variables
        AMOUNT_SODA = 12;//espressed in oz
        MOUSE_WEIGHT = 2;//expressed in lbs
        START_WEIGHT = 150;
        DESIRED_WEIGHT = 140;
        SWEETNER_PERCENT_SODA = 0.001;
       
        //find out how much sweet ner killed te mouse
        sweetnerKillMouse = SWEETNER_PERCENT_SODA * AMOUNT_SODA;
        
        //find out how much sweetner human drinks till he dies 
        //(amount of sweetner that kills human / human weight) = (amount that kills mouse / mouse weight)
        sweetnerKillHuman = DESIRED_WEIGHT * sweetnerKillMouse / MOUSE_WEIGHT;
        
        //find out the total amount of sida which has the amount of sweetner that kills a human
        //(amount of sweetner that kills the mouse / amount of soda ) = (amount of sweetner that kills human / new amount of soda)
        newAmountSoda = (AMOUNT_SODA * sweetnerKillHuman) / sweetnerKillMouse;
        
        //display
        System.out.println(newAmountSoda);//MY RESULT IS 840.00
    }//end main
}//end class
Member Avatar
abelLazm
Postaholic
2,087 posts since Feb 2011
Reputation Points: 183 [?]
Q&As Helped to Solve: 128 [?]
Skill Endorsements: 4 [?]
 
0
 

First of all SWEETNER_PERCENT_SODA = .1/100*AMOUNT_SODA ;

Member Avatar
abelLazm
Postaholic
2,087 posts since Feb 2011
Reputation Points: 183 [?]
Q&As Helped to Solve: 128 [?]
Skill Endorsements: 4 [?]
 
0
 

i can't understand Line # 23 how can you say that??? 12 oz of soda killed a mouse the that 12 oz contain 0.1 % sweetener inside it then why to calculate again?

Member Avatar
abelLazm
Postaholic
2,087 posts since Feb 2011
Reputation Points: 183 [?]
Q&As Helped to Solve: 128 [?]
Skill Endorsements: 4 [?]
 
2
 

if 12oz of soda killed 2 lbs of mouse than it means 6 oz soda is enough for 1 lb.... If it is true than if the weight of you friend is also in lbs then just multiply the weight with 6oz

//declare variables
        int AMOUNT_SODA;
        int MOUSE_WEIGHT;
        int START_WEIGHT;
        int DESIRED_WEIGHT;
        double SWEETNER_PERCENT_SODA;
        double sweetnerKillMouse_2lb; // amount of sweetner that will kill mouae
        double sweetnerKillMouse_1lb;
        double sweetnerKillHuman;//amount of soda that will kill a human
        double newAmountSoda;
        
        //assigne variables
        AMOUNT_SODA = 12;//espressed in oz
        MOUSE_WEIGHT = 2;//expressed in lbs
        START_WEIGHT = 150;
        DESIRED_WEIGHT = 140;
        SWEETNER_PERCENT_SODA = (0.1/100) *AMOUNT_SODA
       
        //find out how much sweet ner killed te mouse
       // sweetnerKillMouse = SWEETNER_PERCENT_SODA * AMOUNT_SODA;
        sweetnerKillMouse_2lb = SWEETNER_PERCENT_SODA;
        sweetnerKillMouse_1lb=sweetnerKillMouse_2lb/2;
        //find out how much sweetner human drinks till he dies 
        //(amount of sweetner that kills human / human weight) = (amount that kills mouse / mouse weight)
      //  sweetnerKillHuman = DESIRED_WEIGHT * sweetnerKillMouse / MOUSE_WEIGHT;
          sweetnerKillHuman = DESIRED_WEIGHT * sweetnerKillMouse_1lb;
        //find out the total amount of sida which has the amount of sweetner that kills a human
        //(amount of sweetner that kills the mouse / amount of soda ) = (amount of sweetner that kills human / new amount of soda)
        newAmountSoda = (AMOUNT_SODA * sweetnerKillHuman) / sweetnerKillMouse;
        
        //display
        System.out.println(newAmountSoda);//MY RESULT IS 840.00
Member Avatar
juan92
Newbie Poster
11 posts since Nov 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

i never thought of it that way, thank you.

Question Answered as of 2 Years Ago by abelLazm
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article