Wednesday, 15 February 2012

Any way to better structure many if else statements in Java -


I have a code for a tax program here. If there is a better way to structure more statements and there is also a better way to write programs

  package jOptionPane; I apologize for any comments before hand. Import javax.swing.JOptionPane; Public square main {public static zero main (string [] algs) {double paycheck = double. PRADABB (JoptionPan.Shownput Dialogue ("How much was your paycheck?"); String [] option = new string [] {"yes", "no"}; Int Response = Joppenpen. Shoovotion Diyogyog (empty, "Are you married?", "Title", joptionpan.defflattn, goptionpen.plin_msassage, blank, options, options [0]); Double cut = integer PRIJIANT (ShowPoint Show Input Diallog ("How many deductions did you claim?"); String [] payoffton = new string [] {"weekly", "biennial"}; Int convertibility = JoptionPan.ShowOptionDialog (empty, "How many times do you get paid?", "Title", joppenpenny DEFAULT_OPTION, Joppenpan.PLIN_Massage, blank, Payoffton, Payoffton [0]); Double ss = 0; If (response == 0) {if (convertibility == 0) {if (paycheck and lt; = 490) {ss = (paycheck - (cut * 73.08)) * .1; } And if (paycheck & lt; = 1515) {ss = (paycheck - (deduction * 73.08) * .15 + 33.4; } Else {System.out.println ("I'm too lazy to count"); }} And {if (paycheck and lt; = 981) {ss = (paycheck - (cut * 146.15)) * .1; } And if (paycheck & lt; = 3031) {ss = (paycheck - (deduction * 146.15)) * .15 + 66.9; } Else {System.out.println ("I'm too lazy to count"); }}} And {if (variability == 0) {if (paycheck and lt; = 20 9) {ss = (paycheck - (cut * 73.08)) * .1; } And if (paycheck & lt; = 721) {ss = (paycheck - (deduction * 73.08) * .15 + 16.8; } Else {System.out.println ("I'm too lazy to count."); }} And {if (paycheck & lt; = 417) {ss = (paycheck - (cut * 146.15)) * .1; } And if (paycheck & lt; = 1442) {ss = (paycheck - (deduction * 146.15)) * .15 + 33.4; } Else {System.out.println ("I'm too much to count."); }}} System.out.println ("You" + SS + is "for Social Security"); }}  

In a real system, all these quantities and rates and boundaries are definitely a A simple arithmetic formula involving the values ​​taken from the database table, and a payment processing row (s) applied will be the case.

Think of restructuring the whole thing with those lines

No comments:

Post a Comment