实现收税

import java.util.*;

	public class ddfd 
	{
		public static void main(String[] args)
		{
			Menu choicemenu= new Menu();
			String input="Y";
			do{
				choicemenu.choiceMenu();
				Scanner in=new Scanner(System.in);
				int choice=in.nextInt();
				switch (choice)
				{
					case 1:
						choicemenu.choice1();
						break;
					case 2:
						choicemenu.choice2();
						break;
					case 3:
						choicemenu.choice3();
						break;
					case 4:
						choicemenu.choice4();
						break;
					default:System.out.println("Please input the number bewteen 1 and 4.");
				}
				System.out.println("Come back to the Choice-Menu(Y/N)?");
				input=in.next();
				if(input.equals("N")||input.equals("Y"))
				{
					if(input.equals("N"))
					{
						System.out.println("Thinks for your use!");
						System.exit(0); 
					}
				}
				else
				{
					System.out.println("You have a wrong choice!");
					System.out.println("Please input your choice again!(Y/N)");
				}
			}
			while(input.equals("Y"));
		}
	}

	class TaxPayer
	{
		private double salary;
		
		public TaxPayer()
		{
			salary=0;
		}
		
		public double getSalary()
		{
			return salary;
		}
		
		public void setSalary(double s)
		{
			salary=s;
		}
	}

	class TaxList
	{

		private double taxpoint;
		private double[] taxrate=new double[5];
		
		
		public TaxList(double p,double t0,double t1,double t2,double t3,double t4)
		{
			taxpoint=p;
			taxrate[0]=t0;
			taxrate[1]=t1;
			taxrate[2]=t2;
			taxrate[3]=t3;
			taxrate[4]=t4;
		}
		
		public double getTaxpoint()
		{
			return taxpoint;
		}
		
		public void setTaxpoint(double n)
		{
			taxpoint=n;
		}
		
		public double getTaxrate(int n)
		{
			return taxrate[n];
		}
		
		public void setTaxrate(int n,double r)
		{
			taxrate[n]=r;
		}
		
		public double calculate(double s)
		{
			double taxsalary=s-taxpoint;
			double tax;
			if(taxsalary>20000)
			{
				tax=(taxsalary-20000)*0.25+3625;
				return tax;
			}
			
			if(taxsalary>5000)
			{
				tax=(taxsalary-5000)*0.2+625;
				return tax;
			}
			
			if(taxsalary>2000)
			{
				tax=(taxsalary-2000)*0.15+175;
				return tax;
			}
			
			if(taxsalary>500)
			{
				tax=(taxsalary-500)*0.1+25;
				return tax;
			}
			
			tax=taxsalary*0.05;
			return tax;
		}
	}

	class Menu 
	{
		private String input="Y";
		
		Scanner in=new Scanner(System.in);
		TaxList list=new TaxList(1600,0.05,0.10,0.15,0.20,0.25);
		TaxPayer person=new TaxPayer();
		

		public void choiceMenu()
		{
			System.out.println("*********************************************************************");
			System.out.println("             Welcome to use this tax-calculate system!");
			System.out.println("");
			System.out.println("                    1:Change your taxpoint.");
			System.out.println("                    2:Change your taxrate.");
			System.out.println("                    3:Calculate your tax.");
			System.out.println("                    4:Exit.");
			System.out.println("");
			System.out.println("                    Please input your choice:");
			System.out.println("*********************************************************************");
		}
		
		public void choice1()
		{
			System.out.println("Now,the taxpoint is"+list.getTaxpoint());
			System.out.println("Do you need change the taxpoint(Y/N)?");
			do
			{
				input=in.next();
				if(input.equals("N")||input.equals("Y"))
				{
					if(input.equals("Y"))
					{
						System.out.println("Please input your new taxpoint.");
						list.setTaxpoint(in.nextDouble());
					}
					break;
				}
				else
				{
					System.out.println("You have a wrong choice!");
					System.out.println("Do you need change the taxpoint(Y/N)?");
				}
			}
			while(true);
		}

		public void choice2()
		{
			System.out.println("Now,the taxrate is:");
			System.out.println("Level one:"+list.getTaxrate(0));
			System.out.println("Level two:"+list.getTaxrate(1));
			System.out.println("Level three:"+list.getTaxrate(2));
			System.out.println("Level four:"+list.getTaxrate(3));
			System.out.println("Level five:"+list.getTaxrate(4));
			System.out.println("Do you need change the taxrate(Y/N)?");
			do
			{
				input=in.next();
				if(input.equals("N")||input.equals("Y"))
				{
					if(input.equals("Y"))
					{
						System.out.println("Please input you new taxrate.");
						System.out.println("Level one:");
						list.setTaxrate(0,in.nextDouble());
						System.out.println("Level two:");
						list.setTaxrate(1,in.nextDouble());
						System.out.println("Level three:");
						list.setTaxrate(2,in.nextDouble());
						System.out.println("Level four:");
						list.setTaxrate(3,in.nextDouble());
						System.out.println("Level five:");
						list.setTaxrate(4,in.nextDouble());
					}
					break;
				}
				else
				{
					System.out.println("You have a wrong choice!");
					System.out.println("Please input your choice again!(Y/N)");
				}
			}	
			while(true);
		}
		
		public void choice3()
		{
			double salary;
			do
			{
				System.out.println("Please input your salary:");
				salary=in.nextDouble();
				if(salary>=0)
				{
					person.setSalary(salary);
					System.out.println("Your salary is:"+person.getSalary());
					System.out.println("Your tax is:"+list.calculate(salary));
					break;
				}
				else
				{
					System.out.println("Please input the number above 0.");
				}
			}
			while(true);
		}

		public void choice4()
		{
			System.out.println("This system come from Deng He!");
			System.out.println("Thinks for your use!");
			System.exit(0);
		}
	}

 

你可能感兴趣的:(实现)