It is necessary to create a transfer of some organizations, but the task says that the transfer must contain the name of the organization and the price of the services. As I understand it, an enumeration is a collection of unit constants. How to list the name of the organization and the price of the services?

PS I do not exclude that the task itself is not correct.

The job text as is. The amount of payment I replaced the price of services.

There must be at least one interface, an abstract class and one internal class, as well as an enumeration for organizations from which listeners came. The transfer must, in addition to the name of the organization, contain the full name of the organization and the amount of the payment.

  • Refine the text of the task. Most likely a mistake in the formulation or interpretation. - Kromster

1 answer 1

Perhaps this is what is meant

public enum Organizations { /** * Организация А */ A("Name1", BigDecimal.valueOf(100)), /** * Организация B */ B("Name2", BigDecimal.valueOf(200)), /** * Организация C */ C("Name3", BigDecimal.valueOf(300)), /** * Организация D */ D("Name4", BigDecimal.valueOf(400)), /** * Организация E */ E("Name5", BigDecimal.valueOf(500)); private Organizations(String name, BigDecimal price) { this.price = price; this.name = name; } /** * Возвращает цену услуг * * @return BigDecimal цена услуг */ public BigDecimal getPrice() { return price; } /** * Возвращает наименование * * @return String наименование */ public String getName() { return name; } private BigDecimal price; private String name; } 

In the code, then you can get both the name Organizations.A.getName() and the price Organizations.A.getPrice()

  • one
    I would recommend to write at the beginning why this is possible) of type Recording enumeration "public enum Test" is equivalent "abstract class Test extends java.lang.Enum" ... so you can write everything as in class .. bla bla bla - Aleksey Shimansky