PROGRAMMING:Square class
Define a square class, including writing content in the subclass: < br / >
Define the class main, and in the main method,
1. first, create the square object S1, then output the affirmative value of edge through getEdge () method, then call getArea method to find out the area of S1 and output
.
2. create the square object S2, and enter the affirmative value of the S2 object through the keyboard, then output the value of edge through getEdge () method, then call the getArea method to get the area of S1 and output
.
###Input format:
Enter the value that gives the edge in one row.
###Output format:
Output the edge of S1 object and the area of S1 object
Output the edge of S2 object and the area of S2 object
###Input example:
Here is a set of inputs. For example:
```in
three
```
```in
-5
```
###Output example:
The corresponding output is given here. For example:
```out
this is constructor method
s1:edge=2
s1:area=4
this is constructor method
s2:edge=3
s2:area=9
```
```out
this is constructor method
s1:edge=2
s1:area=4
this is constructor method
s2:edge=1
s2:area=1
```
answer:If there is no answer, please comment
- Define the member variable side length private int edge; li>
- Definition method: including construction method, setter getter method, area calculation method, etc. the requirements are as follows:
- Define the construction method of the square class: in the construction method, assign edge to 2, and add system. Out. Println ("this is constructor method") li>
- Set the set method for the member variable edge to receive the value given by the user. If the value given by the user is < = 0, set the edge value to 1
- Set the get method for the member variable edge to return the value of edge
- Complete the area method to get the square area: public int getarea ()
- Define the construction method of the square class: in the construction method, assign edge to 2, and add system. Out. Println ("this is constructor method") li>
Define the class main, and in the main method,
1. first, create the square object S1, then output the affirmative value of edge through getEdge () method, then call getArea method to find out the area of S1 and output
.
2. create the square object S2, and enter the affirmative value of the S2 object through the keyboard, then output the value of edge through getEdge () method, then call the getArea method to get the area of S1 and output
.
###Input format:
Enter the value that gives the edge in one row.
###Output format:
Output the edge of S1 object and the area of S1 object
Output the edge of S2 object and the area of S2 object
###Input example:
Here is a set of inputs. For example:
```in
three
```
```in
-5
```
###Output example:
The corresponding output is given here. For example:
```out
this is constructor method
s1:edge=2
s1:area=4
this is constructor method
s2:edge=3
s2:area=9
```
```out
this is constructor method
s1:edge=2
s1:area=4
this is constructor method
s2:edge=1
s2:area=1
```
answer:If there is no answer, please comment