Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. /*
  2.  * Exemplo em Java
  3.  */
  4.  
  5.  ...
  6.  
  7.  public class Exercicio {
  8.     public static void main (String[] args) {
  9.         Aluno aluno = new Aluno("João pedro", 9.3, 9.3, 9.3);
  10.         ...
  11.     }
  12. }
  13.  
  14. class Aluno {
  15.     private String nome;
  16.     private float[] notas = new float[3];
  17.     private float media;
  18.    
  19.     public Aluno (String nome, float nota1, float nota2, float nota3) {
  20.         this.nome = nome;
  21.         this.notas[0] = nota1;
  22.         this.notas[1] = nota2;
  23.         this.notas[2] = nota3;
  24.         this.media = (nota1 + nota2 + nota3)/3;
  25.     }
  26.    
  27.     /* o mesmo de C++, procure como fazer getters em classes Java */
  28. }
  29.  
  30. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement