UI.java
资源名称:project4.rar [点击查看]
上传用户:dscysp
上传日期:2021-04-07
资源大小:268k
文件大小:3k
源码类别:
家庭/个人应用
开发平台:
Java
- import java.util.*;
- /**
- * 用户界面
- * @author 07302260 蒋鹏
- *
- */
- public class UI {
- private taxSystem taxS = new taxSystem();
- private Scanner in = new Scanner(System.in);
- public UI()
- {
- System.out.println("欢迎使用个人所得税计算系统 by cs07A JP");
- System.out.println();
- System.out.println("系统默认基数及税率表");
- showScale();
- while(true)
- {
- System.out.println();
- System.out.println("1.计算个人所得税");
- System.out.println("2.修改基数及税率表");
- System.out.println("3.显示当前基数及税率表");
- System.out.println("4.退出");
- System.out.println("请选择操作:");
- int a = in.nextInt();
- switch(a)
- {
- case 1:
- calculateTax();
- break;
- case 2:
- modifyScale();
- break;
- case 3:
- showScale();
- break;
- case 4:
- System.exit(0);
- break;
- default:
- System.out.println("输入错误!");
- }
- }
- }
- /**
- * 显示当前基数及税率表
- */
- public void showScale()
- {
- System.out.println("当前基数为:");
- System.out.println("RMB "+taxS.taxGetBase()+"");
- System.out.println("当前税率表为:");
- int n;
- n = taxS.taxGetSize();
- int i;
- for(i=0;i<n;i++)
- {
- System.out.println(taxS.taxGetScale(i, 0)+" "+taxS.taxGetScale(i, 1));
- }
- }
- /**
- * 计算个人所得税
- */
- public void calculateTax()
- {
- System.out.println();
- System.out.println("请输入您的收入:");
- System.out.print("RMB ");
- int income = in.nextInt();
- if (income<0)
- {
- System.out.println("输入错误,请重新输入");
- }
- else
- {
- double tax = taxS.taxSolve(income);
- System.out.println();
- System.out.println("您所需要缴纳的个人所得税为"+tax+"元");
- }
- }
- /**
- * 修改当前基数及税率表
- */
- public void modifyScale()
- {
- System.out.println();
- System.out.println("1.修改基数");
- System.out.println("2.修改税率表");
- System.out.println("请选择操作:");
- int b = in.nextInt();
- switch(b)
- {
- case 1:
- System.out.println("请输入新的基数:");
- int base = in.nextInt();
- taxS.taxSetBase(base);
- break;
- case 2:
- System.out.println("请输入新的税率表(请不要多于20级,从低到高输入,输入-1结束):");
- int [][] newtab = new int[10][2];
- int newn = 0;
- int n = 0;
- for(int i=0; i<10; i++)
- {
- System.out.println("新收入级别起点:");
- newtab[i][0]=in.nextInt();
- n=newtab[i][0];
- if (n==-1)
- break;
- System.out.println("新收入级别税率(单位%):");
- newtab[i][1]=in.nextInt();
- newn++;
- }
- taxS.taxSetScale(newtab, newn);
- break;
- }
- }
- }