Skip to content

Commit 7971780

Browse files
committed
- Commit do Exercício 1 (enunciado na pasta 'exercise') do Capítulo 4
1 parent 37e709e commit 7971780

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

EX-CAP-04-01/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.classpath
2+
/.project
52.6 KB
Binary file not shown.

EX-CAP-04-01/src/EX0401.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
public class EX0401 {
3+
4+
public static void main(String[] args) {
5+
Vetor vetor1 = new Vetor(7.2320, 9.0212);
6+
7+
Vetor clone = vetor1.clone();
8+
9+
System.out.println(clone.toString());
10+
}
11+
}

EX-CAP-04-01/src/Vetor.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
public class Vetor {
3+
private double x, y;
4+
5+
public Vetor(double x, double y) {
6+
this.x = x;
7+
this.y = y;
8+
}
9+
10+
private Vetor() { }
11+
12+
public Vetor clone() {
13+
Vetor clone = new Vetor();
14+
15+
clone.x = x;
16+
clone.y = y;
17+
18+
return clone;
19+
}
20+
21+
public String toString() {
22+
return "(" + String.format("%.2f", x) + " , " + String.format("%.2f", y) + ")";
23+
}
24+
}

0 commit comments

Comments
 (0)