Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Author: Leon Beilis
- * Desription: receive two Trapezoid base points and return Trapezoid Perimeter and area
- * minus values support also..
- */
- import java.util.Scanner;
- public class Trapezoid {
- public static void main() {
- //first base
- int firstBaseFirstPointX, firstBaseFirstPointY, firstBaseLength, firstBaseSecondPointX, firstBaseSecondPointY;
- //second base
- int secondBaseFirstPointX, secondBaseFirstPointY, secondBaseLength, secondBaseSecondPointX, secondBaseSecondPointY;
- // trapezoid properties
- int trapezoidHeight;
- double trapezoidBaseSum, trapezoidPerimeterSum;
- //initilize scanner
- Scanner scan = new Scanner(System.in);
- System.out.println("Please enter the first base point and its length to the next points on the x axis");
- System.out.println("by this format: (x1,y1,length on the x axis)");
- System.out.println("for example: \"1 1 5\"");
- firstBaseFirstPointX = Math.abs(scan.nextInt()); // x of a
- firstBaseFirstPointY = firstBaseSecondPointY = Math.abs(scan.nextInt()); // y of a and b
- firstBaseLength = scan.nextInt(); // length on the x axis to the next point (b)
- firstBaseSecondPointX = firstBaseFirstPointX + firstBaseLength; // x of b
- System.out.println("Please enter the second base point and its length to the next points on the x axis");
- secondBaseFirstPointX = Math.abs(scan.nextInt()); // x of c
- secondBaseFirstPointY = secondBaseSecondPointY = Math.abs(scan.nextInt()); // y of c and d
- secondBaseLength = scan.nextInt(); // length on the x axis to the next point (d)
- secondBaseSecondPointX = secondBaseFirstPointX + secondBaseLength; // x of d
- trapezoidHeight = Math.abs(firstBaseFirstPointY - secondBaseFirstPointY);
- trapezoidBaseSum = ( (firstBaseLength + secondBaseLength) * trapezoidHeight ) / 2.0;
- System.out.println("The area of the trapezoid is " + trapezoidBaseSum );
- trapezoidPerimeterSum = firstBaseLength + Math.sqrt( Math.pow( firstBaseSecondPointX - secondBaseSecondPointX ,2) + Math.pow( firstBaseSecondPointY - secondBaseSecondPointY ,2) ) + secondBaseLength + Math.sqrt( Math.pow( secondBaseFirstPointX - firstBaseFirstPointX ,2) + Math.pow( secondBaseFirstPointY - firstBaseFirstPointY ,2) );
- System.out.println("The perimeter of the trapezoid is " + trapezoidPerimeterSum);
- /**
- * Debug zone
- */
- // System.out.println("A point: (" + firstBaseFirstPointX + "," + firstBaseFirstPointY + ")");
- // System.out.println("B point: (" + firstBaseSecondPointX + "," + firstBaseSecondPointY + ")");
- // System.out.println("Length between A to B is: " + firstBaseLength);
- // System.out.println("C point: (" + secondBaseFirstPointX + "," + secondBaseFirstPointY + ")");
- // System.out.println("D point: (" + secondBaseSecondPointX + "," + secondBaseSecondPointY + ")");
- // System.out.println("Length between C to D is: " + secondBaseLength);
- // System.out.println("trapezoidHeight is: " + trapezoidHeight);
- // System.out.println("Base sum is: " + trapezoidBaseSum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement