219k views
3 votes
Create a program in java that calculates area and perimeter of a square - use a class and test program to calculate the area and perimeter; assume length of square is 7 ft.

User Aidas
by
6.1k points

1 Answer

4 votes

Answer:

Following are the program in Java

class abc // class abc

{

public void area(int s) // function area

{

s=s*s;// calculate area

System.out.println(" The area is:" +s + " ft"); // display the area

}

public void perimeter(int s) //function perimeter

{

s=4*s;//calculate perimeter.

System.out.println(" The perimeter is:" +s + " ft"); //display the perimeter

}

}

public class Main //class main

{

public static void main(String[] args) // main function

{

abc ob=new abc(); // creating instance of class abc

ob.area(7); // calling function area

ob.perimeter(7); // calling function perimeter

}

}

Output:

The area is: 49 ft

The perimeter is:28 ft

Step-by-step explanation:

In this program we create the class "abc" .We declared two function in the class "abc" i.e "area" and "perimeter" which is calculating the area and perimeter of a square and print them , from the main function we create a object of class "abc" i.e "ob" which called the function area and perimeter .

User Meiling
by
5.7k points