Question

Draw the UML DIAGRAM ALSO

For this task you will create a Point3D class to represent a point that has coordinates in three dimensions labeled x, y and

Subject Outline Write a TestPoint3D class that will have a main method, and perhaps other methods as required by good design,

PLEASE DRAW THE UML DIAGRAM.ALSO

in java

should use the program in java

For this task you will create a Point3D class to represent a point that has coordinates in three dimensions labeled x, y and z. You will then use the class to perform some calculations on an array of these points. You need to draw a UML diagram for the class (Point3D) and then implement the class The Point3D class will have the following state and functionality: Three data fields, x, y and z, of type double, represent the point's coordinates Additional data field, colour, of type String, A no-arg constructor creates a point at . Another constructor creates a point with A getter method is provided for each of the represents the point's color position (0, 0, 0) and "Red" colour. specified coordinates and colour. fields. An accessor method named distance returns the distance between the current point and another point passed as an argument. The distance method is overloaded to accept the coordinates of the other point.
Subject Outline Write a TestPoint3D class that will have a main method, and perhaps other methods as required by good design, to test your Point3D class. It will not have user input because this class will stand as a record of the tests you have applied and you will be able to run it whenever you alter your Point3D class. For the TestPoint3D class you will need to do the following: . Test the basic state and functionality of the Point3D class. Each of the constructors and each of the methods should be tested using some different data values. The test code should display values so that they can be checked. Write some code to create an array of at least 10 Point3D objects. Write a method max, which will accept the array of points as an argument, and will calculate and display the maximum distance between the points in the array, and the pair of points for which the maximum occurs. . Write a method min, which will accept the array of points as an argument, and will calculate and display the minimum distance between the points in the array, and the pair of points for which the minimum occurs. You need to submit java and class files, a short discussion to explain the logic on how the problem has been solved, UML diagram, and sample output (for detail please see marking guide and
1 0
Add a comment Improve this question Transcribed image text
Answer #1

/******************************Point3D.java******************************/


public class Point3D {

   /*
   * data field
   */
   private double x;
   private double y;
   private double z;
   private String color;

   /*
   * no argument constructor
   */
   public Point3D() {

       this.x = 0.0;
       this.y = 0.0;
       this.z = 0.0;
       this.color = "RED";
   }

   /**
   *
   * @param x
   * @param y
   * @param z
   * @param color
   */
   public Point3D(double x, double y, double z, String color) {
       super();
       this.x = x;
       this.y = y;
       this.z = z;
       this.color = color;
   }

   public double getX() {
       return x;
   }

   public double getY() {
       return y;
   }

   public double getZ() {
       return z;
   }

   public String getColor() {
       return color;
   }

   public double distance(Point3D point) {

       return Math.sqrt(Math.pow(this.x - point.x, 2) + Math.pow(this.y - point.y, 2) + Math.pow(this.z - point.z, 2));
   }

   public double distance(Point3D point1, Point3D point2) {

       return Math.sqrt(
               Math.pow(point1.x - point2.x, 2) + Math.pow(point1.y - point2.y, 2) + Math.pow(point1.z - point2.z, 2));
   }

   @Override
   public String toString() {
       return "[" + x + "," + y + "," + z +"]";
   }
  
  
}
/**********************************TestPoint3D.java*************************************/


public class TestPoint3D {

   public static void main(String[] args) {

       Point3D[] points = new Point3D[10];

       /*
       * creating 10 objects of Point3D
       */
       points[0] = new Point3D();
       points[1] = new Point3D(1.0, 1.0, 1.0, "Blue");
       points[2] = new Point3D(2.0, 3.0, 4.0, "Blue");
       points[3] = new Point3D(1.0, 5.0, 5.0, "Blue");
       points[4] = new Point3D(1.0, 3.0, 1.0, "Blue");
       points[5] = new Point3D(1.0, 5.0, 1.0, "Blue");
       points[6] = new Point3D(1.0, 9.0, 15.0, "Blue");
       points[7] = new Point3D(21.0, 14.0, 19.0, "Blue");
       points[8] = new Point3D(13.0, 13.0, 10.0, "Blue");
       points[9] = new Point3D(51.0, 31.0, 18.0, "Blue");

       /*
       * check the distance function
       */
       System.out.printf("The distance between points is:%.2f ", points[1].distance(points[2]));
       System.out.printf("\nThe distance between two points is:%.2f ", points[1].distance(points[2], points[3]));

       /*
       * calling method max and min
       */
       max(points);
       min(points);

   }

   /*
   * to calculate max distance between points call distance(point1, point2) assign
   * maxDistance to max value of double then compare each value of distance with
   * maxDistance if greater than then assign it to maxDistance and assign points
   * to point1, and point2
   */

   private static void max(Point3D[] points) {

       double maxDistance = Double.MIN_VALUE;
       Point3D point1 = null;
       Point3D point2 = null;
       for (int i = 0; i < points.length; i++) {

           for (int j = i + 1; j < points.length; j++) {

               double distance1 = points[0].distance(points[i], points[j]);
               if (distance1 > maxDistance) {

                   maxDistance = distance1;
                   point1 = points[i];
                   point2 = points[j];

               }
           }
       }

       System.out.printf("\n\nThe max distance is %.2f ", maxDistance);
       System.out.println("\nThe Points pair is : " + point1.toString() + " and " + point2.toString());
   }

   /*
   * to calculate minimum distance between points call distance(point1, point2)
   * assign minDistance to max value of double then compare each value of distance
   * with maxDistance if less than then assign it to minDistance and assign points
   * to point1, and point2
   */
   private static void min(Point3D[] points) {
       double minDistance = Double.MAX_VALUE;
       Point3D point1 = null;
       Point3D point2 = null;
       for (int i = 0; i < points.length; i++) {

           for (int j = i + 1; j < points.length; j++) {

               double distance1 = points[0].distance(points[i], points[j]);
               if (distance1 < minDistance) {

                   minDistance = distance1;
                   point1 = points[i];
                   point2 = points[j];

               }
           }
       }

       System.out.printf("\nThe min distance is %.2f ", minDistance);
       System.out.println("\nThe Points pair is : " + point1.toString() + " and " + point2.toString());
   }

}
/************************output**********************************/

The distance between points is:3.74
The distance between two points is:2.45

The max distance is 62.34
The Points pair is : [0.0,0.0,0.0] and [51.0,31.0,18.0]

The min distance is 1.73
The Points pair is : [0.0,0.0,0.0] and [1.0,1.0,1.0]

Console X <terminated> TestPoint3D [Java Application] C:\Program FilesJava\ire1.8.0 131binljav The distance between points is

Point3D + x: double + y double + z: double + color: String + Point3D () + Point3D (x,y,z,color) + getX(): return x + getY ():

You can edit this uml here

https://creately.com/diagram/jvk9vzzr2/pb0qC7SjCEMev9CXJNmTxw0iZs%3D

Please let me know if you have any doubt or modify this answer, Thanks :)

Add a comment
Know the answer?
Add Answer to:
Draw the UML DIAGRAM ALSO PLEASE DRAW THE UML DIAGRAM.ALSO in java should use the program in java For this task you will create a Point3D class to represent a point that has coordinates in thr...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design a class named MyPoint to represent a point with x and y-coordinates. The class contains:...

    Design a class named MyPoint to represent a point with x and y-coordinates. The class contains: Two data fields x and y that represent the coordinates. . A no-arg constructor that creates a point (0, 0) .A constructor that constructs a point with specified coordinates. Two get functions for data fields x and y, respectively. A function named distance that returns the distance from this point to another point of the MyPoint type Write a test program that creates two...

  • NEEDS TO BE IN PYTHON: (The Point class) Design a class named Point to represent a...

    NEEDS TO BE IN PYTHON: (The Point class) Design a class named Point to represent a point with x- and y-coordinates. The class contains: - Two private data fields x and y that represent the coordinates with get methods. - A constructor that constructs a point with specified coordinates, with default point (0, 0). - A method named distance that returns the distance from this point to another point of the Point type. - A method named isNearBy(p1) that returns...

  • Inheritance Problem: (C++) (The MyPoint class) Design a class named MyPoint to represent a point with...

    Inheritance Problem: (C++) (The MyPoint class) Design a class named MyPoint to represent a point with x-and y-coordinates. The class contains: Two data fields x and y that represent the coordinates. A no-arg constructor that creates a point (0, 0). A constructor that constructs a point with specified coordinates using passed in arguments. Two get functions for data fields x and y, respectively. A method named distance that returns the distance from this point to another point of the MyPoint...

  • Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance...

    Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance variables x and y that represented for the coordinates for a point. Provide constructor for initialising two instance variables. Provide set and get methods for each instance variable, Provide toString method to return formatted string for a point coordinates. 2. Create class Circle, its inheritance from Point. Provide a integer private radius instance variable. Provide constructor to initialise the center coordinates and radius for...

  • In this assignment, you will implement Address and Residence classes. Create a new java project. Part...

    In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...

  • Given the following construct a UML diagram for Java: Design a class named location for locating...

    Given the following construct a UML diagram for Java: Design a class named location for locating a maximal value and its location in a two-dimensional array. The class contains public data fields row, column, and maxValue that store the maximum value and its indices in a two-dimensional array with row and column as int types and maxValue as double type. Write the following method that returns the location of the largest element in two-dimensional array: Public static Location locateLargest(double[][] a)...

  • 1. Please write the following program in Python 3. Also, please create a UML and write...

    1. Please write the following program in Python 3. Also, please create a UML and write the test program. Please show all outputs. (The Fan class) Design a class named Fan to represent a fan. The class contains: Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denote the fan speed. A private int data field named speed that specifies the speed of the fan. A private bool data field named on that specifies...

  • JAVA design a class named Rectangle to represent a rectangle. The class contains: A method named getPerimeter() that returns the perimeter. Two double data fields named width and height that specify...

    JAVA design a class named Rectangle to represent a rectangle. The class contains: A method named getPerimeter() that returns the perimeter. Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. A no-arg constructor that creates a default rectangle. A constructor that creates a rectangle with the specified width and height. A method named getArea() that returns the area of this rectangle. design...

  • Please help me with this code. Thank you Implement the following Java class: Vehicle Class should...

    Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? 3. Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT