Skip to content

Commit 30674be

Browse files
author
java-tester-x
committed
Conflicts: src/ex7/CustomerTest.java src/ex7/Discount.java src/ex7/DiscountSystem/CustomerTest.java src/ex7/VisitTest.java
2 parents a4a4d64 + e729d99 commit 30674be

4 files changed

Lines changed: 69 additions & 1 deletion

File tree

src/ex7/Discount.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class Discount
1212
private static double productDiscountPremium = 0.1;
1313
private static double productDiscountGold = 0.1;
1414
private static double productDiscountSilver = 0.1;
15-
15+
1616
public static double getServiceDiscountRate(String type) {
1717
switch(type.toUpperCase()) {
1818
case "PREMIUM": return serviceDiscountPremium;

src/ex8/Point.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package src.ex8;
2+
3+
public class Point {
4+
5+
private int x;
6+
private int y;
7+
8+
public Point(int x, int y) {
9+
this.x = x;
10+
this.y = y;
11+
}
12+
13+
public String toString() {
14+
return String.format("Point (%1$d, %2$d)", x, y);
15+
}
16+
}

src/ex8/PolyLine.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package src.ex8;
2+
3+
import java.util.List;
4+
import java.util.ArrayList;
5+
6+
public class PolyLine {
7+
8+
private List<Point> points = new ArrayList<Point>();
9+
10+
public PolyLine() { } // default constructor
11+
12+
public PolyLine(List<Point> points) {
13+
this.points = points;
14+
}
15+
16+
public void appendPoint(Point point) {
17+
points.add(point);
18+
}
19+
20+
public void appendPoint(int x, int y) {
21+
points.add(new Point(x, y));
22+
}
23+
24+
public String toString()
25+
{
26+
StringBuilder sb = new StringBuilder();
27+
int i = 0;
28+
for (Point aPoint : points) {
29+
if (i != 0) {
30+
sb.append(", ");
31+
}
32+
sb.append(aPoint.toString());
33+
i++;
34+
}
35+
return sb.toString();
36+
}
37+
}

src/ex8/TestPolyLine.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package src.ex8;
2+
3+
public class TestPolyLine {
4+
5+
public static void main(String[] args)
6+
{
7+
PolyLine l1 = new PolyLine();
8+
System.out.println(l1); // empty
9+
10+
l1.appendPoint(new Point(1, 1));
11+
l1.appendPoint(2, 2);
12+
l1.appendPoint(3, 3);
13+
System.out.println(l1); // (1,1)(2,2)(3,3)
14+
}
15+
}

0 commit comments

Comments
 (0)