Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Help with If Else Satement

1. ## Help with If Else Satement

I'm working on a change in stock price code and all the outputs are right except Intel's Stock Price with change in GDP growth. I know that my GDP if else statement refers to the Fed Fund if else statement and I'm trying to figure out why it works for Jnj and not for Intel.

Oh, and If you're going to try it, Fed fund = 50, GDP growth = 3.

Here's the code:
```import java.text.NumberFormat;
import javax.swing.JOptionPane;

public class Stocks {
static double[ ] jnj = {60, 15, 10, 1};
static double[ ] intel = {25, 40, 45, 2};
static double nspone;// new stock price after change in federal fund rate
static double nsptwo; // new stock price after both fed fund and GDP
static double fedfunds;
static double gdpgrowth;

NumberFormat dollar = NumberFormat.getCurrencyInstance();

public static double Fedfunds(double beta []){
if(beta[3] == 2.0) {

nspone = beta[0] - (beta[0]*((fedfunds*0.20)/100));

} else {

nspone = beta[0] - (beta[0]*((fedfunds*0.10)/100));
}

return nspone;
}

public static double GDPgrowth(double beta[]){
if(beta[3] == 2.0) {

nsptwo = nspone + (nspone*((gdpgrowth*0.07)));

} else {

nsptwo = nspone + (nspone*((gdpgrowth*0.03)));
}
return nsptwo;

}

public static void main(String[] args) {

NumberFormat dollar = NumberFormat.getCurrencyInstance();

fedfunds = Double.parseDouble(JOptionPane.showInputDialog("Please Enter Federal Fund Rate"));
gdpgrowth = Double.parseDouble(JOptionPane.showInputDialog("Please Enter GDP Growth Rate "));

System.out.println("Intel's Original Stock Price " +dollar.format(intel[0]));
System.out.println("JnJ's Original Stock Price " +dollar.format(jnj[0]));
System.out.println("Intel's Stock Price with change in fed fund " +dollar.format(Fedfunds(intel)));
System.out.println("Jnj's Stock Price with change in fed fund " +dollar.format(Fedfunds(jnj)));
System.out.println("Intel's Stock Price with change in GDP growth " +dollar.format(GDPgrowth(intel)));
System.out.println("Jnj's Stock Price with change in GDP growth " +dollar.format(GDPgrowth(jnj)));

}
}```