Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Pessoa{
- private String[] telefones = new String[3];
- private int cont = 0;
- public void inserirTelefone(String numero){
- /**for(int i = 0; i < this.telefones.length; i++){
- if(this.telefones[i] == null){
- this.telefones[i] = numero;
- break;
- }
- } **/
- if(cont < this.telefones.length){
- if(this.telefones[cont] == null){
- this.telefones[cont] = numero;
- cont++;
- }
- }else{
- System.out.println("ERRO! Só é permitido 3 telefones");
- }
- }
- public void listarTelefone(){
- int i;
- for(i = 0; i < this.telefones.length; i++){
- if(this.telefones[i] != null){
- System.out.println("["+ i+"]"+this.telefones[i]);
- }
- }
- }
- //
- public void apagarTelefone(String numero){
- for(int i = 0; i < this.telefones.length; i++){
- if(this.telefones[i] == numero){
- if(i == 0){
- this.telefones[i] = this.telefones[i + 1];
- this.telefones[i + 1] = this.telefones[i + 2];
- this.telefones[i + 2] = null;
- break;
- }else if(i == 1){
- this.telefones[i] = this.telefones[i + 1];
- this.telefones[i + 1] = null;
- break;
- }else{
- this.telefones[i] = null;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement