12.07.2015 Views

k19-k11-orientacao-a.. - Departamento de Sistemas e Computação

k19-k11-orientacao-a.. - Departamento de Sistemas e Computação

k19-k11-orientacao-a.. - Departamento de Sistemas e Computação

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

91 HERANÇA4 Teste o funcionamento dos três tipos <strong>de</strong> funcionários criando um objeto <strong>de</strong> cada uma das classes:Gerente, Telefonista e Secretaria.1 class TestaFuncionarios {2 public static void main ( String [] args ) {3 Gerente g = new Gerente ();4 g. setNome (" Rafael Cosentino ");5 g. setSalario (2000) ;6 g. setUsuario (" rafael . cosentino ");7 g. setSenha (" 12345 ");89 Telefonista t = new Telefonista ();10 t. setNome (" Carolina Mello ");11 t. setSalario (1000) ;12 t. setEstacaoDeTrabalho (13) ;1314 Secretaria s = new Secretaria ();15 s. setNome (" Tatiane Andra<strong>de</strong> ");16 s. setSalario (1500) ;17 s. setRamal (198) ;1819 System . out . println (" GERENTE ");20 System . out . println (" Nome : " + g. getNome ());21 System . out . println (" Salário : " + g. getSalario ());22 System . out . println (" Usuário : " + g. getUsuario ());23 System . out . println (" Senha : " + g. getSenha ());2425 System . out . println (" TELEFONISTA ");26 System . out . println (" Nome : " + t. getNome ());27 System . out . println (" Salário : " + t. getSalario ());28 System . out . println (" Estacao <strong>de</strong> trabalho : " + t. getEstacaoDeTrabalho ());2930 System . out . println (" SECRETARIA ");31 System . out . println (" Nome : " + s. getNome ());32 System . out . println (" Salário : " + s. getSalario ());33 System . out . println (" Ramal : " + s. getRamal ());34 }35 }Código Java 8.24: TestaFuncionarios.javaExecute o teste!5 Suponha que todos os funcionários recebam uma bonificação <strong>de</strong> 10% do salário. Acrescente ummétodo na classe Funcionario para calcular essa bonificação.1 class Funcionario {2 private String nome ;3 private double salario ;45 public double calculaBonificacao () {6 return this . salario * 0.1;7 }89 // GETTERS AND SETTERS10 }Código Java 8.25: Funcionario.java6 Altere a classe TestaFuncionarios para imprimir a bonificação <strong>de</strong> cada funcionário, além dosdados que já foram impressos. Depois, execute o teste novamente.1 class TestaFuncionarios {2 public static void main ( String [] args ) {3 Gerente g = new Gerente ();www.<strong>k19</strong>.com.br 91

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!