Commit | Line | Data |
---|---|---|
84aff5c8 H |
1 | import java.io.*; |
2 | import java.util.*; | |
3 | import java.lang.Math; | |
4 | ||
5 | /** Pisemka - trida "PolCoordinate" | |
6 | * Copylefted by: Harvie 2oo9 ( http://blog.harvie.cz/ ) | |
7 | * @author Thomas Harvie Mudrunka (mudruto1) | |
8 | * @version 1.0 | |
9 | */ | |
10 | class PolCoordinate { | |
11 | private double phi = 0, r = 0; | |
12 | private double x = 0, y = 0; | |
13 | private Scanner sc = new Scanner(System.in); | |
14 | ||
15 | PolCoordinate(double uhel, double vzdalenost) { | |
16 | phi = uhel; | |
17 | r = vzdalenost; | |
18 | x = vzdalenost * Math.cos(uhel); | |
19 | y = vzdalenost * Math.sin(uhel); | |
20 | } | |
21 | ||
22 | public double getX() { return x; } | |
23 | public double getY() { return y; } | |
24 | ||
25 | public String toString() { | |
26 | return new String("X = "+x+"\nY = "+y); | |
27 | } | |
28 | ||
29 | public void addCoor(PolCoordinate b) { | |
30 | x += b.getX(); | |
31 | y += b.getY(); | |
32 | } | |
33 | public boolean equals(PolCoordinate b) { | |
34 | if(x == b.getX() && y == b.getY()) return true; | |
35 | return false; | |
36 | } | |
37 | ||
38 | } | |
39 | ||
40 | public class Polar { | |
41 | public static void main(String[] argv) { | |
42 | PolCoordinate A = new PolCoordinate(45, 100); | |
43 | PolCoordinate B = new PolCoordinate(45, 10); | |
44 | System.out.println("A:\n"+A); | |
45 | System.out.println("B:\n"+B); | |
46 | if(A.equals(B)) System.out.println("A==B"); | |
47 | else System.out.println("A!=B"); | |
48 | A.addCoor(B); | |
49 | System.out.println("A+B:\n"+A); | |
50 | } | |
51 | } | |
52 | ||
53 |