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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 25 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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply