SHARE
TWEET

Untitled

a guest Oct 21st, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Main.java
  2.  
  3. package com.company;
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class Main {
  8.  
  9.     public static void main(String[] args)
  10.     {
  11.         Scanner input = new Scanner(System.in);
  12.         double a , b , c ;
  13.  
  14.         a = input.nextDouble();
  15.         b = input.nextDouble();
  16.         c = input.nextDouble();
  17.  
  18.         Triangle triangle1 = new Triangle();
  19.  
  20.         triangle1.setDimention(a,b,c);
  21.  
  22.         if (triangle1.do_exist(a,b,c))
  23.         {
  24.             System.out.println(triangle1.area());
  25.         }
  26.         else
  27.         {
  28.             System.out.println("No such triangle!");
  29.         }
  30.  
  31.     }
  32. }
  33.  
  34.  
  35. Triangle class
  36.  
  37. package com.company;
  38. import  java.lang.*;
  39.  
  40. public class Triangle {
  41.  
  42.     double _a = 0,_b = 0,_c = 0;
  43.  
  44.     boolean do_exist(double a, double b, double c)
  45.     {
  46.         boolean result  = a + b > c;
  47.  
  48.         result &= a + c > b;
  49.         result &= b + c > a;
  50.  
  51.         if( result )
  52.         {
  53.             return true;
  54.         }
  55.         else
  56.         {
  57.             return false;
  58.         }
  59.     }
  60.  
  61.     void setDimention(double a, double b, double c)
  62.     {
  63.         _a = a;
  64.         _b = b;
  65.         _c = c;
  66.     }
  67.  
  68.     double peremeter()
  69.     {
  70.         double peremeter = _a + _b + _c;
  71.  
  72.         return peremeter;
  73.     }
  74.  
  75.     double halfPeremeter()
  76.     {
  77.         double half_peremeter = peremeter() / 2;
  78.  
  79.         return half_peremeter;
  80.     }
  81.  
  82.     double area()
  83.     {
  84.         double p = halfPeremeter();
  85.         double area = Math.sqrt(p * (p - _a) * (p - _b) * (p - _c));
  86.  
  87.         return area;
  88.     }
  89. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top