Energy Storage


Submit solution

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

Authors:
Problem type
Allowed languages
Java 19, Java 8

題目說明

設計 PowerStation 類別,其中包含以下方法:

calculateEfficiency():
計算調整效率後的剩餘電量,並回傳 double 值
調整後電量 = 電量 × (1 + 能效提升率)
charge():
記錄充電,印出充電後電量
System.out.printf("Energy after charge: " + energy + " kWh");
consume():
記錄耗電,印出耗電後電量
System.out.printf("Energy after consume: " + energy + " kWh");
若耗電量超過剩餘電量,
印出 "POWER FAILURE!",並終止程式

主程式須執行以下步驟:

import java.util.Scanner;

class PowerStation {
    double energy;
    double efficiencyRate;

    // 建構子
    PowerStation(double energy, double efficiencyRate) {
        this.energy = energy;
        this.efficiencyRate = efficiencyRate;
    }

    // 計算調整效率後的電量
    double calculateEfficiency() {

    }

    // 充電
    void charge(double amount) {


        System.out.printf("Energy after charge: %.2f kWh\n", energy);
    }

    // 耗電
    void consume(double amount) {


        System.out.printf("Energy after consume: %.2f kWh\n", energy);
    }
}

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

        double energy = sc.nextDouble();
        double efficiencyRate = sc.nextDouble();

        double charge1 = sc.nextDouble();
        double consume1 = sc.nextDouble();
        double charge2 = sc.nextDouble();
        double consume2 = sc.nextDouble();





        System.out.printf("Final energy report: %.2f kWh\n", finalEnergy);
    }
}

輸入值的格式

目前電量 能效提升率 充電1 耗電1 充電2 耗電2

輸出值的格式

電量(保留兩位小數,四捨五入)

sample input1

1000 0.2
60 900 7500 60

sample output1

Energy after charge: 1060.00 kWh
Energy after consume: 160.00 kWh
Energy after charge: 7660.00 kWh
Energy after consume: 7600.00 kWh
Final energy report: 9120.00 kWh

sample input2

500 0.1
100 700 200 50

sample output2

Energy after charge: 600.00 kWh
POWER FAILURE!

Comments

There are no comments at the moment.