Skip to content

Commit 230d06f

Browse files
committed
Scanner
1 parent 2b72a1e commit 230d06f

File tree

3 files changed

+91
-9
lines changed

3 files changed

+91
-9
lines changed

src/main/java/com/example/AppClasses.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,27 @@
22

33
public class AppClasses {
44
public static void main(String[] args) {
5-
Clientes clientes=new Clientes();
6-
clientes.setRenda(10000);
5+
Clientes cliente1=new Clientes("01234567P"," Paulo Cesar ",10000,'M',1966);
6+
Clientes cliente2=new Clientes(new String("01234567p"),"Lana",20000,'F',1983);
7+
/* clientes.setRenda(10000);
78
clientes.setSexo('F');
89
clientes.setAnoNascimento(2020);
9-
System.out.println(clientes.getRenda());
10-
System.out.println(clientes.getSexo());
11-
System.out.println(clientes.getAnoNascimento());
10+
*/
11+
System.out.println(cliente1.getCpf());
12+
System.out.println(cliente1.getNome());
13+
System.out.println(cliente1.getRenda());
14+
System.out.println(cliente1.getSexo());
15+
System.out.println(cliente1.getAnoNascimento());
16+
System.out.println(cliente1.isEspecial());
17+
18+
if (cliente1.getCpf().equalsIgnoreCase(cliente2.getCpf()))
19+
System.out.println("Os clientes tem o mesmo CPF");
20+
else
21+
System.out.println("Os clientes tem CPFs diferentes");
22+
String[] vetor = cliente1.getNome().split(" ", 0);
23+
for (byte i=0; i <= vetor.length -1;i++)
24+
System.out.println( vetor[i]);
25+
1226
}
1327

1428
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.example;
2+
3+
import java.util.Scanner;
4+
5+
public class AppScanner {
6+
public static void main(String[] args) {
7+
Clientes cliente1=new Clientes("?","?",0,'?',1966);
8+
Scanner scanner=new Scanner(System.in);
9+
System.out.println("Digite o seu nome:");
10+
cliente1.setNome(scanner.nextLine());
11+
System.out.println("Digite o seu CPF:");
12+
cliente1.setCpf(scanner.nextLine());
13+
System.out.println("Digite o seu Salario:");
14+
cliente1.setRenda(scanner.nextDouble());
15+
scanner.nextLine();
16+
System.out.println("Digite o seu sexo:");
17+
cliente1.setSexo(scanner.nextLine().charAt(0));
18+
19+
20+
21+
System.out.println(cliente1.getNome());
22+
System.out.println(cliente1.getCpf());
23+
System.out.println(cliente1.getRenda());
24+
System.out.println(cliente1.getSexo());
25+
System.out.println(cliente1.getAnoNascimento());
26+
System.out.println(cliente1.isEspecial());
27+
28+
}
29+
30+
}

src/main/java/com/example/Clientes.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,43 @@
11
package com.example;
22

33
public class Clientes{
4+
private String cpf;
5+
private String nome;
46
private double renda;
57
private char sexo;
68
private int anoNascimento;
9+
private boolean especial;
710

8-
11+
public Clientes(){
12+
double aleatorio= Math.random();
13+
if(aleatorio >0.5)
14+
setEspecial(true);
15+
else
16+
setEspecial(false);
17+
}
18+
public Clientes(String cpf,String nome, double renda, char sexo, int anoNascimento){
19+
this();
20+
this.setCpf(cpf);
21+
this.setNome(nome);
22+
this.setRenda(renda);
23+
this.setSexo(sexo);
24+
this.setAnoNascimento(anoNascimento);
25+
}
26+
public String getCpf() {
27+
return cpf;
28+
}
29+
public void setCpf(String cpf) {
30+
this.cpf = cpf;
31+
}
32+
public String getNome() {
33+
return nome;
34+
}
35+
public void setNome(String nome) {
36+
if (!nome.isBlank())
37+
this.nome = nome.toUpperCase().trim();
38+
else
39+
System.err.println("Insira um nome");
40+
}
941
public char getSexo() {
1042
return sexo;
1143
}
@@ -19,13 +51,19 @@ public int getAnoNascimento() {
1951
public void setAnoNascimento(int anoNascimento) {
2052
this.anoNascimento = anoNascimento;
2153
}
22-
2354
public double getRenda() {
2455
return renda;
2556
}
2657
public void setRenda(double renda) {
2758
if(renda >= 0)
2859
this.renda=renda;
60+
else
61+
System.err.println("A renda precisa ser maior que zero");
2962
}
30-
31-
}
63+
public boolean isEspecial() {
64+
return especial;
65+
}
66+
public void setEspecial(boolean especial) {
67+
this.especial = especial;
68+
}
69+
}

0 commit comments

Comments
 (0)