TrabalhosGratuitos.com - Trabalhos, Monografias, Artigos, Exames, Resumos de livros, Dissertações
Pesquisar

Programa elaborado para o estudo de Orientação à Objeto em Java

Por:   •  15/2/2017  •  Trabalho acadêmico  •  898 Palavras (4 Páginas)  •  361 Visualizações

Página 1 de 4

SISTEMA DE CRIAÇÃO E CONTROLE DE POKEMONS

PROGRAMA ELABORADO PARA O ESTUDO DE ORIENTAÇÃO À OBJETO EM JAVA

BY: VINÍCIUS OLIVEIRA

======================================================================

// CLASSE: Pokemon

package pokemon;

public class Pokemon {

private String nome;

private int nivel;

private int ataque;

private String tipo;

public Pokemon(String nome, int nivel, int ataque, String tipo) throws Exception {

if (nome == null || nome.trim().equals(""))

throw new Exception("Nome do pokémon não pode ser nulo ou vazio.");

if (nivel < 1)

throw new Exception("Nível do pokémon não pode ser menor ou igual a 0.");

if (ataque < 0)

throw new Exception("Ataque básico do pokémon não pode ser menor ou igual a 0.");

if (tipo == null || tipo.trim().equals(""))

throw new Exception("Tipo do pokémon não pode ser nulo ou vazio.");

this.nome = nome;

this.nivel = nivel;

this.ataque = ataque;

this.tipo = tipo;

}

public String getNome() {

return nome;

}

public void setNome(String nome) {

this.nome = nome;

}

public int getAtaque() {

return ataque;

}

public void setAtaque(int ataque) {

this.ataque = ataque;

}

public String getTipo() {

return tipo;

}

public void setTipo(String tipo) {

this.tipo = tipo;

}

public int getNivel() {

return nivel;

}

public void aumentaNivel() {

this.nivel++;

}

public int poderAtaque() {

return this.nivel * this.ataque;

}

@Override

public int hashCode() {

final int prime = 31;

int result = 1;

result = prime * result + nivel;

result = prime * result + ((nome == null) ? 0 : nome.hashCode());

return result;

}

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

Pokemon other = (Pokemon) obj;

if (nivel != other.nivel)

return false;

if (nome == null) {

if (other.nome != null)

return false;

} else if (!nome.equals(other.nome))

return false;

return true;

}

@Override

public String toString() {

return nome+ "(" +tipo+ "). lvl " +nivel+ "; power: " + poderAtaque();

}

}

======================================================================

// CLASSE: Pokeagenda

package pokemon;

import java.util.ArrayList;

public class Pokeagenda {

private ArrayList<Pokemon> agenda = new ArrayList<>();

private Pokemon pokemon;

public void adiciona(Pokemon pokemon) {

agenda.add(pokemon);

}

public boolean consulta(String nome) {

for (Pokemon pokemon : agenda) {

if (pokemon.getNome().equals(nome)) return true;

}

return false;

}

public int quantidade() {

return agenda.size();

}

...

Baixar como (para membros premium)  txt (9.5 Kb)   pdf (59.8 Kb)   docx (19 Kb)  
Continuar por mais 3 páginas »
Disponível apenas no TrabalhosGratuitos.com