Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vinicius
committed
Dec 21, 2020
1 parent
f66dea9
commit afa121e
Showing
6 changed files
with
133 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
public class Acionista { | ||
|
||
private int quantidadeDeCotas; | ||
|
||
private float totalDividendosRecebidos; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
public class Funcionario extends Pessoa { | ||
|
||
private int matricula; | ||
|
||
private float salario; | ||
|
||
private String cargo; | ||
|
||
public Funcionario(String nome, long cpf, int matricula) { | ||
/* A primeira linha de qualquer construtor PRECISA SER | ||
uma chamada ao construtor da superclasse, via super(.....). | ||
Se nós não fizermos explicitamente essa chamada, | ||
o compilador vai acrescentar automaticamente | ||
a chamada | ||
super(); | ||
*/ | ||
|
||
super(nome, cpf); | ||
|
||
this.matricula = matricula; | ||
this.cargo = "sem cargo"; | ||
this.salario = 1000f; | ||
} | ||
|
||
public int getMatricula() { | ||
return matricula; | ||
} | ||
|
||
public void receberAumento(float percentual) { | ||
salario *= (1 + percentual/100); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("%d --- %s", | ||
matricula, super.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public class Gerente extends Funcionario { | ||
|
||
private int nivel; // 1: gerente de conta; 2: gerente geral | ||
|
||
public Gerente(String nome, long cpf, int matricula) { | ||
super(nome, cpf, matricula); | ||
nivel = 1; | ||
} | ||
|
||
public void setNivel(int nivel) { | ||
if (nivel < 1 && nivel > 2) { | ||
throw new RuntimeException("Nivel invalido!"); | ||
} | ||
|
||
this.nivel = nivel; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,58 @@ | ||
import java.util.Scanner; | ||
|
||
public class Principal { | ||
|
||
public static void main(String[] args) { | ||
|
||
Pessoa fulano = new Pessoa("Fulano de Tal", 12345); | ||
|
||
System.out.println("cpf = " + fulano.getCpf()); | ||
|
||
System.out.println(fulano.toString()); | ||
|
||
|
||
Funcionario paiva; | ||
paiva = new Funcionario("Paiva", 234567, 1111); | ||
|
||
Pessoa beltrano; | ||
beltrano = criarFuncionario(); | ||
|
||
beltrano.setEndereco("Rua Tal, numero 1"); | ||
|
||
//beltrano.receberAumento(10); // essa linha não compilaria!!!! | ||
|
||
paiva.receberAumento(10); | ||
|
||
System.out.println(beltrano.toString()); | ||
|
||
|
||
} | ||
|
||
private static Pessoa criarFuncionario() { | ||
Scanner sc = new Scanner(System.in); | ||
|
||
System.out.println("Nome: "); | ||
String nome = sc.nextLine(); | ||
|
||
System.out.println("CPF: "); | ||
long cpf = sc.nextLong(); | ||
|
||
// consome o "\n" que o nextLong não irá consumir | ||
sc.nextLine(); | ||
|
||
System.out.println("É funcionário (S|N)? "); | ||
String resposta = sc.nextLine(); | ||
boolean ehFuncionario = resposta.equals("S") || | ||
resposta.equals("s"); | ||
|
||
if (ehFuncionario) { | ||
System.out.println("Matrícula: "); | ||
int matricula = sc.nextInt(); | ||
return new Funcionario(nome, cpf, matricula); | ||
} | ||
|
||
//return new Object(); // não compilaria!!!!! | ||
|
||
return new Pessoa(nome, cpf); | ||
} | ||
} |