Hi there everyone, I am a novice at java and this one has me stumped. This is the beginning of a tax calculator but I am getting irregular output from the getIncome() method. It starts fine, letting the user enter income figures, but on the third income entry or so, the loop fails for one iteration then comes back. For the program to stop taking income figures, a negative number has to be entered, but when I do this I get blank output until I try again at which time the number is subtracted from the income total. I am not looking for a code fix, more where to look and the logic behind it as this is for an assignment and I don't want anyone else to do it for me. Anyway, here is the code (it is incomplete but the main method and the getIncome methods are what I am focused on at the moment). Thanks very much in advance for any and all help
import java.util.*;
public class Tax {
public static void main(String[] args) {
getIncome();
//getExpenses();
}
public static void getIncome(){
Scanner key = new Scanner(System.in);
double income = 0;
System.out.println("Welcome to Tax Calculator");
System.out.println("Please enter your income:");
income = key.nextDouble();
while (income >0)
{
System.out.println("Please enter income:");
income += key.nextDouble();
System.out.println("Please enter income:");
if (key.nextDouble()<0) {
System.out.println("Thank you for using tax calculator, your total income entered is:" + income);
System.exit(0);
}
else if (key.nextDouble() <0 || income <= 0){
System.out.println("Thank you for using tax calculator,the program will now exit");
System.exit(0);
}
}
}
public static void getExpenses(){
Scanner in = new Scanner (System.in);
double expenses = 0;
while (expenses >0)
{
System.out.println("Please enter expenses");
expenses += in.nextDouble();
System.out.println("Please enter expenses");
}
}
}