Skip to content
Advertisement

I have an enum, but i dont know how can I use correctly?

I searched so long for what enums are useful. In my Opinion there are Variables with many keywords. So have to programming a program what Is used to manage a bank. My Enum has 2 Variables EINZAHLUNG(Deposit) and AUSZAHLUNG(Payout).

JavaScript

So I have an class Menue which is provide to call the Methods. The menue would be chosen by an UserInput.

JavaScript

The method geldEinzahlen() Pays the desired amount to the account. EINZAHLUNG. This would be change the ArrayList, but first I want to know why I should use enum.

JavaScript

The method geldAbheben() is used to pay a fee from the account. The account cant be under 0€. This would be change the ArrayList, but first I want to know why I should use enum.

JavaScript

I have csv.file but I think that is it not so important.

So the teacher wants that I use a enum but in my Opinion it is really useless. I want to ask the community of Stack Overflow. What can I write for example that I have usage of enums.

Advertisement

Answer

It seems that you are missing the great point of enums. Enum can contain implementation, so using enum avoids any need of writing switch/case structure at all.

Let me give you and example. Please excuse me, but I am going to use English in names of identifiers.

JavaScript

Now it is very easy to use this code:

JavaScript

Where transactionName and amount can be parameters.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement