Question: For this question you must write a java class called Square and a client class called SquareClient. The partial Square class is given below. (For
For this question you must write a java class called Square and a client class called SquareClient. The partial Square class is given below. (For this assignment, you will have to submit 2 .java files: one for the Square class and the other one for the SquareClient class.)
// A Square stores an (x, y) coordinate of its top/left corner, and a length of its side.
public class Square {
private int x;
private int y;
private int sideLength;
// constructs a new Square with the given inX, inY and inSideLength public Rectangle(int inX, int inY, int inSideLength)
// returns the fields' values public int getX()
public int getY()
public int getSideLength()
// returns a string such as Coordinate is (1,2) and dimension is 7x7 where 7 is the length of the side.
public String toString()
... }
Write an instance method called area that will be placed inside the Square class. The method returns the square of the rectangle.
Write another instance method called changeSize that will be placed inside the Square class. This method changes the length of the side. The method accepts
newSideLength as parameter and changes the value of sideLength to this new length.
Write the client class SquareClient that creates an object of class Square and initializes its x coordinate, y coordinates and side length to 11, 12, and 34 respectively. Print out the x- coordinate, y-coordinate, side length (using toString method), and area of this square. Then change the side length to 68 and then print out the x- coordinate, y-coordinate, side length and area again.
When you execute the SquareClient file you result should look like:
Coordinate is (11,12) and dimension is 34x34
Area is 1156
Coordinate is (11,12) and dimension is 68x68
Area after the size is changed is 4624
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
