0

Here my code

public static String modele;
   
   public static String supplier;
   
   public static int height = 180;

   public static final String[] COLORS = { "RED", "BLUE", "GOLD",
         "ORANGE", "PURPLE", "PINK", "NONE" };
        
    public static String description;
    
    public static boolean withSnow = false;
    
    public static boolean sale = false;
    
    public static int numIdentification;

    //constructor

    public Tree (String modele, String supplier, String description, int height, int typeColors, boolean sale, boolean withSnow){

        //////////////////////////////////////
        // a completer selon les directives //
        //////////////////////////////////////
        this.modele = modele;
        this.supplier = fournisseur;
        this.description = description;
        this.height = hauteur;
        this.sale = sale;
        this.withSnow = withSnow;
        numIdentification = numIdentification + 1; 



    }

Here my question

when i created my Tree with this constructor

let say i created my object i pass those values

Tree("tree1","supplier1","firstDescrip",190,2,true,true);

the variable typeColors in my constructor i assign number 2

how i determined that 2 = "BLUE" in my array name COLORS when i create the object.

I want to call it with a function Tree.getColors to get the value.

I just can't figured out how.... any help would be appreciated.

Sorry if my english its not good.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by JamesCherrill
0

i think i found a solution myself

i create another variable naming modeleColors

and when creating object

i assign modeleColors = COLORS[typeColors];

not sure if the right way to do it.

Edited by DarkVision: n/a

0

Bonjour. C'est bon, mais vous avez vos variables "static", c'est a dire que il-y-a une value pour tous les instances. Mauvais idée.
Votre vache espagnole
J

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.