In: Computer Science
Create a Java class with the name (identifier) MyProgram and place it in the Questions package. You will need to create a main method for this class and place all of your code inside of that method. Your program should complete the following steps: - Prompt the user to enter a name for a Student. - Use the Scanner class to read in the user input and store the result in a variable. - Use the Random class to generate a random number (1 – 99999) and store it in a variable. - Create 3 int variables and assign them values of your choosing in the range 0 – 100. - Use the variables you created in the previous steps to instantiate (construct) a Student object where the user input you read is the student’s name, the random number is the student’s ID, and the 3 int variables you created are the student’s exam scores. - Print out the student’s details. You can do this by using the Student object reference as an argument in a println method call. - Run your program to make sure it works correctly.
CODE IN JAVA:
MyProgram.java file:
import java.util.*;
public class MyProgram {
   String name;
   int id;
   int score1;
   int score2;
   int score3;
   MyProgram(String name,int id,int score1,int score2,int
score3){
       this.name = name;
       this.id = id ;
       this.score1 = score1;
       this.score2 = score2;
       this.score3 = score3;
   }
   void print() {
       System.out.println("Student
Name:"+this.name);
       System.out.println("Student
Id:"+this.id);
       System.out.println("Student
Score1:"+this.score1);
       System.out.println("Student
Score2:"+this.score2);
       System.out.println("Student
Score3:"+this.score3);
   }
   public static void main(String[] args) {
      
       Scanner sc = new
Scanner(System.in);
       Random r = new Random();
       System.out.print("Enter the name of
the student:");
       String name = sc.nextLine();
       int id = r.nextInt(100000);
       int score1 = r.nextInt(100);
       int score2 = r.nextInt(100);
       int score3 = r.nextInt(100);
       MyProgram my = new
MyProgram(name,id,score1,score2,score3);
       my.print();
   }
}
OUTPUT:
