# If-Else Statement and Math

• February 2nd, 2012, 08:35 PM
mikecancelosi
If-Else Statement and Math
So, I am trying to make a program that does a math problem. Can someone please look at problem and see what i am doing wrong? The problem is "double Ea = EEa + KEa + GEa;" and it cant find EEa, KEa, or GEa. Here is the full code:
Code :

```import java.util.*; import java.util.Scanner; import java.*; /** * Write a description of class EnergyWork here. * * @author (your name) * @version (a version number or a date) */ public class EnergyWork { // instance variables - replace the example below with your own private int x;   /** * Constructor for objects of class EnergyWork */ public EnergyWork() { // initialise instance variables x = 0; }   public static void main(String[] args) { Scanner kb = new Scanner(System.in);   System.out.println("Answer the next 3 questions about point A (Yes or No)");   System.out.println("Is the object moving?");   String Aa = kb.nextLine(); if( Aa.equals("Yes")||( Aa.equals("yes"))) { System.out.println("What is m?"); double Aam = kb.nextInt(); System.out.println("What is Va?"); double Aav = kb.nextInt();   double KEa = .5 * Aam * (Aav * Aav);   System.out.print("Kinetic Energy = " + KEa); }   System.out.println("Is the object elevated?");   String Ab = kb.nextLine(); if( Ab.equals("Yes") ||( Ab.equals("yes"))) { System.out.println("What is m?"); double Abm = kb.nextInt(); System.out.println("What is Ha?"); double Ha = kb.nextInt(); double GEa = Abm * 9.8 * Ha;   System.out.print("Gravitational Energy = " + GEa); }   System.out.println("Is the object on a spring?");   String Ac = kb.nextLine(); if( Ac.equals("Yes")||( Ac.equals("yes"))) { System.out.println("What is k?"); double Ak = kb.nextInt(); System.out.println("What is Xa?"); double Xa = kb.nextInt(); double EEa = .5 * Ak * (Xa * Xa);   System.out.print("Elastic Energy = " + EEa); }   double Ea = EEa + KEa + GEa; System.out.print("The energy of the system at point A =" + Ea); } }```

Thanks!
• February 3rd, 2012, 12:31 AM
Mr.777
Re: If-Else Statement and Math