Hi there everyone, I have a bit of a problem I am hoping you can help with. This is for an assignment, and I know I can finish the final calculations for my tax program if I could just pass my 2 variables from previous methods into the final method to get my total taxable income. Here is what I have so far which seems to work, I am not sure though how to correctly enter the parameters for the last method to pull the variables I need through:
import java.util.*;
public class Tax {
static Scanner input = new Scanner (System.in);
public static void main(String[] args) {
System.out.println("Welcome to Tax Calculator");
getIncome();
}
public static double getIncome(){
double income = 0;
System.out.println("Please enter income: ");
double i = input.nextDouble();
income = i;
while (i >0){
System.out.println("Please enter income: ");
i = input.nextDouble();
income += i;
if (i < 0){
income = (income-i);
System.out.println("Total income entered is: " + income);
getExpenses();
}
}
return income;
}
public static double getExpenses(){
double expenses = 0;
System.out.print("Please enter expenses: ");
double j = input.nextDouble();
expenses = j;
while (j > 0){
System.out.print("Please enter expenses: ");
j = input.nextDouble();
expenses += j;
if (j < 0){
expenses = (expenses-j);
System.out.println("Total expenses entered: " + expenses);
calculateTaxPayable(income, expenses);
}
}
return expenses;
}
public static double calculateTaxPayable(double income, double expenses){
double taxable = (income - expenses);
System.out.println("Total taxable income: " + taxable);
return taxable;
}
}
Any help would be greatly appreciated! In the calculateTaxPayable() method, I need to pull through income from getIncome() and expenses from getExpenses() and then do some calculations as to how much tax the user should pay. Thanks very much in advance