Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Lista3{
- private String nome;
- private Lista3 proximo;
- public Lista3(){
- this.nome = null;
- this.proximo = null;
- }
- //INSERE OS NOMES NA LISTA
- public void inserir(String nome){
- if (this.proximo==null){
- this.nome = nome;
- this.proximo = new Lista3();
- } else{
- this.proximo.inserir(nome);
- }
- }
- //IMPRIMI TODOS OS NOMES QUE ESTÃO NA LISTA ATUALMENTE
- public String imprimirTudo (String nome){
- String aux = "";
- if (!nome.equals(null)){
- aux += this.nome + "\n";
- }else{
- aux += "";
- }
- return aux;
- }
- //VERIFICA SE O NOME ESTÁ NA LISTA
- public boolean existe (String nome){
- boolean aux = false;
- if (!this.nome.equals(null) && this.nome.equals(nome)){
- aux = true;
- } else if (!this.proximo.equals(null)){
- this.proximo.existe(nome);
- }else {
- aux = false;
- }
- return aux;
- }
- //RETORNA UM NOME ESPECIFICO QUE O ÚSUARIO QUER
- public String imprimirNome (String nome){
- String aux = "";
- if (this.nome.equals(nome)){
- aux = this.nome;
- } else {
- this.proximo.imprimirNome(nome);
- }
- return aux;
- }
- public String remover (String nome){
- String aux = "";
- if (this.proximo != null){
- if (this.nome.equals(nome)){
- this.nome = this.proximo.nome;
- this.proximo = this.proximo.proximo;
- }else {
- this.proximo.remover(nome);
- }
- }
- return this.nome;
- }
- }
- public class Tardis {
- public static void main (String [] args){
- Scanner in = new Scanner(System.in);
- Lista3 lista = new Lista3();
- String comando = "";
- String nome = "";
- String inimigo = in.nextLine();
- String auxiliar[] = inimigo.split(" ");
- while (in.hasNext()){
- inimigo = in.next();
- comando = in.next();
- if (comando.equals("ENTRAR") || comando.equals("SAIR") || comando.equals("VERIFICAR")){
- nome = in.nextLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement