Convert the given class from having public data to private d
Convert the given class from having public data to private data. For each data member, create a \"Get_\" and \"Set_\" access method. For example if a class had a data member named mydata, the class would require methods named: Get_mydata and Set_mydata. Start by copy-pasting the class definition below into your editing window. You only need to write the class definition and any code that is required for that class. Place all code within the class definition. class Lamp {public: string style; char color; float wattage; int bulbs; Lamp() {style = \"Plain\"; color = \'N\'; wattage = phi; bulbs = 1;}//add access methods here};
Solution
public class Lamp { private string style; // instance variable private char color; // instance variable private float wattage; // instance variable private int bulbs; // instance variable // method to set the style in the object public void set_Style(string style) { this.style = style; // store the style } // method to retrieve the style from the object public string get_Style() { return style; // return value of style to caller } // method to set the color in the object public void set_Color(char color) { this.color = color; // store the color } // method to retrieve the color from the object public char get_Color() { return color; // return value of color to caller } // method to set the wattage in the object public void set_Wattage(float wattage) { this.wattage = wattage; // store the wattage } // method to retrieve the wattage from the object public float get_Wattage() { return wattage; // return value of wattage to caller } // method to set the bulbs in the object public void set_Bulbs(int bulbs) { this.bulbs = bulbs; // store the bulbs } // method to retrieve the bulbs from the object public int get_Bulbs() { return bulbs; // return value of bulbs to caller } } // end class Lamp