Hello people, I searched on the web, searched on this site as well but I couldn't get help. So please help me out. This is the code I have written so far. And yes this is an assignment.
This program calculates tax from multiple tax payers.
-----------------------------------------------------------------------------------------------------------------import javax.swing.JOptionPane; public class CalcutateTax { public static void main (String [] args) { String firstName; double grossIncome; double netIncome; int children; double dependencyExemption; double taxDue; firstName = JOptionPane.showInputDialog (null, "What is your first name? "); grossIncome = Double.parseDouble(JOptionPane.showInputDialog("What is your gross income? ")); children = Integer.parseInt(JOptionPane.showInputDialog(" And " + firstName + " how many children do you have? ")); dependencyExemption = 3000*children; netIncome = grossIncome - dependencyExemption; taxDue = calculateTax (netIncome); JOptionPane.showMessageDialog ( null, "Name:" + firstName +"\nGross income: $ " + grossIncome + "\nNumber of children: "+ children + "\nTax due: $" + taxDue); int n = JOptionPane.showConfirmDialog( null,"Calculate another tax returns?", "Confirmation", JOptionPane.YES_NO_OPTION); } public static double calculateTax(double theNetIncome) { double theTaxDue; if (theNetIncome > 50000) { theTaxDue = (15*50000)/100 + (25 *(theNetIncome-50000)/100) ; } else if (theNetIncome>0) { theTaxDue = (15*theNetIncome)/100; } else { theTaxDue = 0; } return theTaxDue; } }
The problem is I cant think how to ask the use if he wants to calculate tax due for another taxpayer. If the user says yes, keep calculating, otherwise exit from the program. And how do I keep count of how many people got their tax calculated? Say for example,
JOptionPane.showMessageDialog (null, " We calculated tax for " + xnumber + " number of people.");
This is the question asked on my assignment
ask the user if he wants to calculate the tax due for another taxpayer
if so, do it again
At the end of the main method, output a message in a dialog box that says: Hello, We calculated taxes for [number of taxpayers].
replace [number of taxpayers] with the actual number of taxpyers you calculated taxes for.