Advertisement
cesarnascimento

ficha 1 seg quest andreza

Sep 28th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.68 KB | None | 0 0
  1. //classe
  2.  
  3. public class Pesquisa {
  4.  
  5.     private String sexo;
  6.     private String corOlho;
  7.     private String corCabelo;
  8.     private int idade;
  9.     public int contPessoas;
  10.  
  11.    
  12.     public String getSexo() {
  13.         return sexo;
  14.     }
  15.     public void setSexo(String sexo) {
  16.         this.sexo = sexo;
  17.     }
  18.    
  19.     public String getCorOlho() {
  20.         return corOlho;
  21.     }
  22.    
  23.     public void setCorOlho(String corOlho) {
  24.         this.corOlho = corOlho;
  25.     }
  26.    
  27.     public String getCorCabelo() {
  28.         return corCabelo;
  29.     }
  30.    
  31.     public void setCorCabelo(String corCabelo) {
  32.         this.corCabelo = corCabelo;
  33.     }
  34.    
  35.     public int getIdade() {
  36.         return idade;
  37.     }
  38.    
  39.     public void setIdade(int idade) {
  40.         this.idade = idade;
  41.     }
  42.    
  43.     public void maiorIdade() {
  44.         int maiorIdade = Integer.MIN_VALUE;
  45.        
  46.         if(idade > maiorIdade) {
  47.             maiorIdade = idade;
  48.             System.out.println("A maior idade é: "+maiorIdade);
  49.         }
  50.     }
  51.    
  52.     public void maiorIdadeMasculino() {
  53.         int maiorIdadeM = Integer.MIN_VALUE;
  54.        
  55.         if(idade > maiorIdadeM && sexo.equalsIgnoreCase("m")) {
  56.             maiorIdadeM = idade;
  57.             System.out.println("A maior idade do sexo masculino é: "+maiorIdadeM);
  58.         }
  59.     }
  60.    
  61.     public void habFeminino() {
  62.         int habFem = 0;
  63.         if(sexo.equalsIgnoreCase("f") && idade >= 18 && idade <= 30 && corOlho.equalsIgnoreCase("verde") &&
  64.                 corCabelo.equalsIgnoreCase("loiro")) {
  65.             habFem++;
  66.         }
  67.        
  68.         System.out.println("Habitantes femininos com idade entre 18 e 30, olho verde e cabelo loiro: "+habFem);
  69.         //habitantes com idade entre 18 e 30, olho verde e cabelo loiro.
  70.     }
  71.    
  72.     public void mediaIdade() {
  73.         int idadeTotal = 0;
  74.         idadeTotal = idadeTotal + idade;
  75.         int media = idadeTotal / contPessoas;
  76.        
  77.         System.out.println("Media de idade das pessoas: "+media);
  78.     }
  79.  
  80. }
  81.  
  82. //main
  83.  
  84. import java.util.Scanner;
  85.  
  86. public class Principal {
  87.  
  88.     public static void main(String[] args) {
  89.         Scanner sc = new Scanner(System.in);
  90.        
  91.         Pesquisa pesquisa = new Pesquisa();
  92.        
  93.         boolean continuar = true;
  94.        
  95.         while(continuar) {
  96.             System.out.println("Digite seu sexo(M OU F): ");
  97.             pesquisa.setSexo(sc.next());
  98.            
  99.             System.out.println("Digite a cor dos seus olhos: ");
  100.             pesquisa.setCorOlho(sc.next());
  101.            
  102.             System.out.println("Digite a cor dos seus cabelos: ");
  103.             pesquisa.setCorCabelo(sc.next());
  104.            
  105.             System.out.println("Digite a sua idade: ");
  106.             pesquisa.setIdade(sc.nextInt());
  107.             pesquisa.contPessoas++;
  108.            
  109.             System.out.println("Você deseja sair? S/N?");
  110.             String opcao = sc.next();
  111.             if(opcao.equalsIgnoreCase("s")) {
  112.                 System.out.println("Saindo..");
  113.                 continuar = false;
  114.             }else {
  115.                 //continua o programa
  116.             }
  117.         }
  118.        
  119.         pesquisa.maiorIdade();
  120.         pesquisa.maiorIdadeMasculino();
  121.         pesquisa.habFeminino();
  122.         pesquisa.mediaIdade();
  123.  
  124.     }
  125.  
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement