Guest User

Untitled

a guest
Jan 13th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. static Aluno alunosExistente(int matAluno) {
  2. Iterator<Aluno> itAluno = listaAluno.iterator();
  3. Aluno aluno;
  4. while (itAluno.hasNext()) {
  5. aluno = itAluno.next();
  6. if (aluno.getNumMat() == matAluno) {
  7. return aluno;
  8. }
  9. }
  10. return null;
  11. }
  12. static Livro livrosExistente(int codLivro) {
  13. Iterator<Livro> itLista = listaLivro.iterator();
  14. Livro livro;
  15. while (itLista.hasNext()) {
  16. livro = itLista.next();
  17. if (livro.getCodigoLivro() == codLivro) {
  18. return livro;
  19. }
  20. }
  21. return null;
  22. }
  23.  
  24. static void emprestarLivro() {
  25. Keyboard.clrscr();
  26. char resp;
  27. do {
  28. int matAlun = Keyboard.readInt("Digite a matricula do aluno: ");
  29. Aluno aluno = alunosExistente(matAlun);
  30. if (aluno == null) {
  31. System.out.println("Aluno não existe");
  32. } else {
  33. int codLivro = Keyboard.readInt("Digite Codigo do livro: ");
  34. Livro livro = livrosExistente(codLivro);
  35. if (livro == null) {
  36. System.out.println("Livro não existe");
  37. }
  38. livro = listaLivro.retrieve(livro);
  39. if(livro!= null){
  40. if(livro.getRefLivro() == null){
  41. aluno.inserirLivro(livro);
  42. livro.setComAluno(aluno);
  43. System.out.println("Emprestimo realizado!");
  44. }
  45. else{
  46. System.out.println("Livro ja emprestado!");
  47. }
  48. }
Add Comment
Please, Sign In to add comment