- private void test() {
- Scanner sc = new Scanner(System.in);
- int seniority = inputInteger(sc, "请输入你的工龄:");
- int wage = inputInteger(sc, "请输入你的基本工资:");
- int addWage = 0;
-
- if(seniority >= 0 && seniority < 1) {
- addWage = 200;
- } else if(seniority >= 1 && seniority < 3) {
- addWage = 500;
- } else if(seniority >= 3 && seniority < 5) {
- addWage = 1000;
- } else if(seniority >= 5 && seniority < 10) {
- addWage = 2500;
- } else if(seniority >= 10 && seniority <= 15) {
- addWage = 5000;
- }
-
- System.out.println(String.format("您目前工作了 %d 年,基本工资为 %d 元, 应涨工资 %d 元,涨后工资 %d 元", seniority, wage, addWage, wage + addWage));
- }
-
- private int inputInteger(Scanner sc, String msg) {
- System.out.print(msg);
- while(true) {
- int result;
- try{
- return sc.nextInt();
- } catch(InputMismatchException e) {
- System.out.println("您的输入有误,请重新输入!");
- }
- }
- }
复制代码
|