Advertisement
IvanKrastev

Homework Java Syntax Problem 9 Point Insde the House

Jan 26th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class Problem_9_PointsInsideTheHouse {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner scanner= new Scanner(System.in);
  8.        
  9.         double aX= 12.5;
  10.        
  11.        
  12.         double aY= 8.5;
  13.        
  14.    
  15.         double bX= 22.5;
  16.        
  17.        
  18.         double bY= 8.5;
  19.        
  20.        
  21.         double cX= 17.5;
  22.        
  23.        
  24.         double cY= 3.5;
  25.        
  26.         System.out.print("Ox= ");
  27.         double oX= scanner.nextDouble();
  28.        
  29.         System.out.print("Oy= ");
  30.         double oY= scanner.nextDouble();
  31.         double area= Math.abs(((aX * ((bY - cY))) + (bX * ((cY - aY))) + (cX * ((aY - bY)))) / 2);
  32.         // If the point is in the triangle it is possible to create 3 sub triangles. The sum of their areas is equal to area of the greater triangle.
  33.         double area1= Math.abs(((aX * ((bY - oY))) + (bX * ((oY - aY))) + (oX * ((aY - bY)))) / 2);
  34.         double area2= Math.abs(((aX * ((oY - cY))) + (oX * ((cY - aY))) + (cX * ((aY - oY)))) / 2);
  35.         double area3= Math.abs(((oX * ((bY - cY))) + (bX * ((cY - oY))) + (cX * ((oY - bY)))) / 2);
  36.         double sumAreas= area1 + area2 + area3;
  37.        
  38.         if (sumAreas == area) {
  39.             System.out.print("Inside");
  40.         }
  41.         else {
  42.             if (oX >= 12.5 && oX <= 17.5 && oY >= 8.5 && oY <= 13.5) {
  43.             System.out.print("Inside");
  44.             }
  45.             else {
  46.                 if (oX >= 20 && oX <= 22.5 && oY >= 8.5 && oY <= 13.5) {
  47.                     System.out.print("Inside");
  48.                     }
  49.                 else {
  50.                     System.out.print("Outside");
  51.                 }
  52.            
  53.         }
  54.        
  55.            
  56.         }
  57.  
  58.     }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement