Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package laborki3;
- import java.util.*;
- class Punkt2D
- {
- double x;
- double y;
- Punkt2D(double x, double y)
- {
- this.x = x;
- this.y = y;
- }
- static double dist(Punkt2D a, Punkt2D b)
- {
- double ox = b.x - a.x;
- double oy = b.y - a.y;
- return Math.sqrt(Math.pow(ox, 2) + Math.pow(oy, 2));
- }
- int suma(int x, int y)
- {
- return x + y;
- }
- }
- class Punkt3D extends Punkt2D
- {
- double z;
- Punkt3D(double x, double y, double z)
- {
- super(x, y);
- this.z = z;
- }
- static double dist(Punkt3D a, Punkt3D b)
- {
- double ox = b.x - a.x;
- double oy = b.y - a.y;
- double oz = b.z - a.z;
- return Math.sqrt(Math.pow(ox, 2) + Math.pow(oy, 2) + Math.pow(oz, 2));
- }
- int suma(int x, int y, int z)
- {
- return super.suma(x, y) + z;
- }
- }
- public class Laborki3
- {
- public static void main(String[] args)
- {
- int x1, x2, y1, y2, z1, z2;
- Scanner x = new Scanner(System.in);
- System.out.println("Podaj x_1: ");
- x1 = x.nextInt();
- System.out.println("Podaj y_1: ");
- y1 = x.nextInt();
- System.out.println("Podaj z_1: ");
- z1 = x.nextInt();
- System.out.println("Podaj x_2: ");
- x2 = x.nextInt();
- System.out.println("Podaj y_2: ");
- y2 = x.nextInt();
- System.out.println("Podaj z_2: ");
- z2 = x.nextInt();
- Punkt2D a2D = new Punkt2D(x1, y1);
- Punkt2D b2D = new Punkt2D(x2, y2);
- Punkt3D a3D = new Punkt3D(x1, y1, z1);
- Punkt3D b3D = new Punkt3D(x1, y1, z2);
- System.out.println("Odległość między dwoma punktami 2D wynosi: " + Punkt2D.dist(a2D,b2D));
- System.out.println("Odległość między dwoma punktami 3D wynosi: " + Punkt3D.dist(a3D,b3D));
- System.out.println("Suma współrzędnych punktu A (2D): " + a2D.suma(x1, y1));
- System.out.println("Suma współrzędnych punktu B (2D): " + b2D.suma(x2, y2));
- System.out.println("Suma współrzędnych punktu A (3D): " + a3D.suma(x1, y1, z1));
- System.out.println("Suma współrzędnych punktu B (3D): " + b3D.suma(x2, y2, z2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement