Page 1 of 1

Based on the following description, design a class named Square to represent a square. • One field width that specifies

Posted: Fri Apr 29, 2022 7:12 am
by answerhappygod
Based On The Following Description Design A Class Named Square To Represent A Square One Field Width That Specifies 1
Based On The Following Description Design A Class Named Square To Represent A Square One Field Width That Specifies 1 (59.86 KiB) Viewed 27 times
CODE CAN NOT BE MODIFIED. CAN ONLY ADD NEW CODE
Based on the following description, design a class named Square to represent a square. • One field width that specifies the width of the square. • A default constructor that creates a default square. The default value is 1 for the width. • A constructor that creates a square with the specified width. • A method named getArea() that returns the area of this square. • A method named getPerimeter() that returns the perimeter of the square. Sample run Input: 238 Output: 4.0 8.0 9.0 12.0 64.0 32.
1 import java.util.Scanner; 2 2 3. public class Test { 4 5 public static void main(String[] args) { Scanner stdin = new Scanner(System.in); while (stdin.hasNextDouble() { Square sq = new Square(stdin.nextDouble()); 10 System.out.println(sq.getArea(); System.out.println(sq.getPerimeter()); ) } } // your code starts here Nm N 000 6 7 8 9 11 12 13 14 15 16 17 // your code ends here