Employee Salary Management System


Submit solution

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

Authors:
Problem type
Allowed languages
Java 19, Java 8

題目說明

請完成以下程式,設計一個 Employee 類別來管理員工資料與薪資調整功能。

  1. increaseSalary(int ratio)
  • 用來增加員工薪資百分比
  • 若輸入負數,需輸出: You cannot increase the salary by a negative amount,並直接結束方法
  1. toString()
  • 回傳員工資訊,範例格式如下:Name: John, Salary: 309
  1. main() 主程式
  • 建立兩位員工物件
  • 幫員工增加薪資
  • 呼叫 increaseSalary()
  • 輸出員工資訊

樣板程式碼如下

class Employee {
    private String name;
    private int salary;

    public Employee(String name, int salary) {
        this.name = name;
        this.salary = salary;
    }

    public void increaseSalary(int ratio) { 
       //TODO:請補齊剩下的程式碼。
    }

    public String toString() {
       //TODO:請補齊剩下的程式碼。
    }
}

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

        String name1 = sc.next();
        int salary1 = sc.nextInt();
        int ratio1 = sc.nextInt();

        String name2 = sc.next();
        int salary2 = sc.nextInt();
        int ratio2 = sc.nextInt();

        Employee emp1 = new Employee(name1, salary1);
        Employee emp2 = new Employee(name2, salary2);

        emp1.increaseSalary(ratio1);
        emp2.increaseSalary(ratio2);

        System.out.println(emp1);
        System.out.println(emp2);

        sc.close();
    }
}

輸入值的格式

第一位員工姓名、員工薪資、員工調薪百分比、第二位員工姓名、員工薪資、員工調薪百分比

輸出值的格式

Name: 員工姓名, Salary: 調薪後薪資

sample input1

John 300 3 Alice 4800 5

sample output1

Name: John, Salary: 309
Name: Alice, Salary: 5040

sample input2

Tom 1000 -10 Mary 2000 -20

sample output2

You cannot increase the salary by a negative amount
You cannot increase the salary by a negative amount
Name: Tom, Salary: 1000
Name: Mary, Salary: 2000

Comments

There are no comments at the moment.