I Have just started with getters and setters in Java<\/p>\n
And the code feels a little heavy. I am doing my best to understand it but I feel a little lost.<\/p>\n
I understand that setmethods modifies the current value while get methods returns the current value.<\/p>\n
But what my teacher has tried here is a little complex for me to understand.<\/p>\n
public class Circle {
\nprivate double radius;
\nprivate Point position;<\/p>\n
public Circle( double inRadius, Point inPosition ) {
\nthis.radius = inRadius;
\nthis.position = inPosition;
\n}<\/p>\n
public void setPosition( Point inPosition ) {
\nthis.position = inPosition;
\n}<\/p>\n
public double getRadius() {
\nreturn this.radius;
\n}<\/p>\n
public Point getPosition() {
\nreturn this.position;
\n}<\/p>\n
public int getX() {
\nreturn this.position.getX();
\n}<\/p>\n
public int getY() {
\nreturn this.position.getY();
\n}<\/p>\n
public String toString() {
\nreturn \"CIRCLE, radius = \" + this.radius + \", position = \" + position.toString();
\n}
\n}<\/p>","upvoteCount":5,"answerCount":3,"datePublished":"2018-10-27T21:15:00.000Z","author":{"@type":"Person","name":"roseyme","url":"https://community.spiceworks.com/u/roseyme"},"suggestedAnswer":[{"@type":"Answer","text":"
I Have just started with getters and setters in Java<\/p>\n
And the code feels a little heavy. I am doing my best to understand it but I feel a little lost.<\/p>\n
I understand that setmethods modifies the current value while get methods returns the current value.<\/p>\n
But what my teacher has tried here is a little complex for me to understand.<\/p>\n
public class Circle {
\nprivate double radius;
\nprivate Point position;<\/p>\n
public Circle( double inRadius, Point inPosition ) {
\nthis.radius = inRadius;
\nthis.position = inPosition;
\n}<\/p>\n
public void setPosition( Point inPosition ) {
\nthis.position = inPosition;
\n}<\/p>\n
public double getRadius() {
\nreturn this.radius;
\n}<\/p>\n
public Point getPosition() {
\nreturn this.position;
\n}<\/p>\n
public int getX() {
\nreturn this.position.getX();
\n}<\/p>\n
public int getY() {
\nreturn this.position.getY();
\n}<\/p>\n
public String toString() {
\nreturn \"CIRCLE, radius = \" + this.radius + \", position = \" + position.toString();
\n}
\n}<\/p>","upvoteCount":5,"datePublished":"2018-10-27T21:15:00.000Z","url":"https://community.spiceworks.com/t/hello-could-you-please-help-me-understand-this-code/680881/1","author":{"@type":"Person","name":"roseyme","url":"https://community.spiceworks.com/u/roseyme"}},{"@type":"Answer","text":"
This seems to be a very straight forward piece of code that creates an object “circle” with properties “radius” and “position”.<\/p>\n
Not sure the syntax is all correct but it is quite understandable in it’s structure.<\/p>\n
What is it you don’t understand?<\/p>","upvoteCount":2,"datePublished":"2018-10-28T23:44:38.000Z","url":"https://community.spiceworks.com/t/hello-could-you-please-help-me-understand-this-code/680881/2","author":{"@type":"Person","name":"cyberdec","url":"https://community.spiceworks.com/u/cyberdec"}},{"@type":"Answer","text":"
It’s not clear that What and/or which part of the code you don’t understand ?<\/p>\n