I just need a smidge of help to determine the maximum value of the taxPayable assignment and it's associated name
Note: probably lots of things not perfect with my code XD
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Ass1dDialog
{
public static void main(String[] args)
{
double taxTotal = 0, yearlyIncome = 0, maxTaxPayable = 0;
int loopCounter = 0;
final int loopMax = 3;
String maxTaxPayerName = "";
JOptionPane.showMessageDialog(null, "Welcome to the Tax Computation System");
for(int x = 0; x < loopMax ; x++){
String taxPayerName = "";
taxPayerName = JOptionPane.showInputDialog("Enter the Tax Payer's Name");
double taxPayable = computeTax(yearlyIncome);
yearlyIncome = Double.parseDouble(JOptionPane.showInputDialog(" Enter income for " + taxPayerName + "")); //WRITE "Enter income for the tax payer==> "
JOptionPane.showMessageDialog(null, "The tax that " + taxPayerName + " has to pay is $" + computeTax(yearlyIncome) + "\n");
this is the line(s) that I seem to be having the most trouble with
if (computeTax(yearlyIncome) > maxTaxPayable){
maxTaxPayable = taxPayable;
I have tried all sorts of positioning and methods of producing the maximum value. But for some reason it seems to display the wrong values, and I can't figure out why :[
}
}
JOptionPane.showMessageDialog(null, "The maximum tax payable is $" + maxTaxPayable + ", payable by " + maxTaxPayerName + "\n");
}
private static double computeTax(double yearlyIncome)
{
double taxPayable, maxTaxPayable = 0;
final double RATE0 = 0, ////
RATE1 = 18200, //
RATE2 = 37000, //
RATE3 = 87000, //
RATE4 = 180000; // - Tax rates for 2017
final double RATE_A = 0.19, //
RATE_B = 0.325, //
RATE_C = 0.37, //
RATE_D = 0.47; ////
if (yearlyIncome < RATE1) {
taxPayable = (yearlyIncome * RATE0); ////
} else if (yearlyIncome < RATE2) { //
taxPayable = ((yearlyIncome - RATE1) * RATE_A); //
} else if (yearlyIncome < RATE3) { //
taxPayable = (3572 + (yearlyIncome - RATE2) * RATE_B); // - Determine tax payable from yearly income input.
} else if (yearlyIncome < RATE4) { //
taxPayable = (19822 + (yearlyIncome - RATE3) * RATE_C); //
} else { //
taxPayable = (54232 + (yearlyIncome - RATE4) * RATE_D); ////
}
return taxPayable;
}
}
Aucun commentaire:
Enregistrer un commentaire