Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package b;
- public class Empresa {
- public String nome;
- public String setor;
- public int idade;
- public float salario;
- static int matricula = 0;
- Empresa(){
- matricula++;
- System.out.println("Funcionários cadastrados: "+matricula);
- }
- public Empresa(String no, String se, int id, float sal,int mat) {
- this.idade = id;
- this.nome = no;
- this.setor = se;
- this.salario = sal;
- this.matricula = mat;
- }
- public String toString() {
- return "nome: " +this.nome+" | "+ "setor: "+this.setor+" | "+
- "idade: "+this.idade+" | "+this.salario+" | "+ "matrícula: "+this.matricula;
- }
- }
- //main
- package b;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Empresa empresa = new Empresa();
- System.out.println("Quantos funcionários cadastrar? ");
- int n = sc.nextInt();
- for(int i = 0; i < n; i++) {
- System.out.println("Funcionário nº "+i+1);
- System.out.println("Nome: ");
- empresa.nome = sc.next();
- System.out.println("Setor: ");
- empresa.setor = sc.next();
- System.out.println("Idade: ");
- empresa.idade = sc.nextInt();
- System.out.println("Salário: ");
- empresa.salario = sc.nextFloat();
- }
- System.out.println(empresa.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment