Question

a) A class Point3D is given. Re-write this class so that it meets the requirements for storage in our HashList<E> container T

skeleton:

import java.util.*;
public class Point3D{
private int x,y,z;

Point3D(int a, int b, int c){
x = a; y = b; z = c;
}

public int x(){
return x;
}

public int y(){
return y;
}

public int z(){
return z;
}

public String toString(){
return "("+x+","+y+","+z+")";
}
}


Question1Test.java

import java.util.*;
public class Question1Test {
public static void main(String[] args){
MyHashList<Point3D> lst = new MyHashList<Point3D>(1000);
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

The problem has been resolved. I have modified the "Point3D" class and "Question1Test" class for testing. You have not mentioned MyHashList class so I have not completed the Generic part of the code but I have tested this code on 10,000 recoreds. I'm getting radom value of x,y,z and creating objects and adding them to a arraylist because you have not given me this MyHashList class. After that the method "printEqualPoints" will print equals point.

When you want to read this code just change the number of time from 10000 to 100 and this maximum value of radom from 100 to 5 and uncomment the code. Then you will find the solution.

((int) (Math.random()*(100 - 1))) + 1 ->  ((int) (Math.random()*(5 - 1))) + 1

I'm attaching the running code screenshot for better understanding.

Screenshot:

Code:

-------------------------------

Point3D.class

------------

import java.util.*;
public class Point3D{
private int x,y,z;

Point3D(int a, int b, int c){
x = a; y = b; z = c;
}

public int getX(){
return x;
}

public int getY(){
return y;
}

public int getZ(){
return z;
}

public void setX(int a){
   this.x=a;
}
public void setY(int b){
   this.y=b;
}
public void setZ(int c){
   this.z=c;
}

public String toString(){
return "("+x+","+y+","+z+")";
}

}

------------

Question1Test.class

----------------

import java.util.*;
public class Question1Test {
   public static void main(String[] args){
   List<Point3D> list = new ArrayList<Point3D>(10000);

   Random random = new Random();

   for(int i=0;i<10000;i++){
       int a= ((int) (Math.random()*(100 - 1))) + 1;
       int b= ((int) (Math.random()*(100 - 1))) + 1;
       int c= ((int) (Math.random()*(100 - 1))) + 1;
       //System.out.println("a: "+a+" b: "+b+" c: "+c);

       list.add(new Point3D(a,b,c));
      
   }

   printEqualPoints(list);
  

   }

   static void printEqualPoints(List<Point3D> list){
       //System.out.println("here: "+list.size());
       for(int i=0;i<list.size();i++){
           Point3D obj1= list.get(i);

           for(int j=i;j<list.size();j++){
              
               Point3D obj2= list.get(j);

               //System.out.println(obj1.toString()+" -> "+obj2.toString());

               if(i!=j && obj1.getX()==obj2.getX() && obj1.getY()==obj2.getY() && obj1.getZ() == obj2.getZ()){

                   System.out.println("Point "+i+" and "+j+" are equal");
                   break;
               }

           }
       }
   }
}

----------------

------------------------------

The problem has been resolved, I hope you will like the solution. If you have any question or query regarding this problem or other, please comment below and give the positive rating.

Thank You!! Happy Learning!! !!

Add a comment
Know the answer?
Add Answer to:
skeleton: import java.util.*; public class Point3D{ private int x,y,z; Point3D(int a, int b, int c){ x = a; y = b; z = c; } public int x(){ return x; } public int y(){ return y; } public in...
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
  • import java.util.*; public class Movie {    private String movieName; private int numMinutes; private boolean isKidFriendly;...

    import java.util.*; public class Movie {    private String movieName; private int numMinutes; private boolean isKidFriendly; private int numCastMembers; private String[] castMembers;    // default constructor public Movie() { movieName = "Flick"; numMinutes = 0; isKidFriendly = false; numCastMembers = 0; castMembers = new String[10]; }    // overloaded parameterized constructor public Movie(String movieName, int numMinutes, boolean isKidFriendly, String[] castMembers) { this.movieName = movieName; this.numMinutes = numMinutes; this.isKidFriendly = isKidFriendly; numCastMembers = castMembers.length; this.castMembers = new String[numCastMembers];    for(int i=0;i<castMembers.length;i++)...

  • public class Point f private int x; private int y; public Point(int x, int y) this.x...

    public class Point f private int x; private int y; public Point(int x, int y) this.x X; this.y y; public int getX() return x; public int getY() return Y: public double distance (Point other) double dx this.x-other.x; double dy this.y-other.y double dist Math.sqrt(dx dx + dy dy); return dist;

  • Question 19 Given the following class: public class Swapper ( private int x; private String y...

    Question 19 Given the following class: public class Swapper ( private int x; private String y public int z; public Swapper( int a, String b, int c) ( x-a; y b; zC; public String swap() ( int temp -x; x-z z temp; return y: public String tostring() ( if (x<z) return y: else return" +x+z What would the following code output? Swapper r new Suapper( 5, "no", 10); System.out.printin( r. swap ) ): no no510 510 e 15 Question 20...

  • c++ please Given the following skeleton of an unsorted list class that uses an unsorted linked...

    c++ please Given the following skeleton of an unsorted list class that uses an unsorted linked list: template<class ItemType> struct NodeType {                 ItemType item;                 NodeType* next; }; template<class ItemType> class UList { public:                 UList(); // default constrctor                 UList(const UList &x); // we implement copy constructor with deep copy                 UList& operator = (UList &x); // equal sign operator with deep copy                 bool IsThere(ItemType item) const; // return true of false to indicate if item is...

  • In the following program: public  class Problem2{     public static int sample(int x, int y){         int z;         .........

    In the following program: public  class Problem2{     public static int sample(int x, int y){         int z;         ......      }     public static void  main(String[] args)     {          int a, b;          ......          sample(a,b);     } } (1) What is the return type of sample? (2) What are the local variables of sample? (3) What are the parameters of sample? (4) What are the arguments of sample? (5) Is sample a per-object method? Or a per-class method? (6) Is sample a public method, or private method?

  • P1 is below package p6_linkedList; import java.util.*; public class LinkedList { public Node header; public LinkedList()...

    P1 is below package p6_linkedList; import java.util.*; public class LinkedList { public Node header; public LinkedList() { header = null; } public final Node Search(int key) { Node current = header; while (current != null && current.item != key) { current = current.link; } return current; } public final void Append(int newItem) { Node newNode = new Node(newItem); newNode.link = header; header = newNode; } public final Node Remove() { Node x = header; if (header != null) { header...

  • package simple; import java.awt.Frame; public class Scrubby extends Frame { int y; public Scrubby() { f(15);...

    package simple; import java.awt.Frame; public class Scrubby extends Frame { int y; public Scrubby() { f(15); } int f(int x) { return x+y; } } the cross-reference tool generates the following report: e:/test/ # java JavaXref simple Parsing... e:\test\simple\Scrubby.java Resolving types... resolving: simple.Scrubby Writing report... Cross Reference Report ====================== A Java Cross-Reference Tool A Java Cross-Reference Tool 3 sur 13 Package: simple ----------------------------------------- simple.Scrubby (Class) [Scrubby.java:5] Superclass: Frame [Scrubby.java:3] Imported classes/packages: Frame simple.Scrubby.~constructor~ (Method) [Scrubby.java:8] simple.Scrubby.y (Variable) [Scrubby.java:6] Type: int...

  • In C++, A point class has the following definition: class Point{ private: int x; int y;...

    In C++, A point class has the following definition: class Point{ private: int x; int y; public: Point(int, int); A vector has two points as a start point (x,y) and end point (x,y). Write the header file and implementation file of the Vector class containing constructor, other functions, and also a function returning length of Vector determined from start point and end point coordinates. Write also the client code.

  • Given the following class: class Q2 { private int a; private int b; private int c;...

    Given the following class: class Q2 { private int a; private int b; private int c; public void setA(int a){this.a = a; } public void setB(int b){this.b = b;} public void setc(int c){this.c = c;} public int geta(){return a; } public int gets(){return b;} public int getc(){return c;} public int m1(int a, int b){ return a + b; public boolean m2 (int x, int y){ return m1(x, y) + x + y < 10; What is the output of the...

  • Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class...

    Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class Delete extends Info { String name; int Id; int del; public Delete() { } public void display() { Scanner key = new Scanner(System.in); System.out.println("Input Customer Name: "); name = key.nextLine(); System.out.println("Enter ID Number: "); Id = key.nextInt(); System.out.println("Would you like to Delete? Enter 1 for yes or 2 for no. "); del = key.nextInt(); if (del == 1) { int flag = 0; //learned...

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