Java Saved Program: fragrant-rain

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;

class Script
{
	public  static void main (String[] args){
	    Triangle t1 = new Triangle(4.0,7.0,5.0);
	    Triangle t2 = new Triangle(1.0, 4.0, 4.0);
	    Triangle t3 = new Triangle(3.0,4.0,5.0);
        Triangle t4 = new Triangle(1.0,2.0,3.0);
	    
	    System.out.println(t1.isTriangle());
	    System.out.println(t3.circumference());
	    System.out.println(t3.area());
	    System.out.println(t3.isRectangular());
	    System.out.println(t2.isRectangular());
	    System.out.println(t4.isRectangular());
	    
	   }

	}
	
class Triangle{
    private double mA, mB, mC;
    
    
    public Triangle(){
        this.mA = this.mB = this.mC = 1.0;// katete ne mogu biti postavljene na 0, zbog pravila "trokuta".
    }
    
    public Triangle(double a, double b, double c){
        this.mA = a;
        this.mB = b;
        this.mC = c;
    }
    
    public double circumference(){//opseg.
    return this.mA + this.mB + this.mC;
        
    }
    
    
    //korištena je Heronova formula(povrsina)
    public double area(){
        double s =this.circumference() / 2;
        double temp = s * (s - this.mA) * (s - this.mB) * (s - this.mC);
        double area = Math.sqrt(temp);
        return area;
    } 
    
    public boolean isRectangular(){//provjera je li pravokutan
                                                    
        if(this.checkPyhagorea(this.mA, this.mB, this.mC) ||
           this.checkPyhagorea(this.mB, this.mA, this.mC) ||
           this.checkPyhagorea(this.mC, this.mA, this.mB))
           {
                return true;
                
            }
                       
                return false;
            
    }
    
    private boolean checkPyhagorea(double a, double b, double c){
        return a*a == b*b + c*c;
                 
        
    }
    
    public boolean isTriangle(){//je li trokut ili neko drugo tijelo.
        if(this.mA + this.mB <= this.mC ||
           this.mA + this.mC <= this.mB ||
           this.mC + this.mB <= this.mA){
               return false;
               
           }
           return true;
               do{
                   System.out.println("Trokut sa stranicama mA, mB, mC nije moguc.");
               }
               while(this.mA + this.mB <= this.mC ||
                     this.mA + this.mC <= this.mB ||
                     this.mC + this.mB <= this.mA);
           
               
     }      
    }

class GeoIznimka{
    private double mA, mB, mC;{
        
    }
    
}


       
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs