Given the following class: Create a class MyGenerator that can be used in the below main method.
class Random{
public static void main(String [] args){
perform(new MyGenerator());
}
private static abstract class Generator {
protected abstract double getRandom();
}
public static void perform(T g){
System.out.println(g.getRandom());
}
}

Respuesta :

Answer:

Explanation:

The below code shows the complete code for the project. we have used Math.random() as a means of generating a random double value in the getRandom() method since it is not specified.

class Random {

          [tex]\ \ \ \ \ \ \ \ \mathbf{ public \ static \ void \ main \ (String[] \ args) \ \ \{}[/tex]

               perform(new MyGenerator());

       }  

           [tex]\mathbf{private \ static \ abstract \ class \ Generator \{ \ }[/tex]

                  [tex]\mathbf{ \ protected \ abstract \ double \ getRandom();}[/tex]

       }  

       public static <T extends Generator> void perform(T g) {

               [tex]\mathbf{System.out.println(g.getRandom());}[/tex]

       }  

       // MyGenerator class inherited from Generator

       public static class MyGenerator extends Generator {

               // implementing abstract method getRandom() of Generator class

               [tex]\mathbf{Override}[/tex]

               [tex]\mathbf{protected \ double \ getRandom() \{ }[/tex]

                       //returning a single double value between 0.0 and 1.0

                       [tex]\mathbf{return \ Math.random();}[/tex]

               }

       }

}

/*OUTPUT (will be random)*/

0.53296649765

RELAXING NOICE
Relax