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

In JAVA please Using as reference the design model below, write the java code fo

ID: 3732840 • Letter: I

Question

In JAVA please

Using as reference the design model below, write the java code for the implementation of the classes Point2D and Point3D Point2D x:float -0.0f y:float 0.0f +Point2D(x:float,y:float) +Point2D() +getx():float +setX(x:float) void tgety():float +setY(y:float) void setx(x:float,y:float): void +getXY):float[2] +toStrine):Strine"(x,y) Array of (x,yj extends Point3D z:float 0.0f +Point3D(x:float,y:float,z:float) +Point3D) tgetZ):float +setZ(z: flaot) void +setXYZ(x:float,y:flaot,z:float):voidArray of tx,y,z) +getXYZ():float[3] +toString ():String Concepts in practice: Classes and objects, Inheritance, UML.

Explanation / Answer

import java.util.*;

//Class Point2D definition.

class Point2D{

private

float x;

float y;

public

//Parametrised constructor

Point2D(float x,float y){

this.x = x;

this.y = y;

}

//Default constructor

Point2D(){

this.x=0.0f;

this.y=0.0f;

}

//getter function to get x

float getX(){

return this.x;

}

//setter function to set x

void setX(float x){

this.x = x;

}

//getter function to get y

float getY(){

return this.y;

}

//setter function to set y

void setY(float y){

this.y = y;

}

//getter function to get value of x and y

float[] getXY(){

float arr[] = new float[2];

arr[0]=this.x;

arr[1]=this.y;

return arr;

}

//setter function to set value of x and y

void setXY(float x,float y){

this.x = x;

this.y = y;

}

@Override

public String toString(){

String str1,str2;

str1 = Float.toString(getX());

str2 = Float.toString(getY());

return str1+" "+str2;

}

}

//Derived class definition

class Point3D extends Point2D{

private

float z;

public

//Parametrised constructor

Point3D(float x,float y,float z){

setXY(x,y);

this.z = z;

}

//Default constructor

Point3D(){

setXY(0.0f,0.0f);

this.z = 0.0f;

}

//getter function to get value of z

float getZ(){

return this.z;

}

//setter function to set value of z

void setZ(float z){

this.z = z;

}

//getter function to get value of x,y and z

float[] getXYZ(){

float arr[] = new float[3];

arr[0]=getX();

arr[1]=getY();

arr[2]=this.z;

return arr;

}

//setter function to get value of x,y and z

void setXYZ(float x,float y,float z){

setXY(x,y);

this.z = z;

}

@Override

public String toString(){

String str1,str2,str3;

str1 = Float.toString(getX());

str2 = Float.toString(getY());

str3 = Float.toString(getZ());

return str1+" "+str2+" "+str3;

}

}

//Tester class

public class Main

{

public static void main(String[] args) {

Point2D p2 = new Point2D(2.0f,3.5f);

Point3D p3 = new Point3D(-1.0f,2.9f,4.3f);

System.out.println("x = "+p2.getX()+" y = "+p2.getY());

System.out.println("x = "+p3.getX()+" y = "+p3.getY()+" z = "+p3.getZ());

p2.setXY(20.0f,30.5f);

p3.setXYZ(-10.0f,20.9f,40.3f);

System.out.println(p2.toString());

System.out.println(p3.toString());

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote