Getters, Setters and Constructors in Java - Making a car and stocking it <p>I'm trying to create a class in Java using BlueJ. My class is named Automobile. My goal is to be able to use my Constructor method to create cars with the variables: year, color, brand, number of doors, number of kilometers, if it's automatic (boolean), if it's sold (boolean), a description, and an identification number. All the variables have a set default value, a minimum and a maximum accepted value.</p> <p>I have to use getVariablename and setVariablename for my methods. My color and brand variables are int, and I made methods to retrieve their String counterparts in a table in my class. </p> <p>My issue is I don't understand the principle of setting my variable in one method and getting it in another (while making sure it's an accepted value). Also, once I have my Setter and Getter method, what do I have to write down in the creation of my Constructor method?</p> <p>Up to now, I have this :</p> <pre><code>public class Automobile { private static final String[] COLORS = { "Other", "Noir", "Blanc", "Bleu Nuit", "Bleu Clair", "Vert Pomme", "Vert Bouteille", "Taupe", "Argent", "Sable"}; private static final String[] BRANDS = { "Autre", "Mazda", "Toyota", "Ford", "GM", "Hyunday", "BMW", "SAAB", "Honda"}; public static final int COLOR_DEF = 8; public static final int COLOR_MIN = 0; public static final int COLOR_MAX = COULEURS.length - 1; public static final int BRAND_DEF = 4; public static final int BRAND_MIN = 0; public static final int BRAND_MAX = MARQUES.length - 1; public static final double KILO_DEFAULT = 55000; public static final double KILO_MIN = 15000; public static final double KILO_MAX = 140000; public static final int TWO_DOORS = 2; public static final int FOUR_DOORS = 4; public static final int DOORS_DEFAULT = FOUR_DOORS; public static final boolean AUTO_DEF = true; public static final int YEAR_MIN = 1997; public static final int YEAR_MAX = 2016; public static final int YEAR_DEFAUT = 2007; public static final String COMM_DEFAUT = ""; public static String color (int cou) { String chainecolor = ""; if (cou &gt;= COLOR_MIN &amp;&amp; cou &lt;= COLOR_MAX) { chainecolor = COLORS[cou]; } return chainecolor; } //This method is to return the String value of a color from its int value using the COLORS table. If invalid it returns an empty chain. public static String brand (int br) { String chainebrand = ""; if (ma &gt;= BRAND_MIN &amp;&amp; ma &lt;= BRAND_MAX) { chainebrand = BRANDS[br]; } return chainebrand; } //same thing for the brand public Automobile (int brand, int year, int color, boolean automatic, double kilometers,int nbrDoors, String description, boolean sold){ //To be completed } //here i'm supposed to create getters that return int values for everything but automatic, sold and description public void setYear ( int year ) { if (year &gt;= YEAR_MIN &amp;&amp; YEAR &lt;= YEAR_MAX) { year = year; } } // supposed to be the setter for my year, as long as it's within the accepted values public void setMarque (int brand){ if (brand &gt;= BRAND_MIN &amp;&amp; brand &lt;= BRAND_MAX) { brand = brand; } } //same, for the brand public void setColor (int color) { if (color &gt;= COLOR_MIN &amp;&amp; color &lt;= COLOR_MAX){ color = color; } }// same for the color public void setNbrDoors (int p) { if (p == TWO_DOORS || p == FOUR_DOORS){ p = p; } } // same for the door. I am forced to use (int p) as the variable for this method, which confuses me as to how I will refer to it from nbrDoors up in the Automobile constructor method } // Automobile </code></pre> <p>So my difficulties lie in: </p> <ul> <li><p>Are the examples of setters that I made valid for this purpose? I do not understand the need for p = p, or color = color...</p></li> <li><p>How do I create a getter method that will be able to go pick up the Variable p from setNbrDoors, return its value and have it be used for nbrDoors in the Automobile constructor?</p></li> <li><p>What am I supposed to write in the Constructor method, such as it will be able to get its values from the getters?</p></li> </ul> <p>This is all because the second part is I will have to create a little code to ask the user to input all the values for variables, then create a table to stock the Cars the user creates.</p> <p>P.S.: the work is originally in french, so I translated the variable and method names best I could for your better understanding. Also, the variable names, methods, etc are all imposed, I am FORCED to make the class this way exactly.</p> <p>EDIT: As such, the use of static for brand and color conversion are also imposed. Those 2 methods are solely for returning a String of character from an int value. they are not used in the Constructor. Finally, the exceptions will be handled in the second part of the work using a separate validation loop. The Automobile class is really used solely to handle the creation of the "car" object.</p>