A New Income

A NEW INCOME

A New Income Q&A

a new income

Q: What is wrong with my Java code?

Ok, so when I run this code everything works besides the pin number. Any pin number I type in, valid or not, I just get the response saying "Sorry, this pin number is not valid." Here is my code: import java.util.Scanner; public class MyBankAccount { public static void main(String[]args) { //Declare variables double deposit; double balance; double yearlyIncome; int years; int numberOfDeposits; boolean inTheBlack; double lifeTimeGoal; double lifeTimeGoalBalance; String name; String pinNumber; Scanner input = new Scanner(System.in); //Asks for age and name, and asks for opinion on hat. System.out.println("What is your name?"); name = input.nextLine(); if (name.equals("Kyle")) { System.out.println("You are my creator, and I thank you for that."); } else if (name.equals("kyle")) { System.out.println("You are my creator, and I thank you for that."); } else { System.out.println("Hello, " + name); } //Asks for pin number System.out.println("What is your pin number?"); pinNumber = input.nextLine(); if (pinNumber.equals(42)){ System.out.println("Congratulations! You have read the Hitchhiker's Guide to the Galaxy! Since 42 is the answer to life, the universe, and everything that still applies at this bank"); } else if (pinNumber.equals(6666)) { System.out.println("This pin number is valid. You may continue."); balance = 8970; System.out.println("Your balance is $" + balance); System.out.println("How much would you like to deposit?"); deposit = input.nextDouble(); System.out.println("Your new balance is $" + (deposit+balance)); System.out.println("What is your yearly income?"); yearlyIncome = input.nextDouble(); System.out.println("What is your lifetime goal for the amount of money you have?"); lifeTimeGoalBalance = input.nextDouble(); System.out.println("You are $" + (lifeTimeGoalBalance - (deposit+balance)) + "away from your goal."); System.out.println("It will take you " + ((lifeTimeGoalBalance - (deposit+balance)) / yearlyIncome) + " years to reach your goal."); System.out.println("Have a nice day!");} else if (pinNumber.equals(6)) { System.out.println("This pin number is valid. You may continue."); balance = 208937420; System.out.println("Your balance is $" + balance); System.out.println("How much would you like to deposit?"); deposit = input.nextDouble(); System.out.println("Your new balance is $" + (deposit+balance)); System.out.println("What is your yearly income?"); yearlyIncome = input.nextDouble(); System.out.println("What is your lifetime goal for the amount of money you have?"); lifeTimeGoalBalance = input.nextDouble(); System.out.println("You are $" + (lifeTimeGoalBalance - (deposit+balance)) + "away from your goal."); System.out.println("It will take you " + ((lifeTimeGoalBalance - (deposit+balance)) / yearlyIncome) + " years to reach your goal."); System.out.println("Have a nice day!");} else if (pinNumber.equals(666)) { System.out.println("This pin number is valid. You may continue."); balance = 32087; System.out.println("Your balance is $" + balance); System.out.println("How much would you like to deposit?"); deposit = input.nextDouble(); System.out.println("Your new balance is $" + (deposit+balance)); System.out.println("What is your yearly income?"); yearlyIncome = input.nextDouble(); System.out.println("What is your lifetime goal for the amount of money you have?"); lifeTimeGoalBalance = input.nextDouble(); System.out.println("You are $" + (lifeTimeGoalBalance - (deposit+balance)) + "away from your goal."); System.out.println("It will take you " + ((lifeTimeGoalBalance - (deposit+balance)) / yearlyIncome) + " years to reach your goal."); System.out.println("Have a nice day!");} else if (pinNumber.equals("Over 9000")) { System.out.println("This pin number is valid. You may continue."); balance = 98078; System.out.println("Your balance is $" + balance); System.out.println("How much would you like to deposit?");

A: You need to do string comparisons, so you'd do: if (pinNumber.equals("42")) { // do stuff }

A New Income Q&A A New Income

 

 

© 2010 anewincome.com Contact us - Q&A powered by Yahoo! Answers

A New Income