1 / 7

Associação

Associação. Desafio – Aula07. Desafio – Aula07. class Aluno { private String nome; private float nota; public Aluno(String nome, float nota){ this.nome = nome; this.nota = nota; } public void setNota(float nota){ this.nota = nota; } public float getNota(){

gaius
Download Presentation

Associação

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Associação

  2. Desafio – Aula07

  3. Desafio – Aula07 • class Aluno { • private String nome; • private float nota; • public Aluno(String nome, float nota){ • this.nome = nome; • this.nota = nota; • } • public void setNota(float nota){ • this.nota = nota; • } • public float getNota(){ • return nota; • } • public String getNome(){ • return nome; • } • }

  4. Desafio – Aula07 • class Disciplina{ • private String materia; • private String professor; • public static Aluno alunos[] = new Aluno[10]; • public Disciplina (String materia, String professor) { • this.materia = materia; • this.professor = professor; • } • public Aluno procurarAluno(String aluno) { • for (int i=0; i<10; i++){ • if (aluno.equals(alunos[i].getNome())){ • return (alunos[i]); • } • } • return (null); • }

  5. Desafio – Aula07 • public void inserirAluno(Aluno aluno, int posicao){ • alunos[posicao]=aluno; • } • } • import java.util.Scanner; // Classe Scanner • class Principal { • public static void main(String args[]) { • Aluno aluno; • String disciplina="",professor="",nomeAluno=""; //inicia Strings • float nota; • Scanner entrada = new Scanner( System.in );

  6. Desafio – Aula07 • System.out.printf("\nEntre com nome da disciplina: "); • disciplina = entrada.nextLine() ; • System.out.printf("\nEntre com nome do professor: "); • professor = entrada.nextLine(); • Disciplina minhaDisciplina = new Disciplina(disciplina,professor); • for (int cont=0; cont<10; cont++){ • System.out.printf("\nDigite o nome do aluno %d: ",cont+1); • nomeAluno = entrada.nextLine(); // lê nome do aluno • aluno = new Aluno(nomeAluno,0); • minhaDisciplina.inserirAluno(aluno,cont); • } • do { • System.out.printf("\nEntre com nome do aluno a procurar: "); • nomeAluno = entrada.nextLine();

  7. Desafio – Aula07 • if (nomeAluno!="") { • aluno = minhaDisciplina.procurarAluno (nomeAluno); • if ( aluno != null) { • System.out.printf("\nNota atual: %.1f",aluno.getNota()); • System.out.printf("\nEntre com a nova nota: "); • nota = entrada.nextFloat(); • aluno.setNota(nota); • System.out.printf("\nNova nota de %s: %.1f\n", • aluno.getNome(),aluno.getNota()); • String lixo = entrada.nextLine();// consome o ENTER da nota • } • } • } while (!nomeAluno.equals("")); • System.out.printf("\nFim do programa...\n"); • } //main method • } //class Principal

More Related