Java_CH8_HW1


import java.util.*;
public class Java_CH8_HW1
{

 public static void main(String[] args)
 {
  // TODO 自動產生的方法 Stub
  double a = 0, b = 0;
  char opr = (char) -1;
  Tax_Calculation demo = new Tax_Calculation();
  System.out.println("enter single/married s or m");
  try
  {
   opr = (char) System.in.read();
  }
  catch (Exception e)
  {
   System.out.println("Error : " + e.toString());
  }
  System.out.println("enter your income : ");
  Scanner sc = new Scanner(System.in);
  a = sc.nextFloat();
  switch (opr)
  {
   case 's' :
    System.out.println("Your martial status : single. Your tax = "
      + demo.single(a));
    break;
   case 'm' :
    System.out.println("Your martial status : married, Your tax ="
      + demo.married(a));
    break;
   default :
    System.out.println(" Unknown status ");
  }
 }

}

class Tax_Calculation
{
 double y, z;
 public double single(double y)
 {
  this.y = y;
  if (y > 0 && y <= 21450)
  {
   z = y * 0.15;
  }
  if (y > 21450 && y <= 51900)
  {
   z = (y - 21450) * 0.28 + 3217.5;
  }
  if (y > 51900)
  {
   z = (y - 51900) * 0.31 + 11743.5;
  }
  return z;
 }

 public double married(double y)
 {
  this.y = y;
  if (y > 0 && y <= 35800)
   z = y * 0.15;
  else if (y < 86500)
   z = (y - 35800) * 0.28 + 3217.5;
  else if (y > 86500)
   z = (y - 86500) * 0.31 + 11743.5;
  return z;
 }
}

留言

這個網誌中的熱門文章

UVA 11321 Java