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

(JAVA) : Write a class called Student. This class should have the following data

ID: 3677111 • Letter: #

Question

(JAVA) : Write a class called Student. This class should have the following data members: * Number of Students *First Name * Last Name * College ID * GPA * "Alpha" 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 isValidAlphaLogin to check that what they entered is actually a valid Alpha login. As you recall, the Alpha 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 Alpha Login. j) Iterate through the array of objects and call the isValidAlphaLogin method to display whether each student’s Alpha Login is valid using this format: Student ’s Alpha Login is . If you did not make a mistake during the instantiation of each Student object, you should be getting all valid Alpha 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

Explanation / Answer

Hi, I have created all basic class and functionality.

you have to add only last two part because i do not have all info.

public class Student {
  
   private String firstName;
   private String lastName;
   private long collegeId;
   private double gpa;
   private String alphaLoginId;
  
   private static int numberOfStudents;

   public Student(String firstName, String lastName, long collegeId,
           double gpa, String alphaLoginId) {
       super();
       this.firstName = firstName;
       this.lastName = lastName;
       this.collegeId = collegeId;
       this.gpa = gpa;
       this.alphaLoginId = alphaLoginId;
       numberOfStudents++;
   }
  
   public static int getNumberOfStudents(){
       return numberOfStudents;
   }
  
   public double getGpa(){
       return gpa;
   }
  
   public boolean isValidAlphaLogin(){
       String loginId = "";
       loginId = loginId + lastName.substring(0, 2);
       loginId = loginId + firstName.substring(0, 2);
       // converting college id into string
       String s = String.valueOf(collegeId);
       int length = s.length();
       loginId = loginId + s.substring(length-5); //getting last 4 digits
      
       if(loginId.equalsIgnoreCase(alphaLoginId))
           return true;
       return false;
   }
  
   public void displayAttributes(){
       System.out.println("Student Name: "+firstName+" "+lastName);
       System.out.println("GPA: "+gpa);
       System.out.println("College ID: "+collegeId);
       System.out.println("Alpha Login ID: "+alphaLoginId);
   }
  
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("How many student want to create: ");
       int n = sc.nextInt();
      
       Student[] student = new Student[n];
      
       // here you have to select random firstName and all otheer info for a student , since i do not have
       // array, so i am taking from user. If you have then you can create student based on randomly
       // picked values
       for(int i=0; i<n; i++){
           System.out.println("Enter details of student "+(i+1));
           System.out.print("First Name: ");
           String firstName = sc.next();
           System.out.print("Last Name: ");
           String lastName = sc.next();
           System.out.print("GPA: ");
           double gpa = sc.nextDouble();
           System.out.print("College ID: ");
           long collegeId = sc.nextLong();
           System.out.print("Aplha Login Id: ");
           String loginId = sc.next();
          
           // creating student
           student[i] = new Student(firstName, lastName, collegeId, gpa, loginId);
       }
      
       // then call isValidAlphaId on each of the student
   }
  
}