Feito
This commit is contained in:
105
src/main/java/com/mycompany/tic_projeto/Tic_Projeto.java
Normal file
105
src/main/java/com/mycompany/tic_projeto/Tic_Projeto.java
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
*/
|
||||||
|
package com.mycompany.tic_projeto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author 250424
|
||||||
|
*/
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Tic_Projeto {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
ArrayList<String> livros = new ArrayList<>();
|
||||||
|
|
||||||
|
int opcao;
|
||||||
|
|
||||||
|
do {
|
||||||
|
System.out.println("\n===== GESTOR DE BIBLIOTECA =====");
|
||||||
|
System.out.println("1 - Adicionar livro");
|
||||||
|
System.out.println("2 - Ver livros");
|
||||||
|
System.out.println("3 - Remover livro");
|
||||||
|
System.out.println("4 - Procurar livro");
|
||||||
|
System.out.println("5 - Sair");
|
||||||
|
System.out.print("Escolha uma opção: ");
|
||||||
|
|
||||||
|
opcao = scanner.nextInt();
|
||||||
|
scanner.nextLine(); // Limpa o Enter
|
||||||
|
|
||||||
|
switch (opcao) {
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
System.out.print("Nome do livro: ");
|
||||||
|
String livro = scanner.nextLine();
|
||||||
|
livros.add(livro);
|
||||||
|
System.out.println("Livro adicionado com sucesso!");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
if (livros.isEmpty()) {
|
||||||
|
System.out.println("Não existem livros registados.");
|
||||||
|
} else {
|
||||||
|
System.out.println("\nLista de livros:");
|
||||||
|
for (int i = 0; i < livros.size(); i++) {
|
||||||
|
System.out.println((i + 1) + " - " + livros.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
if (livros.isEmpty()) {
|
||||||
|
System.out.println("Não existem livros para remover.");
|
||||||
|
} else {
|
||||||
|
System.out.println("\nLista de livros:");
|
||||||
|
for (int i = 0; i < livros.size(); i++) {
|
||||||
|
System.out.println((i + 1) + " - " + livros.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.print("Número do livro a remover: ");
|
||||||
|
int remover = scanner.nextInt();
|
||||||
|
|
||||||
|
if (remover >= 1 && remover <= livros.size()) {
|
||||||
|
livros.remove(remover - 1);
|
||||||
|
System.out.println("Livro removido com sucesso!");
|
||||||
|
} else {
|
||||||
|
System.out.println("Número inválido.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
System.out.print("Nome do livro a procurar: ");
|
||||||
|
String procurar = scanner.nextLine();
|
||||||
|
|
||||||
|
boolean encontrado = false;
|
||||||
|
|
||||||
|
for (String l : livros) {
|
||||||
|
if (l.equalsIgnoreCase(procurar)) {
|
||||||
|
System.out.println("Livro encontrado: " + l);
|
||||||
|
encontrado = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!encontrado) {
|
||||||
|
System.out.println("Livro não encontrado.");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
System.out.println("Programa terminado.");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
System.out.println("Opção inválida.");
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (opcao != 5);
|
||||||
|
|
||||||
|
scanner.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user