Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design a class named Point3D. The class represents a 3-dimensional point at coordinates (x, y, z). The coordinates are represented as integers which can be

Design a class named Point3D. The class represents a 3-dimensional point at coordinates (x, y, z). The coordinates are represented as integers which can be negative, zero, or positive. Your class should contain:

Private data fields necessary to represent the coordinates x, y, and z.

A default constructor which accepts no parameters and initializes the instance variables to 0, 0, 0.

A constructor that creates a 3D point using three integer parameters passed to the constructor. Your parameters should be named using the same names as the instance variables and should use the "this" keyword as described in the lecture slides to set the instance variables.

Public accessors which return the x,y, and z values. Use the names of the instance variables in conjunction with "get" to name them. They should take no parameters and return int (the same data type as the instance variables).

Public mutators which modify the x, y, and z values. Your parameters should be named using the same names as the instance variables and should use the "this" keyword as described in the lecture slides to set the instance variables. Use the names of the instance variables in conjunction with "set" to name them. Remember that mutators return void and take a single parameter of the same data type as the instance variable they are modifying.

A method named setCoords which accepts three integer parameters representing the x, y, and z coordinates and sets the associated instance variables. Your parameters should be named using the same names as the instance variables and should use the "this" keyword as described in the lecture slides to set them.

A method named toString which returns the values of all three coordinates as a comma-separated String. This method takes no parameters and does not display any output.

Note: no import statements are required for this assignment (do not use the JavaFX example used in the lecture slides).

Use the following main method in your Point3D class to test your class (do not modify this code):

public static void main(String[] args) { // create various Point3D objects Point3D p1 = new Point3D(1, 2, 3); Point3D p2 = new Point3D(2, 3, 4); // Test the methods of Point3D System.out.println("p1 toString = " + p1.toString()); System.out.println("p2 accessors = " + p2.getX() + "," + p2.getY() + "," + p2.getZ()); p1.setCoords(10, 20, 30); System.out.println("p1 setCoords = " + p1.toString()); p2.setX(50); p2.setY(60); p2.setZ(70); System.out.println("p2 toString = " + p2.toString()); }

Your submission should consist of a single .java file named Point3D.java.

Expected Output:

p1 toString = 1,2,3

p2 accessors = 2,3,4

p1 setCoords = 10,20,30

p2 toString = 50,60,70

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago