Answer to Question #301050 in Java | JSP | JSF for nnn

Question #301050

Create a class named Square which performs the following tasks. a. Provide a method which returns calcuated area and circumference of the square and takes side length as one parameter of type integer. Write a test application named SquareApp which performs the following tasks. a. Create an object for the class Square. b. Read the side length of the Square from the user c. Pass the side length to the methods of the square class as an argument and print the calculated area and circumference of the square.


1
Expert's answer
2022-02-22T12:13:45-0500
import java.util.Scanner;


class Square {


	public int area(int side) {
		return side * side;
	}


	public int circumference(int side) {
		return 4 * side;
	}


}


class SquareApp  {


	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		System.out.print("Enter the side length of the Square: ");
		int side = keyBoard.nextInt();
		Square s = new Square();


		System.out.println("\nCircumference : " + s.circumference(side));
		System.out.println("Area: " + s.area(side));


		keyBoard.close();
	}
}

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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS