i have to write this program
1) A “MyNum” class that will generate a random integer number from 1 to 200.
2) A “Time” class that will return the system time with sufficient resolution to show the time between insertions. I suggest System.nanoTime().
3) A “Node” class that will encapsulate the integer number and the Time it was generated.
4) And a “Storage class” class that will contain the all the SORTED Nodes using an insertion sort.
a. This class should have a “add” method to add in each node.
b. And method(s) so the driver class may display the sorted list of nodes
5) The “main” or driver class.
So far i have written MyNum class and Time i am stuck on the Node class. When i run it, it only gives me the random number it does not give me the time it took for it to generate.
Node Class
HTML Code:class Node { private long time; private int num; public Node (){ num=MyNum.genRandom(); time = Time.time(); } public String toString (){ return "Number" + num + "Time" + time; } }
Time CLASS
Random NumberHTML Code:public class Time { public static long time(){ return System.nanoTime(); } }
HTML Code:import java.util.Random; public class MyNum { static Random number = new Random(); public static void main(String[] args) { for (int i =0; i < 1 ; i++) { System.out.println( genRandom()); } } public static int genRandom(){ return number.nextInt(200); } }