java - How to use methods and call them within the Switch statement -


i'm making tax calculator class can't quite figure out how separate code in individual cases

  println("please enter filing status: ");     println("enter 0 single filers,");     println("      1 married filing jointly,");     println("      2 married filing separately, or");     println("      3 head of household");     double tax = 0;     decimalformat df = new decimalformat("#.00");     int filingstatus = readint("status: ");     switch (filingstatus) {         case 0: double taxableincomes = readdouble("please enter taxable income: ");         if (taxableincomes <= 8925)         {             tax = (taxableincomes * ten);             println("you owe: $" + df.format(tax));         }         if (taxableincomes > 8925 && taxableincomes <= 36250)         {                 tax = 892.5 + fifteen * (taxableincomes - 8925);             println("you owe: $" + df.format(tax));         }         if (taxableincomes > 36250 && taxableincomes <= 87850)         {             tax = 892.5 + 4098.75 + twentyfive * (taxableincomes - 36250);             println("you owe: $" + df.format(tax));         }         if (taxableincomes > 87850 && taxableincomes <= 183250)         {             tax = 892.5 + 4098.75 + 12900 + twentyeight * (taxableincomes - 87850);             println("you owe: $" + df.format(tax));         }         if (taxableincomes > 183250 && taxableincomes <= 398350)         {             tax = 892.5 + 4098.75 + 12900 + 26712 + thirtythree * (taxableincomes - 183250);             println("you owe: $" + df.format(tax));         }         if (taxableincomes > 398350 && taxableincomes <= 400000)         {             tax = 892.5 + 4098.75 + 12900 + 26712 + 70983 + thirtyfive * (taxableincomes - 183250);             println("you owe: $" + df.format(tax));         }         if (taxableincomes > 400000)         {             tax = 892.5 + 4098.75 + 12900 + 26712 + 70983 + 577.5 + thirtynine * (taxableincomes - 183250);             println("you owe: $" + df.format(tax));         }            break; 

into separate methods call methods under case:0. calculator i'm supposed use 4 separate methods , since have 4 separate cases figured easing thing sort code each case different methods call methods each case have. if try use

private double tax() 

and copy , paste of code under case 0: tells me class,interface, or enum expected.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -