Salary Raise Application


Submit solution

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

Authors:
Problem type

題目說明

請設計一個 Employee 類別,具備以下功能:

  1. 使用者需輸入兩位員工的姓名與薪水。

  2. 接著輸入每位員工的加薪百分比。

  3. 若加薪比例為負數,則顯示錯誤訊息,並不進行加薪。

  4. 請依照範例程式模板撰寫,不可變更主程式結構,否則不予計分。

  5. 每位員工的資訊需使用 getInfo 方法輸出,格式如範例。

輸入

每個員工共輸入三個資料:

  1. 員工的姓名(字串)

  2. 員工的薪水(整數)

  3. 員工的加薪比例(整數,單位為 %)

輸出

對每位員工:

若加薪比例為正數或零,輸出加薪後資訊:Name: 姓名, Salary: 加薪後薪水
若加薪比例為負數,先輸出錯誤訊息:You cannot increase the salary by a negative amount
然後輸出加薪前資訊(因為未加薪):Name: 姓名, Salary: 原始薪水

程式模板

import java.util.Scanner;

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

        String name1 = scanner.nextLine();
        int salary1 = scanner.nextInt();
        int raise1 = scanner.nextInt();
        scanner.nextLine(); 

        Employee emp1 = new Employee(name1, salary1);
        emp1.increaseSalary(raise1);
        System.out.println(emp1.getInfo());

        String name2 = scanner.nextLine();
        int salary2 = scanner.nextInt();
        int raise2 = scanner.nextInt();

        Employee emp2 = new Employee(name2, salary2);
        emp2.increaseSalary(raise2);
        System.out.println(emp2.getInfo());
    }
}

// 請在下方建立 Employee 類別

範例輸入 #1

Ethan
3000
5
Mia
2500
8

範例輸出 #1

Name: Ethan, Salary: 3150
Name: Mia, Salary: 2700

說明:
Ethan 加薪 5%,3000 + 3000×5% = 3150。
Mia 加薪 8%,2500 + 2500×8% = 2700。

範例輸入 #2

Bob
2000
10
Amy
5000
-5

範例輸出 #2

Name: Bob, Salary: 2200
You cannot increase the salary by a negative amount
Name: Amy, Salary: 5000

說明:
Bob 的薪資為 2000,加薪 10%,即 2000 + 2000×10% = 2200。
Amy 加薪 -5%,為負數,因此顯示錯誤訊息,薪水維持原樣不變,為 5000。


Comments

There are no comments at the moment.