File tree Expand file tree Collapse file tree 1 file changed +90
-0
lines changed
Roadmap/19 - ENUMERACIONES/java Expand file tree Collapse file tree 1 file changed +90
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ public class danhingar {
3
+
4
+ public static void main (String [] args ) {
5
+ System .out .println (Days .valueOf (8 ));
6
+
7
+ // EXTRA
8
+ Order order = new Order (1 );
9
+ order .displayStatus ();
10
+ order .deliever ();
11
+ order .ship ();
12
+ order .deliever ();
13
+ order .cancel ();
14
+ }
15
+
16
+ static class Order {
17
+ private static int id ;
18
+ private static Status status ;
19
+
20
+ public Order (int identifier ) {
21
+ id = identifier ;
22
+ status = Status .PENDIENTE ;
23
+ }
24
+
25
+ public void ship () {
26
+ if (status .equals (Status .PENDIENTE )) {
27
+ status = Status .ENVIADO ;
28
+ displayStatus ();
29
+ } else {
30
+ System .out .println ("El pedido ya ha sido enviado o cancelado" );
31
+ }
32
+ }
33
+
34
+ public void deliever () {
35
+ if (status .equals (Status .ENVIADO )) {
36
+ status = Status .ENTREGADO ;
37
+ displayStatus ();
38
+ } else {
39
+ System .out .println ("El pedido necesita ser enviado antes de entregarse" );
40
+ }
41
+ }
42
+
43
+ public void cancel () {
44
+ if (!status .equals (Status .ENTREGADO )) {
45
+ status = Status .CANCELADO ;
46
+ displayStatus ();
47
+ } else {
48
+ System .out .println ("El pedido no se puede cancelar ya que ya se ha entregado." );
49
+ }
50
+ }
51
+
52
+ public void displayStatus () {
53
+ System .out .println ("El estado del pedido " + id + " es " + status );
54
+ }
55
+
56
+ }
57
+
58
+ }
59
+
60
+ enum Days {
61
+ LUNES (1 ),
62
+ MARTES (2 ),
63
+ MIERCOLES (3 ),
64
+ JUEVES (4 ),
65
+ VIERNES (5 ),
66
+ SABADO (6 ),
67
+ DOMINGO (7 );
68
+
69
+ private int numberDay ;
70
+
71
+ private Days (int numberDay ) {
72
+ this .numberDay = numberDay ;
73
+ }
74
+
75
+ public static String valueOf (int i ) {
76
+ return Days .values ().length >= i ? Days .values ()[i - 1 ].name () : "Selecciona un valor entre 1-7" ;
77
+ }
78
+
79
+ public int getNumberDay () {
80
+ return numberDay ;
81
+ }
82
+
83
+ }
84
+
85
+ enum Status {
86
+ PENDIENTE ,
87
+ ENVIADO ,
88
+ ENTREGADO ,
89
+ CANCELADO ;
90
+ }
You can’t perform that action at this time.
0 commit comments