cesarnascimento

questao1 anderson

Sep 8th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. package b;
  2.  
  3. public class Empresa {
  4.  
  5.     public String nome;
  6.     public String setor;
  7.     public int idade;
  8.     public float salario;
  9.     static int matricula = 0;
  10.    
  11.     Empresa(){
  12.         matricula++;
  13.         System.out.println("Funcionários cadastrados: "+matricula);
  14.     }
  15.    
  16.     public Empresa(String no, String se, int id, float sal,int mat) {
  17.         this.idade = id;
  18.         this.nome = no;
  19.         this.setor = se;
  20.         this.salario = sal;
  21.         this.matricula = mat;
  22.     }
  23.    
  24.     public String toString() {
  25.         return "nome: " +this.nome+" | "+ "setor: "+this.setor+" | "+
  26.         "idade: "+this.idade+" | "+this.salario+" | "+ "matrícula: "+this.matricula;
  27.     }
  28.    
  29. }
  30.  
  31.  
  32. //main
  33.  
  34. package b;
  35. import java.util.Scanner;
  36. public class Main {
  37.  
  38.     public static void main(String[] args) {
  39.         Scanner sc = new Scanner(System.in);
  40.         Empresa empresa = new Empresa();
  41.        
  42.         System.out.println("Quantos funcionários cadastrar? ");
  43.         int n = sc.nextInt();
  44.        
  45.         for(int i = 0; i < n; i++) {
  46.             System.out.println("Funcionário nº "+i+1);
  47.            
  48.             System.out.println("Nome: ");
  49.             empresa.nome = sc.next();
  50.            
  51.             System.out.println("Setor: ");
  52.             empresa.setor = sc.next();
  53.            
  54.             System.out.println("Idade: ");
  55.             empresa.idade = sc.nextInt();
  56.            
  57.             System.out.println("Salário: ");
  58.             empresa.salario = sc.nextFloat();
  59.            
  60.         }
  61.         System.out.println(empresa.toString());
  62.        
  63.  
  64.     }
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment