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

can somebody please help me out on this java code? I will give great rate. Nl ,

ID: 3569017 • Letter: C

Question



can somebody please help me out on this java code? I will give great rate.

Nl , 4G .ill 13% T 10:03PM 1 The Point class represent a single point at a given co-ordinates(x, y). x and y co-ordinate values are taken as fields of integer type. Below are the signatures of all the Point's methods and its constructors. These are called the interface. You will provide an implementation of this interface, that is, fields and method/constructor bodies The Point class has two constructors. The default constructor initializes both fields to zero. The Parameterized constructor takes two formal parameters of type integer and are used to initialize the fields The Point class has five methods in addition to its constructors. getX takes no parameters and is used to return the value of xco-ordinate getY takes no parameters and is used to return the value of Y co-ordinate setX takes one parameters and is used to set the value of x co-ordinate setY takes one parameters and is used to set the value of Y co-ordinate toString takes no parameters and is used to return the value of x and y co-ordinates as String in the form(x, y) The Point3D class inherits the features of Point class and represent a single 3D point at a given co-ordinates(x, y, z). z co-ordinate value is taken as field of integer type and uses x, y values from its super class. Below are the signatures of all the Point3D's methods and its constructors. These are called the interface. You will provide an implementation of this interface, that is, fields and method/constructor bodies. The Point3Dclass has two constructors, The default constructor calls super class default constructor and initializes field z to zero. The Parameterized constructor takes three formal parameters of type integer and is used to initialize the field z. It also Initializes super class parameterized constructor with x and y values. The Point3D class has three methods in addition to its constructors. getZ takes no parameters and is used to return the value of Z co-ordinate setZ takes one parameter and is used to set the value of Z co-ordinate toString takes no parameters and is used to return the value of x, y and z co-ordinates as String in the form (x, y, z) Provide appropriate comments in all your classes, using java doc documentation style. Create your own testing class TestPoint3D that has a public static void main (String [ args)

Explanation / Answer

public class Point{

   int x;
   int y;

    public Point()
   {
    x=0;
    y=0;
   }

   public Point(int a, int b)
   {
    x=a;
    y=b;
   }

   public void setX(int a)
   {
    x=a;
   }

   public void setY(int a)
   {
    y=a;
   }
   public int getX()
   {
    return x;
   }
   public int getY()
   {
    return y;
   }
   public String toString()
   {
    return "("+Integer.toString(x)+" , "+Integer.toString(y)+")";
   }
}

//=======================//

public class Point3D extends Point{

   int z;
   public Point3D()
   {
     super();
     z=0;
   }
   public Point3D (int a, int b, int c)
   {
      super(a,b);
      z=c;
    }
    public void setZ(int a)
   {
      z=a;
   }

   public int getZ()
   {
       return z;
   }
   public String toString()
   {
      return "("+Integer.toString(x)+" , "+Integer.toString(y)+" , "+Integer.toString(z)+")";
   }
}

public class TestPoint3D {

public static void main(String[] args)

{

System.out.println("Point");

System.out.println("--------------------");;

Point point=new Point(1,2);

System.out.println(point);

System.out.println("--------------------");

System.out.println("Point3D");

System.out.println("--------------------");

Point3D p1=new Point3D(1,2,3);

System.out.println(p1);

System.out.println("x :"+p1.getX());

System.out.println("y :"+p1.getY());

System.out.println("z :"+p1.getZ());

p1.setX(4);

p1.setY(5);

p1.setZ(6);

System.out.println(p1);

}

}

Dr Jack
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote