Advertisement
dantepw

Untitled

Feb 6th, 2014
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. public class exAula1 {
  2.    
  3.     String nome = "";
  4.     String equipe = "";
  5.     int idade;
  6.    
  7.     void imprimir(){
  8.     System.out.println("Nome: " + nome + "\nEquipe: " + equipe + "\nIdade: " + idade);
  9.     }
  10.  
  11.    
  12.     void separarGrupo(){
  13.    
  14.         if(idade >= 6 && idade <= 10){
  15.             equipe = "A";
  16.         }
  17.        
  18.         else if (idade >= 11 && idade <= 20){
  19.             equipe = "B";
  20.         }
  21.        
  22.         else if (idade >= 21){
  23.             equipe = "C";
  24.         }
  25.        
  26.        
  27.     }
  28.    
  29.     void setDados(String nome, int idade){
  30.         this.nome = nome;
  31.         this.idade = idade;
  32.     }
  33.    
  34.     public static void main (String[] args){
  35.         Scanner input = new Scanner (System.in);
  36.         exAula1 obj = new exAula1();
  37.         String nome, equipe;
  38.         int idade;
  39.        
  40.         //recebendo variáveis
  41.         nome = JOptionPane.showInputDialog(null, "Digite um nome: ");
  42.         idade = Integer.parseInt(JOptionPane.showInputDialog(null, "Digite uma idade: "));
  43.        
  44.         //procedimentos na ordem necessária
  45.         obj.setDados(nome, idade); //joga as variáveis para o "setDados", aonde atribui um valor para as mesmas
  46.         obj.separarGrupo(); //faz a condição das idades com esse método
  47.         obj.imprimir(); //imprime na tela
  48.        
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement