Commit d54c731e authored by Georgii Aksenov's avatar Georgii Aksenov
Browse files

iteration 01 done

parent 0d4e6e66
package cz.muni.fi.pb162.project;
import cz.muni.fi.pb162.project.geometry.Vertex2D;
/**
* Class for running main method.
*
* @author TODO: put your name here
* @author Georgii Aksenov <xaksenov@fi.muni.cz>
*/
public class Demo {
/**
* Runs the code.
* prints info for two vertices of fixed coordinates.
*
* @param args command line arguments, will be ignored
*/
public static void main(String[] args) {
Vertex2D v1 = newVertex(2, 3);
Vertex2D v2 = newVertex(1, 1);
v1.move(v2);
System.out.println("Hello world!");
System.out.println(v1.getInfo());
System.out.println(v2.getInfo());
}
/**
* Creates new instance of Vertex2D.
*
* @param x coordinate for new vector
* @param y coordinate for new vector
* @return new Vertex2D.
*/
private static Vertex2D newVertex(double x, double y) {
Vertex2D vertex = new Vertex2D();
vertex.setX(x);
vertex.setY(y);
return vertex;
}
}
package cz.muni.fi.pb162.project.geometry;
/**
* @author Georgii Aksenov <xaksenov@fi.muni.cz>
*/
public class Vertex2D {
private double X = 0;
private double Y = 0;
public double getX() {
return X;
}
public void setX(double x) {
X = x;
}
public double getY() {
return Y;
}
public void setY(double y) {
Y = y;
}
/**
* To get string representation.
*
* @return string representation.
*/
public String getInfo() {
return String.format("[%.1f, %.1f]", X, Y);
}
/**
* To get sum of coordinates.
*
* @return sum of coordinates.
*/
public double sumCoordinates() {
return X + Y;
}
/**
* Moves the vertex.
*
* @param vertex is added to this vertex.
*/
public void move(Vertex2D vertex) {
X += vertex.X;
Y += vertex.Y;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment