Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class Student { private int cin; private double gpa; public Student(int c

ID: 3827085 • Letter: P

Question

public class Student {
private int cin;
private double gpa;
public Student(int cin, double gpa) {
super();
this.cin = cin;
this.gpa = gpa;
}

public String toString(){
return "Student # " + cin + " has GPA of " + gpa;
}
}

in java

Write a CourseRoll class with an array list (not an array) of Students, an int field called nextCin, a reference to a Simulator (studentDriver class), and an instance method called offerClass(). OfferClass() uses the Simulator to get an array of 30 random Doubles from a Gaussian distribution that will be used to simulate GPAs. call getgaussianData() using arguments that are reasonable for GPAs (min of 2.0, max of 4.0, etc.) OfferClass() must instantiate 30 Students and add them to the list by calling Student's constructor from inside a loop. Each time you call the constructor, send nextCin and the next value in the array of doubles. Increment nextCIN each time, so that the first student's CIN is 1 and the last student's is 30. After you have created the list, use a loop to print out the data (from toString()) on each Student in the list. The first few lines of output should look like this:

Student # 1 has GPA of 4.0
Student # 2 has GPA of 3.77674628
Student # 3 has GPA of 3.66734843762

Explanation / Answer

package com.student;

public class Student {
  
   private int cin;
   private double gpa;
  
   public Student(int cin, double gpa) {
       super();
       this.cin = cin;
       this.gpa = gpa;
   }
  
   public String toString(){
   return "Student # " + cin + " has GPA of " + gpa;
   }
}

package com.student;

import java.util.ArrayList;

public class CourseRoll {
   private int nextCin;
   private StudentDriver simulator;
   private ArrayList<Student> arr;
  
   public void offerClass(){
       double[] guassianArr = new double[30];
       simulator = new StudentDriver();
       for(int i=0;i<30;i++){
           guassianArr[i] = simulator.getgaussianData(2, 4);
       }
       arr = new ArrayList<Student>(30);
       for(nextCin=1;nextCin<=30;nextCin++){
           Student obj = new Student(nextCin, guassianArr[nextCin-1]);
           arr.add(obj);
       }
   }

   public static void main(String args[]){
       CourseRoll cr = new CourseRoll();
       cr.offerClass();
       for(int i=0; i<30; i++){
           System.out.println(cr.arr.get(i).toString());
       }
   }

}

package com.student;

import java.util.Random;

public class StudentDriver {

   public double getgaussianData(int min, int max){
       Random r = new Random();
       double res = r.nextGaussian() + min; // standard mean is min
       res = res < 0 ? res * -1 : res; // if the value goes negative make it positive
       res = res > max ? res - max : res; // if values goes beyond max, drag it back
       return res;
   }

}

A Sample output from my eclipse:

Student # 1 has GPA of 1.0460675866537508
Student # 2 has GPA of 1.162478401803566
Student # 3 has GPA of 1.088201862857301
Student # 4 has GPA of 1.4969975863384346
Student # 5 has GPA of 1.6207601399067229
Student # 6 has GPA of 0.4844343082267377
Student # 7 has GPA of 1.81159015130395
Student # 8 has GPA of 2.24597738991814
Student # 9 has GPA of 1.1458315467581397
Student # 10 has GPA of 2.6920133495973393
Student # 11 has GPA of 1.3151795287065504
Student # 12 has GPA of 1.4791892738291867
Student # 13 has GPA of 3.169476657525699
Student # 14 has GPA of 2.630932909990622
Student # 15 has GPA of 1.0508938067352873
Student # 16 has GPA of 2.0311692069444405
Student # 17 has GPA of 0.8554440676713093
Student # 18 has GPA of 1.022823813638266
Student # 19 has GPA of 1.0750227940553965
Student # 20 has GPA of 1.7733930885500004
Student # 21 has GPA of 1.8054921227986953
Student # 22 has GPA of 3.220231190962056
Student # 23 has GPA of 1.2938673749432477
Student # 24 has GPA of 3.2355861376758233
Student # 25 has GPA of 0.5146127992063294
Student # 26 has GPA of 2.423871960078286
Student # 27 has GPA of 0.08353016591453066
Student # 28 has GPA of 1.9852425007996863
Student # 29 has GPA of 1.4430596702759932
Student # 30 has GPA of 2.0471800487946137

INSTRUCTIONS:

1. Open Eclipse, create a java project

2. create three classes with those names with package as 'com.student'

3. Run CourseRoll.java as Java Application...