0

I need make an objet (client) with this variables:

  • Name
  • Date
  • Age
  • Phone
  • Type

But Type can only take 3 values: Good, Fair, Poor.

How you declare the variable type?

OneCricketeer
  • 151,199
  • 17
  • 111
  • 216

2 Answers2

2

You can define it as an enum to restrict the possible values to a small set:

enum Type {
    Good,
    Fair,
    Poor
}

And see this answer for more background.

Community
  • 1
  • 1
drhr
  • 2,233
  • 2
  • 17
  • 34
  • This can help too: [Stack Overflow documentation for Enums](http://stackoverflow.com/documentation/java/155/enums#t=201610301920168839009) – RaminS Oct 30 '16 at 19:21
1

Create an enumeration:

public enum Type {
    GOOD, FAIR, POOR 
}

Then you can declare Type type;.

pzaenger
  • 9,417
  • 3
  • 39
  • 44