Answer to Question #174842 in Java | JSP | JSF for Prisy

Question #174842

a. Write a Java program to compute the area of a polygon.

Area of a polygon = (n*s^2)/(4*tan(π/n))

where n is n-sided polygon and s is the length of a side

Input Data:

Input the number of sides on the polygon: 7

Input the length of one of the sides: 6

b. Explain each of the following Java programming terms

i. extended [1]

ii. protected [1]

iii. instanceOf [1]

iv. abstract [1]

v. Write a Java program to print the contents of a two-dimensional Boolean array where t will represent true and f will represent false.


1
Expert's answer
2021-03-23T18:18:46-0400
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Input the number of sides on the polygon: ");
        int n = in.nextInt();
        System.out.print("Input the length of one of the sides: ");
        int s = in.nextInt();
        System.out.println("Area of a polygon = " + (n * s * s) / (4 * Math.tan(Math.PI / n)));
    }
}


1 It means that the class inherited the functionality of the parent class and extended it with its own functionality.

2. One of the types of encapsulation means that a method or variable can be used either by inherited classes or by classes located in the same package.

3. Checks if an object is an object of some class.

4. The abstract keyword in the class name means that the class contains methods that must be implemented in the inherited class, you cannot create an object of such a class. If the method signature contains the abstract keyword, it means that such a method must be implemented in the inherited class.


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        boolean[][] arr = {{true, false, true}, {false, true, false}, {true, false, true}};
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] ? "t " : "f ");
            }
            System.out.println();
        }
    }
}





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