Employee Salary Manager


Submit solution

Points: 45 (partial)
Time limit: 1.0s
Memory limit: 64M

Authors:
Problem type

題目說明

請設計一個 Employee 類別,並完成TODO部分,Employee 類別具有以下功能:

透過建構子設定員工的姓名(name)與薪資(salary)。

設計方法 increaseSalary(int ratio),用來調整薪資,比例由使用者指定(例如 5 表示增加 5%)。

若輸入負數,請輸出提示訊息 "You cannot increase the salary by a negative amount",並且不調整薪資。

輸入

輸入第一位員工的姓名(字串)、薪資(整數)和該員工的加薪比例(整數,單位%)。

接著輸入第二位員工的姓名(字串)、薪資(整數)和該員工的加薪比例(整數,單位%)。

輸出

輸出每位員工的姓名與薪資,並顯示加薪後的結果。

若加薪比例是負數,顯示錯誤訊息 "You cannot increase the salary by a negative amount",並不進行加薪。

程式模板

import java.util.Scanner;

// TODO: 請在此建立 Employee 類別
// 要包含:
// - 私有屬性 name (String)、salary (int)
// - 建構子 Employee(String name, int salary)
// - 方法 void increaseSalary(int ratio):調整薪資
// - 方法 String toString():回傳格式化的員工資訊

public class MyProgram {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // TODO:輸入第一位員工資料

        // TODO:呼叫 increaseSalary 方法進行加薪

        // 顯示結果
        System.out.println(employee1);

        // TODO:輸入第二位員工資料

        // TODO:呼叫 increaseSalary 方法進行加薪

        // 顯示結果
        System.out.println(employee2);

        scanner.close();
    }
}

範例輸入 #1

John 2500 -10
Alice 4000 4

範例輸出 #1

You cannot increase the salary by a negative amount
Name: John, Salary: 2500
Name: Alice, Salary: 4160

說明: John 薪水加薪為負,薪資不變。 Alice 薪水增加 4%,變成 4000 + 160 = 4160。


Comments

There are no comments at the moment.