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

Basically I have to Write a class called Student. the class must have the follow

ID: 3677318 • Letter: B

Question

Basically I have to Write a class called Student.
the class must have the following data members:
**Number of Students
**First Name
** Last Name
**College ID
** GPA
**Venus Login ID
Remember to name them appropriately and use lower camel case. eg. First Name = firstName.
b) Write a constructor for your class that accepts all the values listed above and initialize your object appropriately. Your
constructor needs to increment the static value Number of Students each time an instantiation occurred so that you can
keep track of the students at any given time.
c) Write a static method that will return the number of students.
d) Write a method called getGPA that will return the student’s GPA.
e) Write a Boolean method called isValidVenusLogin to check that what they entered is actually a valid Venus login. As
you recall, the Venus login has to be in this format: lafi1234 (First two characters of your last name, first two characters
of your first name and your last 4 digits of your College ID).
Hint: Use the Java String API to achieve this.
f) Write a print method called displayAttributes that will output all non-static attribute values. So, for example, you
should have something like this:
System.out.println(“Student Name: ” + First Name + “ “ + Last Name);
System.out.println(“GPA: ” + GPA);
g) Create an array of type Student with n objects inside your main. (Use JOptionPane to ask user to tell you how many
Student objects you need to instantiate.)
h) Iterate through the array and use proper constructor to instantiate and populate values for each of your student.
i) Use Math.random() to select from a list of predetermined array values dynamically to select a name for each student. For
example, you would have an array called firstNames that has the values {“Bob”, “Mary”, “Peter”} and lastNames =
{“Peterson”, “Reich”, “Jackson”} etc.
Randomly select the first name and last names for each student during your instantiation as well as for your GPA, College
ID, and Venus Login.
j) Iterate through the array of objects and call the isValidVenusLogin method to display whether each student’s Venus
Login is valid using this format:
Student <FirstName + LastName>’s Venus Login is <Valid/Invalid>.
If you did not make a mistake during the instantiation of each Student object, you should be getting all valid Venus login.
k) Iterate through the array of objects and call the displayAttributes Method that you have created in (f) to display
each student’s attributes.
l) Call the static method that you have created in c) to get and display the number of students using this format:
The number of students that exists now is <number of students>.

Explanation / Answer

import java.util.Random;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class Student {

   static int numberOfStudents = 0;
   String firstName;
   String lastName;
   int collegeID;
   String GPA;
   String venusLoginID;

   /**
   * @param firstName
   * @param lastName
   * @param collegeID
   * @param gPA
   * @param venusLoginID
   */
   public Student(String firstName, String lastName, int collegeID, String gPA) {

       this.firstName = firstName;
       this.lastName = lastName;
       this.collegeID = collegeID;
       GPA = gPA;
       this.venusLoginID = lastName.substring(0, 2)
               + firstName.substring(0, 2) + collegeID;
       numberOfStudents++;
   }

   /**
   * @return the numberOfStudents
   */
   public static int getNumberOfStudents() {
       return numberOfStudents;
   }

   /**
   * @param gPA
   * the gPA to set
   */
   public void setGPA(String gPA) {
       GPA = gPA;
   }

   /**
   * @return
   */
   public boolean isValidVenusLogin() {

       if (venusLoginID.length() != 8)
           return false;
       String loginID = lastName.substring(0, 2) + firstName.substring(0, 2)
               + collegeID;
       if (loginID.equals(venusLoginID)) {
           return true;
       }
       return false;
   }

   /**
   *
   */
   public void displayAttributes() {

       System.out.println("Student Name: " + firstName + " " + lastName);
       System.out.println("GPA: " + GPA);
   }

   public static void main(String[] args) {

       try {
           JFrame frame = new JFrame("Student Information ");
           String noOfStudents = JOptionPane.showInputDialog(frame,
                   "How many Students ");
           int n = Integer.parseInt(noOfStudents);
           Student students[] = new Student[n];
           String firstNames[] = { "Bob", "Mary", "Peter" };
           String lastNames[] = { "Peterson", "Reich", "Jackson" };

           Random random = new Random();
           for (int i = 0; i < n; i++) {

               int randomNum = random.nextInt(3);
               students[i] = new Student(firstNames[randomNum],
                       lastNames[randomNum], 1234, "A");

           }

           for (int i = 0; i < n; i++) {

               if (students[i].isValidVenusLogin()) {

                   System.out
                           .println("Student " + students[i].firstName
                                   + students[i].lastName
                                   + "’s Venus Login is Valid.");
               } else {

                   System.out
                           .println("Student " + students[i].firstName
                                   + students[i].lastName
                                   + "’s Venus Login is Valid.");
               }

           }
           for (int i = 0; i < n; i++) {

               students[i].displayAttributes();

           }

           System.out.println("The number of students that exists now is "
                   + Student.getNumberOfStudents());

           System.exit(0);
       } catch (Exception e) {
           // TODO: handle exception
       }
   }

}

OUTPUT:

Student PeterJackson’s Venus Login is Valid.
Student MaryReich’s Venus Login is Valid.
Student PeterJackson’s Venus Login is Valid.
Student MaryReich’s Venus Login is Valid.
Student PeterJackson’s Venus Login is Valid.
Student Name: Peter Jackson
GPA: A
Student Name: Mary Reich
GPA: A
Student Name: Peter Jackson
GPA: A
Student Name: Mary Reich
GPA: A
Student Name: Peter Jackson
GPA: A
The number of students that exists now is 5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote