Baixe o app para aproveitar ainda mais
Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original
Circulo.java /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package circunferencia; /** * * @author joao */ public class Circulo { private double raio; private double perimetro; private double area; public Circulo() { this.raio = 0;this.perimetro = 0;this.area = 0; } public Circulo(double raio) { this.raio = raio; this.perimetro = 0; this.area = 0; } public double getPerimetro() { this.perimetro = (raio != 0) ? 2 * Math.PI * raio : perimetro; return perimetro; } public double getArea() { this.area = (raio != 0) ? 2 * Math.PI * Math.pow(raio, 2) : area; return area; } public double getRaio() { return raio; } public void setRaio(double raio) { this.raio = raio; } public double getApotema() { return (raio != 0) ? this.raio / 2 : 0; } public double getAreaTrianguloEquilateroInscrito() { return (raio != 0) ? ((3 * Math.pow(raio, 2) * Math.sqrt(3)) / 4) : 0; } @Override public String toString() { return ("Raio:[" + this.raio + " Perimetro:[" + this.getPerimetro() + "] Area:[" + this.getArea() + "] Area trinagulo Inscrito:[" + this.getAreaTrianguloEquilateroInscrito() + "]"); } } Circunferencia.java /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package circunferencia; /** * * @author joao */ public class Circunferencia { /** * @param args the command line arguments */ public static void main(String[] args) { Circulo circulo; for (int i = 0; i < 100; i++) { circulo = new Circulo((int) (Math.random() * i)); System.out.println(circulo.toString()); } } }
Compartilhar