0% found this document useful (0 votes)
11 views

Vektori

This document defines classes for vector operations in Java, including a Vector class to represent vectors with x, y, z coordinates, and subclasses to calculate the scalar and mixed products of vectors. It takes user input to create Vector objects, calculates their scalar and mixed products, and prints the results.

Uploaded by

jana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Vektori

This document defines classes for vector operations in Java, including a Vector class to represent vectors with x, y, z coordinates, and subclasses to calculate the scalar and mixed products of vectors. It takes user input to create Vector objects, calculates their scalar and mixed products, and prints the results.

Uploaded by

jana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

Scanner;

abstract class VektorOperacija {


abstract double izracunaj();
}

class Vektor {
private double x, y, z;

public Vektor() {
}

public Vektor(double x, double y, double z) {


this.x = x;
this.y = y;
this.z = z;
}

public double getX() {


return x;
}

public double getY() {


return y;
}

public double getZ() {


return z;
}

public void setX(double x) {


this.x = x;
}

public void setY(double y) {


this.y = y;
}

public void setZ(double z) {


this.z = z;
}

public static Vektor vektorskiProizvod(Vektor u, Vektor t) {


double newX = u.getY() * t.getZ() - u.getZ() * t.getY();
double newY = u.getZ() * t.getX() - u.getX() * t.getZ();
double newZ = u.getX() * t.getY() - u.getY() * t.getX();
return new Vektor(newX, newY, newZ);
}
}

class SkalarniProizvod extends VektorOperacija {


private Vektor u;
private Vektor t;

public SkalarniProizvod(Vektor u, Vektor t) {


this.u = new Vektor(u.getX(), u.getY(), u.getZ());
this.t = new Vektor(t.getX(), t.getY(), t.getZ());
}
public double izracunaj() {
return u.getX() * t.getX() + u.getY() * t.getY() + u.getZ() * t.getZ();
}

@Override
public String toString() {
return "(" + u.getX() + ", " + u.getY() + ", " + u.getZ() + ").(" +
t.getX() + ", " + t.getY() + ", " + t.getZ() + ") = " + izracunaj();
}
}

class MesovitiProizvod extends VektorOperacija {


private Vektor u;
private Vektor v;
private Vektor t;

public MesovitiProizvod(Vektor u, Vektor v, Vektor t) {


this.u = new Vektor(u.getX(), u.getY(), u.getZ());
this.v = new Vektor(v.getX(), v.getY(), v.getZ());
this.t = new Vektor(t.getX(), t.getY(), t.getZ());
}

public double izracunaj() {


Vektor vektorskiProizvod = Vektor.vektorskiProizvod(v, t);
return new SkalarniProizvod(u, vektorskiProizvod).izracunaj();
}

@Override
public String toString() {
return "(" + u.getX() + ", " + u.getY() + ", " + u.getZ() + ").((" +
v.getX() + ", " + v.getY() + ", " + v.getZ() + ")x(" + t.getX() + ", " + t.getY() +
", " + t.getZ() + ")) = " + izracunaj();
}
}

public class TestVektori {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Uneti koordinate prvog vektora:");


double x1 = scanner.nextDouble();
double y1 = scanner.nextDouble();
double z1 = scanner.nextDouble();
Vektor prvi = new Vektor(x1, y1, z1);

System.out.println("Uneti koordinate drugog vektora:");


double x2 = scanner.nextDouble();
double y2 = scanner.nextDouble();
double z2 = scanner.nextDouble();
Vektor drugi = new Vektor(x2, y2, z2);

System.out.println("Uneti koordinate treceg vektora:");


double x3 = scanner.nextDouble();
double y3 = scanner.nextDouble();
double z3 = scanner.nextDouble();
Vektor treci = new Vektor(x3, y3, z3);

SkalarniProizvod skalarni = new SkalarniProizvod(prvi, drugi);


MesovitiProizvod mesoviti = new MesovitiProizvod(prvi, drugi, treci);
System.out.println(skalarni);
System.out.println(mesoviti);

scanner.close();
}
}

You might also like