Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Make a program that uses the OOP\'s method. The program should make a call of th

ID: 3796232 • Letter: M

Question

Make a program that uses the OOP's method.

The program should make a call of the Button class with the following private attributes:

String text
Int width
Height int
Int locationX
Int locationY
It should also have constructors: default and parameter, public methods (member functions): get and set for the text attribute (suggestion for getText names, setText, follow the "naming convention" found in the area). (Note: There are no individual setters of width, height, location X and locationY)

You must have a setter called setLocation that will get two parameters, the serious void header setLocation (int x, int y). Also make another setter called setSize that will receive two parameters, the serious void header setSize (int width, int height).

After doing the class, the program must instantiate the objects and the program must ask all the attributes for each object and save it using its corresponding method. Then the program must clear the screen and print the values of each attribute.

Explanation / Answer

public class Demo{

public static void main(String []args){
Button btn = new Button();
//Ask for text and set it using setText
btn.setText("new button");
  
//Ask for location and set it using setLocation
btn.setLocation(10,20);
  
//Ask for size and set it using setSize
btn.setSize(100,60);
  
//Display all the attributes using displayAttribute method.
btn.displayAttributes();
}
}

################################################################################

public class Button {
//Private attributes
private String text;
private int width;
private int height;
private int locationX;
private int locationY;
  
//Default constructor
public Button() {};
  
//Getter for Text
public String getText() {
return text;
}
  
//Setter for text
public void setText(String value) {
text = value;
}
  
//Setter for location
public void setLocation(int x, int y) {
locationX= x;
locationY = y;
}
  
//Setter for size
public void setSize(int h, int w) {
height = h;
width = w;
}
  
public void displayAttributes() {
System.out.println("Text: " + text);
System.out.println("height: " + Integer.toString(height));
System.out.println("width: " + Integer.toString(width));
System.out.println("locationX: " + Integer.toString(locationX));
System.out.println("locationY: " + Integer.toString(locationY));
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote