+ 1

Point Class, Point controller

Hello I have problem with one Task, These are my codes: https://code.sololearn.com/c8VUVBV8NI8I/#java https://code.sololearn.com/c3qj68a5JIlD/#java And this is a Task description: Create a program, that allows to control data of an object, which represents a point on a plane. Point (class Point) - should have two fields that represents coordinates X and Y - representation of coordinates should be integer-like. Class should follow JavaBeans specification. Class should have constructor without parameters and constructor that allows to set coordinates while creating object.   PointContoller (class PointController) - have 4 methods which allow to manipulate position of the point on the plane: -addX() - increase variable x with value of 1 -minusX() - decrease variable x with value of 1 -addY() - increase variable y with value of 1 -minusY() - decrease variable y with value of 1   Each method adopts as a parameter the Point class object and operates on it. Both classes should be placed in different packages, and their operation should be tested in the third class called PointApplication. Could you please point me to the right direction? How to combine it in one program.

10th Apr 2018, 1:28 PM
Łukasz Stachura
Łukasz Stachura - avatar
2 Réponses
0
Declaring packages won't work as it's related to the path of your java file. For example package Test must be declared in a file located inside a folder named Test. This is required.Thus, u can't use packages and u will have to make a single class (java does't accept more than one class defined in a file).
10th Apr 2018, 1:43 PM
Hallox
Hallox - avatar
0
Maybe this : public class Point { private int x; private int y; public Point(int x, int y) { this.x = x; this.y = y; } public String toString() { return "(" + x + "," + y + ")"; } public void addX() { this.x += 1; } public void addY() { this.y += 1; } public void minusX() { this.x -= 1; } public void minusY() { this.y -= 1; } public static void main(String[] args) { Point point = new Point(3, 6); System.out.println(point.toString()); } }
10th Apr 2018, 1:50 PM
Hallox
Hallox - avatar