Created
September 5, 2013 04:39
-
-
Save fabioluciano/6446180 to your computer and use it in GitHub Desktop.
Códigos da Aula 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Circulo implements Figura2D { | |
private double raio; | |
public Circulo(double raio) { | |
this.raio = raio; | |
} | |
public double getRaio() { | |
return this.raio; | |
} | |
public double getArea() { | |
return Figura2D.PI * (this.getRaio() * this.getRaio()); | |
} | |
public double getPerimetro() { | |
return 2 * Figura2D.PI * this.getRaio(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Esfera extends Circulo implements Figura3D { | |
public Esfera(double raio) { | |
super(raio); | |
} | |
public double getArea() { | |
return 4 * super.getArea(); | |
} | |
public double getVolume() { | |
return (4 * Figura3D.PI * this.getRaio() * this.getRaio() * this.getRaio()) / 3; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Figura2D { | |
double PI = 3.1415; | |
double getArea(); | |
double getPerimetro(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Figura3D extends Figura2D { | |
double getVolume(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Funcionario extends Pessoa { | |
private double salario; | |
public double getSalario() { | |
return this.salario; | |
} | |
public Funcionario(String nome) { | |
super(nome); | |
} | |
public String toString() { | |
return this.getClass().getSimpleName() + "(" + this.getNome() + ")"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class Pessoa extends Object { | |
private String nome; | |
public String getNome() { | |
return this.nome; | |
} | |
public Pessoa(String nome) { | |
this.nome = nome; | |
} | |
public abstract String toString(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestaClasseAbstrataFuncionario extends Object { | |
public static void main(String[] args) { | |
Pessoa pessoa = new Funcionario("Maria"); | |
System.out.println(pessoa.getNome()); | |
if( pessoa instanceof Pessoa) { | |
System.out.println("Funcionario é instancia de Pessoa"); | |
} | |
System.out.println(pessoa); | |
Funcionario funcionario = new Funcionario("João"); | |
System.out.println(funcionario); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestaInterface { | |
public static void main(String[] args) { | |
Figura2D circulo = new Circulo(10); | |
System.out.println("Área do círculo: " + circulo.getArea()); | |
System.out.println("Perímetro do círculo: " + circulo.getPerimetro()); | |
System.out.println("--------"); | |
Figura3D esfera = new Esfera(10); | |
System.out.println("Área do círculo: " + esfera.getArea()); | |
System.out.println("Perímetro do círculo: " + esfera.getPerimetro()); | |
System.out.println("Volume do círculo: " + esfera.getVolume()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment