Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement(define) a class named cPointType.java A cPointType has a label (a Stri

ID: 3812965 • Letter: I

Question

Implement(define) a class named cPointType.java A cPointType has a label (a String) and x,y, values (doubles). It provides the methods to set each of the coordinates (give the point an initial value) change the each (increase or decrease the position by some value), to return the current value, to set the label value and to return the label value. Objects that are declared to be of CPointType are given initial coordinates of 0 and an initial label value of the origin, there is a second constructor that allows for setting the label and position on instantiation. Additionally, cPointType has a toString method that returns cPointTypeas label (x,y).

PLEASE EXPLAIN WITH YOUR ANSWER LIKE I AM 5. i AM NEW TO JAVA..

Explanation / Answer

cPointType.java

public class cPointType
{
public String label;
public int x,y;

public cPointType(String name, int x, int y) {
this.label = name;
this.x = x;
this.y = y;
}
public cPointType() {
this.label = "origin";
this.x = 0;
this.y = 0;
}
void increase(int dx,int dy)
{
this.x = this.x + dx;
this.y = this.y + dy;
}
void decrease(int dx,int dy)
{
this.x = this.x - dx;
this.y = this.y - dy;
}
String tostring()
{
String out ;
out = this.label + "(" + Integer.toString(x) + "," + Integer.toString(y) + ")";
return out;
}
String Curlabel()
{
return this.label;
}

int Curx()
{
return this.x;
}
int Cury()
{
return this.y;
}

}

driver.java

public class driver {

public static void main(String[] args) {
cPointType xx =new cPointType("middle",2,3);
System.out.println(xx.tostring());
System.out.println(xx.Curx());
System.out.println(xx.Cury());
System.out.println(xx.Curlabel());
}
  
}

Sample Output:

middle(2,3)
2
3
middle