System of units

Report a typo

You are given an enum SI with three constants. Each constant stores a string field with its quantity name:

enum SI {

    M("length"),
    KG("mass"),
    S("time");

    public final String quantityName;

    SI(String quantityName) {
        this.quantityName = quantityName;
    }
}

Declare the instance method getQuantityName that returns the quantity name of the constant.

Write a program in Java 17
enum SI {

M("length"),
KG("mass"),
S("time");

public final String quantityName;

SI(String quantityName) {
this.quantityName = quantityName;
}

// implement getQuantityName() method here

}
___

Create a free account to access the full topic