-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReto1.java
More file actions
148 lines (123 loc) · 3.96 KB
/
Reto1.java
File metadata and controls
148 lines (123 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package ejerciciosretosudea;
public class Reto1 {
//Inserte acá los atributos
String nombre;
char sexo;
double posicionX = 0;
double posicionY = 0;
double distanciaTotal = 0;
int numeroBotiquines = 0;
double vida = 100;
//Inserte acá el método constructor
public Reto1(String nombre, char sexo) {
this.nombre = nombre;
this.sexo = sexo;
}
//Inserte acá los métodos (NO LOS GETTER Y SETTERS)
public void usarBotiquin () {
if (numeroBotiquines != 0) {
numeroBotiquines -= 1;
vida += 5;
}
}
public void recogerBotiquin() {
numeroBotiquines += 1;
}
public void moverDerecha(double d) {
posicionX += d;
distanciaTotal += d;
}
public void moverIzquierda(double d) {
posicionX -= d;
distanciaTotal += d;
}
public void moverArriba(double d) {
posicionY += d;
distanciaTotal += d;
}
public void moverAbajo(double d) {
posicionY -= d;
distanciaTotal += d;
}
public double calcularDistanciaRespectoOrigen() {
return Math.sqrt(Math.pow(posicionX, 2) + Math.pow(posicionY, 2));
}
//Inserte acá los SETTERS Y GETTERS
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public char getSexo() {
return sexo;
}
public void setSexo(char sexo) {
this.sexo = sexo;
}
public double getPosicionX() {
return posicionX;
}
public void setPosicionX(double posicionX) {
this.posicionX = posicionX;
}
public double getPosicionY() {
return posicionY;
}
public void setPosicionY(double posicionY) {
this.posicionY = posicionY;
}
public double getDistanciaTotal() {
return distanciaTotal;
}
public void setDistanciaTotal(double distanciaTotal) {
this.distanciaTotal = distanciaTotal;
}
public int getNumeroBotiquines() {
return numeroBotiquines;
}
public void setNumeroBotiquines(int numeroBotiquines) {
this.numeroBotiquines = numeroBotiquines;
}
public double getVida() {
return vida;
}
public void setVida(double vida) {
this.vida = vida;
}
public static void main(String[] args) {
Reto1 personaje = new Reto1("Juan", 'm');
personaje.moverDerecha(2);
personaje.moverAbajo(5);
personaje.moverIzquierda(1);
System.out.print("Distancia respecto al origen: ");
System.out.println(personaje.calcularDistanciaRespectoOrigen());
personaje.setVida(personaje.getVida() - 40);
System.out.print("Menos 40 de vida: ");
System.out.println(personaje.getVida());
personaje.recogerBotiquin();
personaje.recogerBotiquin();
personaje.recogerBotiquin();
System.out.println("Recoge 3 botiquines");
System.out.print("Numero de botiquines: ");
System.out.println(personaje.getNumeroBotiquines());
personaje.usarBotiquin();
personaje.usarBotiquin();
System.out.println("Usa 2 botiquines");
System.out.println("");
System.out.print("Numero de botiquines: ");
System.out.println(personaje.getNumeroBotiquines());
System.out.print("Distancia total: ");
System.out.println(personaje.getDistanciaTotal());
System.out.print("Nombre: ");
System.out.println(personaje.getNombre());
System.out.print("PosicionX: ");
System.out.println(personaje.getPosicionX());
System.out.print("PosicionY: ");
System.out.println(personaje.getPosicionY());
System.out.print("Sexo: ");
System.out.println(personaje.getSexo());
System.out.print("Vida: ");
System.out.println(personaje.getVida());
}
}