63 193
Assignments Done
99,3%
Successfully Done
In July 2018

Answer to Question #33518 in Java | JSP | JSF for Jimbo

Question #33518
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)
Expert's answer
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);
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions