What does the following code do? The first code listing contains the declaration of class Shape. Each Shape object represents a closed shape with a number of sides (a closed shape must have three or more sides). The second code listing contains a method (mystery) declared by a client of class Shape. What does this method do?
```
1 public class Shape
2 {
3 // integer for storing number of sides
4 private int sides;
5
6 // Shape constructor, number of sides supplied
7 public Shape( int numSides )
8 {
9 setSides( numSides );
10
11 } // end constructor
12
13 // return sides value
14 public int getSides()
15 {
16 return sides;
17
18 } // end method getSides
19
20 // set sides value
21 public void setSides( int numSides )
22 {
23 if ( numSides > 2 )
24 {
25 sides = numSides;
26 }
27 else // set invalid input to 0
28 {
29 sides = 0;
30 }
31
32 } // end method setSides
33
34 } // end class Shape
```
```
1 public String mystery( Shape shape)
2 {
3 String shapeText;
4
5 // switch with number of shape’s sides
6 switch ( shape.getSides() )
7 {
8 case 3:
9 shapeText = "Triangle";
10 break;
11
12 case 4:
13 shapeText = "Quadrilateral";
14 break;
15
16 default:
17 shapeText = "Other polygon";
18
19 } // end switch
20
21 return shapeText;
22
23 } // end method mystery
```
Method mystery returns a String containing text indicating what type of shape the Shape object passed to it is. Method mystery will determine whether the Shape object is a triangle, quadrilateral or other polygon by the number of sides the Shape object has.
You might also like to view...
Digital forensics operations are often ____.
A. inhouse B. contracted C. permanent D. outsourced
What is the loopback address, and what block is reserved for loopback?
What will be an ideal response?
The horizontal margin and vertical margin settings determine how much ____ is displayed between the picture and surrounding text.
A. wrapping B. white space C. reflection D. thickness
Case-Based Critical Thinking Question ? Jenna manages the website for a local band. She is exploring responsive design to determine which aspects she might implement on the band's website. Jenna decides to change element sizes on the website to use
A. percentages B. ems C. pixels D. points