Untitled
unknown
java
5 months ago
1.3 kB
3
Indexable
class Point { private int x; private int y; // Konstruktor domyślny public Point() { x = 0; y = 0; } public Point( int x, int y ) { this.x = x; this.y = y; } public int getX() { return x; } public int getY() { return y; } public Point add( Point other ) { return new Point( x + other.x, y + other.y ); } public Point subtract( Point other ) { return new Point( x - other.x, y - other.y ); } public static Point operatorStar( Point p1, Point p2 ) { return new Point( p1.x * p2.x, p1.y * p2.y ); } @Override public String toString() { return "( " + x + ", " + y + " )"; } } public class Main { public static void main(String[] args) { Point p1 = new Point(1, 2); Point p2 = new Point(3, 4); Point p3 = p1.add(p2); Point p4 = p1.subtract(p2); Point p5 = Point.operatorStar(p3, p4); System.out.println("Punkt p1: " + p1); System.out.println("Punkt p2: " + p2); System.out.println("Dodawanie: " + p3); System.out.println("Odejmowanie: " + p4); System.out.println("Mnożenie: " + p5); } }
Editor is loading...
Leave a Comment