Write a class Square whose constructor receives the height of the sides. Then supply methods to compute
-the area and parameter of the square
-the length of the diagonal (use the Pythagorean theorem)
1
Expert's answer
2013-07-31T08:47:25-0400
import java.util.*; import java.lang.*;
class Square { double height; public Square(double Hscan) { height = Hscan;} public double area(double H) {return H*H;} public double perimeter(double H) {return 4*H;} public double diagonal(double H) {return H*Math.sqrt(2);} public static void main (String[] args) { System.out.println("Enter the height of a square:"); System.out.print("the height = "); Scanner scan = new Scanner(System.in); String s = scan.nextLine(); double h = Double.parseDouble(s); Square sq = new Square(h); System.out.println("An area of the square = "+sq.area(h)+" with the height = "+h); System.out.println("A perimeter of the square = "+sq.perimeter(h)+" with the height = "+h); System.out.println("A lenght of the diagonal of the square = "+sq.diagonal(h)+" with the height = "+h); } }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment