Ask Question

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.

+2
Answers (1)
  1. 29 January, 14:45
    0
    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

    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “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; ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers