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.
THANKS IN ADVANCE!
Oh, and If you're going to try it, Fed fund = 50, GDP growth = 3.
Here's the code:
Code Java:
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)));
}
}
Re: Help with If Else Satement
You choice of bad method and variable names makes your code VERY hard to follow. Next time please surround your code in [highlight=java][/highlight] tags. Are you getting an error when you try to compile your program, are you not recieving the desired output, What is the desired output? As you can see there is loads of data you left out that makes our job alot easier. :)
TIP: If you have a variable named fedfunds, then don't create a method named Fedfunds. Instead make a method named convertToFedFunds or getFedFunds. (just examples. I'm not exactly sure what you're doing in the method)