fork(2) download
  1. class HelloWorld {
  2. public static void main (String[] args) {
  3. Aluno aluno = new Aluno("joao", 1, 8f, 6f);
  4. aluno.exibir();
  5. }
  6. }
  7.  
  8. class Aluno {
  9. private String nome;
  10. private int matricula;
  11. private float n1, n2;
  12.  
  13. public Aluno(String nome, int matricula, float n1, float n2) {
  14. this.nome = nome;
  15. this.matricula = matricula;
  16. this.n1 = n1;
  17. this.n2 = n2;
  18. }
  19.  
  20. public float media() {
  21. return (n1 + n2) / 2;
  22. }
  23.  
  24. public void exibir() {
  25. System.out.println("Nome:" +nome);
  26. System.out.println("Matrícula:" + matricula);
  27. System.out.println("Nota 1:" + n1);
  28. System.out.println("Nota 2:" + n2);
  29. System.out.println("A média é:" + media());
  30. }
  31. }
  32.  
  33. //https://pt.stackoverflow.com/q/204494/101
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
Nome:joao
Matrícula:1
Nota 1:8.0
Nota 2:6.0
A média é:7.0