File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
src/main/java/com/example Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .example ;
2
+
3
+ import java .time .LocalDate ;
4
+
5
+ public class AppEleitor {
6
+ public static void main (String [] args ){
7
+
8
+ var cidadao = new Cidadao ();
9
+ cidadao .setDataNascimento (LocalDate .of (1990 ,8 ,11 ));
10
+
11
+ System .out .println ("A idade do cidadão é " + cidadao .idade ());
12
+ System .out .println (cidadao .eleitor ());
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ package com .example ;
2
+
3
+ import java .time .LocalDate ;
4
+
5
+ public class Cidadao {
6
+ private LocalDate dataNascimento ;
7
+
8
+ public LocalDate getDataNascimento () {
9
+ return dataNascimento ;
10
+ }
11
+
12
+ public void setDataNascimento (LocalDate dataNascimento ) {
13
+ this .dataNascimento = dataNascimento ;
14
+ }
15
+
16
+ public int idade () {
17
+ return LocalDate .now ().getYear () - dataNascimento .getYear ();
18
+ }
19
+
20
+ public String eleitor () {
21
+ int idade = idade ();
22
+
23
+ if (idade < 16 )
24
+ return "não é eleitor" ;
25
+
26
+ if ((idade >= 16 && idade < 18 ) || (idade > 70 ))
27
+ return "é eleitor facultativo" ;
28
+
29
+ return "é eleitor obrigatório" ;
30
+
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments