Bom,eu estou começando a ver a materia de java agora e já estou vendo o basico e o avançado ao mesmo tempo,por isso achei melhor postar aqui essa duvida,porque creio que terá gente mais capacitada para ajudar.
E eu precizo bastante de ajuda,muito mesmo!
vou ter prova segunda agora e nao sei nada.
Eu peguei um codigo pronto de um colega meu e tive duvida nessa parte do codigo:
private String telefone, ddd;
public void setTelefone(String telefone){
if(telefone == null || telefone.trim().length() == 0){
throw new RuntimeException(“Telefone Inválido”);
}
this.telefone = telefone;
}
public String getTelefone(){
return this.telefone;
}
O codigo inteiro é esse:
package agendajava.modelo;
import java.util.Date;
public class Contato {
//Atributos
private Integer id;
private String nome;
private String telefone, ddd;
private String endereco;
private String email;
private String sexo;
private Date dataNascimento;
private String estadoCivil;
//metodos
//ID
public void setId(Integer id){
if(id == null || id == 0){
throw new RuntimeException("Id Invalido");
}
this.id = id;
}
public Integer getId(){
return this.id;
}
//Nome
public void setNome(String nome){
if(nome == null || nome.trim().length() == 0){
throw new RuntimeException("Nome Invalido");
}
this.nome = nome;
}
public String getNome(){
return this.nome;
}
//Telefone
public void setTelefone(String telefone){
if(telefone == null || telefone.trim().length() == 0){
throw new RuntimeException("Telefone Inválido");
}
this.telefone = telefone;
}
public String getTelefone(){
return this.telefone;
}
//DDD
public void setDDD(String DDD){
if(DDD == null || DDD.trim().length() == 0){
throw new RuntimeException("DDD inválido");
}
this.ddd = DDD;
}
public String getDDD(){
return this.ddd;
}
//Endereco
public void setEndereco(String endereco){
if(nome == null || nome.trim().length() == 0){
throw new RuntimeException("Endereço Invalido");
}
this.endereco = endereco;
}
public String getEndereco(){
return this.endereco;
}
//Email
public void setEmail(String email){
if(email == null || email.trim().length() == 0){
throw new RuntimeException("Email Inválido");
}
this.email = email;
}
public String getEmail(){
return this.email;
}
//Sexo
public void setSexo(String sexo){
if( !(sexo == "M" || sexo == "F") ){
throw new RuntimeException("Sexo Inválido");
}
this.sexo = sexo;
}
public String getSexo(){
return this.sexo;
}
//Data de Nascimento
public void setDataNascimento(Date data){
//throw new RuntimeException("Data Nascimento Inválido");
this.dataNascimento = data;
}
public Date getDataNascimento(){
return this.dataNascimento;
}
//Estado Civil
public void setEstadoCivil(String estadoCivil){
if( !(estadoCivil == "C" || estadoCivil == "S" || estadoCivil == "O" ) ){
throw new RuntimeException("Estado Civil Inválido");
}
this.estadoCivil = estadoCivil;
}
public String getEstadoCivil(){
return this.estadoCivil;
}
Eu tive duvida só naquela parte do codigo que eu mostrei que é a do telefone.
Eu nao entendi porque o telefone está sendo declarado como String…
eu rodei no eclipse e ele nao apontou erro algum.
Será que isso pode dar algum problema futuramente?
Thá correto?
abraços
Façam o maximo pra me dar uma forçinha galera.
eu precizo muito!
Vou deixar aqui meu MSN.
[email removido]