Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CPSC1012 Quiz 1- Fall 2018 Term Complete Program Question (5 marks) 12. Code a c

ID: 3751632 • Letter: C

Question

CPSC1012 Quiz 1- Fall 2018 Term Complete Program Question (5 marks) 12. Code a complete main program that will prompt the user to input the height (h) two parallel sides (a given below. The area is then displayed as shown in the following samp and lengths of the and b) of a trapezoid. The program then calculates the area using the formula le runs. (a + b) Area = Sample run #2 Sample run #1 Trapezoid Area Calculator Enter height: 2 Enter length of first parallel side: 3 Enter length of second parallel side: 4 The area of the trapezoid is 7 Trapezoid Area Calculator Enter height: 5.25 Enter length of first parallel side: 3.5 Enter length of second parallel side: 6.5 The area of the trapezoid is 26.25 static void Main(string[] args)

Explanation / Answer

import java.util.Scanner;

class Main {

public static void main(String[] args) {

// declaring variables

double a, b, h;

Scanner sc = new Scanner(System.in);

// taking user input

System.out.println("Trapezoid Area Calculator");

System.out.print("Enter height: ");

h = sc.nextDouble();

System.out.print("Enter length of first parallel side: ");

a = sc.nextDouble();

System.out.print("Enter length of second parallel side: ");

b = sc.nextDouble();

// calculating and printing output

double area = (a + b) * h / 2.0;

System.out.print("The area of the trapezoid is " + area);

}

}

/*SAMPLE OUTPUT

Trapezoid Area Calculator

Enter height: 5.25

Enter length of first parallel side: 3.5

Enter length of second parallel side: 6.5

The area of the trapezoid is 26.25

Trapezoid Area Calculator

Enter height: 2

Enter length of first parallel side: 3

Enter length of second parallel side: 4

The area of the trapezoid is 7.0

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote