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
  • 179,855
  • 19
  • 132
  • 245

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,261
  • 2
  • 17
  • 35
  • 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
  • 11,381
  • 3
  • 45
  • 46