中易网

大一Java程序设计问题

答案:1  悬赏:0  
解决时间 2021-01-17 18:56
  • 提问者网友:容嬷嬷拿针来
  • 2021-01-17 12:30
大一Java程序设计问题
最佳答案
  • 二级知识专家网友:孤独的牧羊人
  • 2021-01-17 12:46
多余话不说直接上代码,求采纳!package com.main;

import java.util.Calendar;
import java.util.Scanner;

public class Main {

    
    public static void main(String[] args) throws Exception {
        Calendar date = Calendar.getInstance();
        int year = date.get(Calendar.YEAR);
        int year_get = chackyear(year);
        int money = chackMoney();
        System.out.println("该员工赢得奖金:" + getBonus(year, year_get, money));
    }

    
    public static int chackyear(int thisyear) throws Exception {
        int return_year = 0;
        System.out.println("请输入员工入职年份");
        Scanner input = new Scanner(System.in);
        String year = input.nextLine();
        try {
            int year_get = Integer.parseInt(year);
            if (year_get < 0 || thisyear < year_get) {
                putException("ILLegalYearException:无效的年份");
            } else {
                return_year = year_get;
            }

        } catch (Exception e) {
            putException("ILLegalYearException:无效的年份");
        }
        return return_year;
    }

    
    public static int chackMoney() throws Exception {
        int return_money = 0;

        System.out.println("请输入员工月工资");
        Scanner input = new Scanner(System.in);
        String money = input.nextLine();
        try {
            int money_get = Integer.parseInt(money);
            if (money_get < 0 || money_get < 500) {
                putException("ILLegalSalaryException:无效月工资");
            } else {
                return_money = money_get;
            }

        } catch (Exception e) {
            putException("ILLegalSalaryException:无效月工资");
        }
        return return_money;
    }

    
    public static double getBonus(int year, int yearget, int money) {
        int year_count = year - yearget;

        if (year_count == 0) {
            return money;
        } else if (year_count <= 3 && year_count > 0) {
            return money * 1.3;
        } else if (year_count > 3 && year_count <= 5) {
            return money * 1.5;
        } else {
            return money * 2;
        }
    }

    
    public static void putException(String name) throws Exception {
        throw new Exception(name);
    }

}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息