Question

In: Computer Science

Code an application program that keeps track of student information at your college: names, identification numbers,...

Code an application program that keeps track of student
information at your college: names, identification numbers, and grade

point averages in a fully e ncapsulated (homogeneous) Sorted array-
based data structure. When launched, the user will be asked to input the

maximum size of the data set, the initial number of students, and the
initial data set. Once this is complete, the user will be presented with
the following menu:
Enter: 1 to insert a new student's information,
2 to fetch and output a student's information,
3 to delete a student's information,
4 to update a student's information,
5 to output all the student information in sorted order, and
6 to exit the program.
The program should perform an unlimited number of operations until
the user enters a 6 to exit the program.

Solutions

Expert Solution

1). ANSWER :

GIVENTHAT :

/****************************Student.java************************/

public class Student {

   private String name;
   private String id;
   private double gpa;

   public Student(String name, String id, double gpa) {
       super();
       this.name = name;
       this.id = id;
       this.gpa = gpa;
   }

   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public String getId() {
       return id;
   }

   public void setId(String id) {
       this.id = id;
   }

   public double getgpa() {
       return gpa;
   }

   public void setgpa(double gpa) {
       this.gpa = gpa;
   }

   @Override
   public String toString() {
       return "Name: " + name + "\tID: " + id + "\tGPA: " + gpa;
   }

}
/*********************************StudentInformation.java*************************/

import java.util.Arrays;
import java.util.Collections;

public class StudentInformation {

   private Student[] students;
   private int numberOfStudents;

   public StudentInformation() {
       this.numberOfStudents = 0;
       students = new Student[100];
   }

   public StudentInformation(int numberOfStudent) {
       this.students = new Student[numberOfStudent];
       this.numberOfStudents = 0;
   }

   public Student[] getStudents() {
       return students;
   }

   public void setStudents(Student[] students) {
       this.students = students;
   }

   public int getNumberOfStudents() {
       return numberOfStudents;
   }

   public void setNumberOfStudents(int numberOfStudents) {
       this.numberOfStudents = numberOfStudents;
   }

   public void insertNewStudent(String name, String id, double gpa) {

       students[numberOfStudents] = new Student(name, id, gpa);
       numberOfStudents++;
   }

   public Student fetchStudent(String id) {

       Student st = null;

       for (Student student : students) {

           if (student != null && student.getId().equalsIgnoreCase(id)) {

               st = student;
               break;
           }
       }

       return st;
   }

   public void deleteStudent(String id) {

       int currentLength = students.length;
       for (int i = 0; i < currentLength; i++) {
           if (students[i] != null && students[i].getId().equalsIgnoreCase(id)) {
               students[i] = students[currentLength - 1];
               // employees[currentLength - 1] = null; ... could help reclaim storage
               currentLength--;
               break;
           }

           if (i == currentLength - 1) {
               System.out.println("No Student found with this id!!");
           }
       }
   }

   public void updateStudent(String id, String nameUpdate, double gpa) {

       Student st = fetchStudent(id);

       if (st != null) {
           st.setName(nameUpdate);
           st.setgpa(gpa);
       } else {

           System.out.println("No Student found with this id!!");
       }
   }

   private void sortStudents() {

       Collections.sort(Arrays.asList(students), new StudentComparator());
   }

   public void printAllStudent() {

       try {
           sortStudents();
       } catch (Exception e) {

       }

       for (Student student : students) {

           if (student != null) {

               System.out.println(student.toString());
           }
       }

   }
}

/*********************************StudentComparator.java***************************/

import java.util.Comparator;

public class StudentComparator implements Comparator<Student> {

   @Override
   public int compare(Student o1, Student o2) {

       return o1.getName().compareTo(o2.getName());
   }

}
/******************************************StudentInfoTest.java***************************/

import java.util.Scanner;

public class StudentInfoTest {

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       System.out.print("Enter the number of Student: ");
       int numberOfStudents = scan.nextInt();
       StudentInformation stf = new StudentInformation(numberOfStudents);
       scan.nextLine();
       int option = 0;
       do {

           System.out.println(
                   "Menu:\n\t1. Insert New Student\n\t2. Fetch Student\n\t3. Delete Student\n\t4. Update Student\n\t5. Print All Student\n\t6. Exit");
           System.out.print("Enter your choice: ");
           option = scan.nextInt();
           scan.nextLine();
           switch (option) {
           case 1:
               System.out.print("Enter Student id: ");
               String id = scan.nextLine();
               System.out.print("Enter Student name: ");
               String name = scan.nextLine();
               System.out.print("Enter Student gpa: ");
               double gpa = scan.nextDouble();
               scan.nextLine();
               stf.insertNewStudent(name, id, gpa);

               break;
           case 2:
               System.out.print("Enter student id: ");
               id = scan.nextLine();

               Student st = stf.fetchStudent(id);
               if (st == null) {

                   System.out.println("No Student Found!!");
               } else {
                   System.out.println(st.toString());
               }
               break;
           case 3:
               System.out.print("Enter Student id: ");
               id = scan.nextLine();
               stf.deleteStudent(id);
               break;
           case 4:
               System.out.print("Enter Student id: ");
               id = scan.nextLine();
               System.out.print("Enter Student Name: ");
               name = scan.nextLine();
               System.out.print("Enter Student gpa: ");
               gpa = scan.nextDouble();
               scan.nextLine();

               stf.updateStudent(id, name, gpa);
               break;
           case 5:
               stf.printAllStudent();
               break;
           case 6:
               System.out.println("Thank you!!");
               break;

           default:
               System.out.println("Invalid Choice!!");
               break;
           }

       } while (option != 6);
   }
}
The above program output :

Enter the number of Student: 100
Menu:
   1. Insert New Student
   2. Fetch Student
   3. Delete Student
   4. Update Student
   5. Print All Student
   6. Exit
Enter your choice: 1
Enter Student id: A100
Enter Student name: JKS
Enter Student gpa: 9.43
Menu:
   1. Insert New Student
   2. Fetch Student
   3. Delete Student
   4. Update Student
   5. Print All Student
   6. Exit
Enter your choice: 1
Enter Student id: B101
Enter Student name: Virat Kohli
Enter Student gpa: 8.45
Menu:
   1. Insert New Student
   2. Fetch Student
   3. Delete Student
   4. Update Student
   5. Print All Student
   6. Exit
Enter your choice: 1
Enter Student id: MS Dhoni
Enter Student name: DD
Enter Student gpa: 6.6
Menu:
   1. Insert New Student
   2. Fetch Student
   3. Delete Student
   4. Update Student
   5. Print All Student
   6. Exit
Enter your choice: 5
Name: DD   ID: MS Dhoni   GPA: 6.6
Name: JKS   ID: A100   GPA: 9.43
Name: Virat Kohli   ID: B101   GPA: 8.45
Menu:
   1. Insert New Student
   2. Fetch Student
   3. Delete Student
   4. Update Student
   5. Print All Student
   6. Exit
Enter your choice: 3
Enter Student id: MS Dhoni
Menu:
   1. Insert New Student
   2. Fetch Student
   3. Delete Student
   4. Update Student
   5. Print All Student
   6. Exit
Enter your choice: 5
Name: JKS   ID: A100   GPA: 9.43
Name: Virat Kohli   ID: B101   GPA: 8.45
Menu:
   1. Insert New Student
   2. Fetch Student
   3. Delete Student
   4. Update Student
   5. Print All Student
   6. Exit
Enter your choice: 2
Enter student id: B101
Name: Virat Kohli   ID: B101   GPA: 8.45
Menu:
   1. Insert New Student
   2. Fetch Student
   3. Delete Student
   4. Update Student
   5. Print All Student
   6. Exit
Enter your choice: 4
Enter Student id: B101
Enter Student Name: Virat
Enter Student gpa: 9.99
Menu:
   1. Insert New Student
   2. Fetch Student
   3. Delete Student
   4. Update Student
   5. Print All Student
   6. Exit
Enter your choice: 5
Name: JKS   ID: A100   GPA: 9.43
Name: Virat   ID: B101   GPA: 9.99
Menu:
   1. Insert New Student
   2. Fetch Student
   3. Delete Student
   4. Update Student
   5. Print All Student
   6. Exit
Enter your choice: 6
Thank you!!


Related Solutions

Code an application program that keeps track of student information at your college: names, identification numbers,...
Code an application program that keeps track of student information at your college: names, identification numbers, and grade point averages in a fully encapsulated (homogeneous) Sorted array-based data structure. When launched, the user will be asked to input the maximum size of the data set, the initial number of students, and the initial data set. Once this is complete, the user will be presented with the following menu: Enter: 1 to insert a new student’s information. 2 to fetch and...
Create a program that keeps track of the following information input by the user: First Name,...
Create a program that keeps track of the following information input by the user: First Name, Last Name, Phone Number, Age Now - let's store this in a multidimensional array that will hold 10 of these contacts. So our multidimensional array will need to be 10 rows and 4 columns. You should be able to add, display and remove contacts in the array. In Java
Please answer with code for C language Problem: Counting Numbers Write a program that keeps taking...
Please answer with code for C language Problem: Counting Numbers Write a program that keeps taking integers until the user enters -100. In the end, the program should display the count of positive, negative (excluding that -100) and zeros entered. Sample Input/Output 1: Input the number: 0 2 3 -9 -6 -4 -100 Number of positive numbers: 2 Number of Negative numbers: 3 Number of Zero: 1
Write a C++ program for Euclids Algorithm that keeps track of the number of iterations (%...
Write a C++ program for Euclids Algorithm that keeps track of the number of iterations (% & loop) 1. Euclid’s Algorithm An alternative of the Euclidean algorithm for finding greatest common divisors (GCD) is repeatedly performing the modulo operation on two numbers until the remainder is 0. Here is the pseudocode for find the GCD of two positive numbers a and b using the Euclidean algorithm :while b ≠ 0 temp = b b = a mod t a =...
Grocery List Program Write a program that keeps track of the user's grocery list items. Prompt...
Grocery List Program Write a program that keeps track of the user's grocery list items. Prompt the user if they'd like to (each action is a function): See the list Display all items (if any) in the list Add item to their list Confirm with the user before adding item (y/n or yes/no) If they enter a duplicate item, notify them the item already exists Remove items from their list Confirm with the user before removing item (y/n or yes/no)...
Write a python program that keeps names and email addresses in a dictionary as key-value pairs....
Write a python program that keeps names and email addresses in a dictionary as key-value pairs. The program should display a menu that lets the user look up a person’s email address, add a new name and email address, change an existing email address, and delete an existing name and email address. The program should bind the dictionary and save it to a file when the user exits the program. Each time the program starts, it should retrieve the dictionary...
Write C++ a program that shows a class called gamma that keeps track of how many...
Write C++ a program that shows a class called gamma that keeps track of how many objects of itself there are. Each gamma object has its own identification called ID. The ID number is set equal to total of current gamma objects when an object is created. Test you class by using the main function below. int main()    {    gamma g1;    gamma::showtotal();    gamma g2, g3;    gamma::showtotal();    g1.showid();    g2.showid();    g3.showid();    cout <<...
create a program that asks user math questions and keeps track of answers... Python Allow the...
create a program that asks user math questions and keeps track of answers... Python Allow the user to decide whether or not to keep playing after each math challenge. Ensure the user’s answer to each math problem is greater than or equal to zero. Keep track of how many math problems have been asked and how many have been answered correctly. When finished, inform the user how they did by displaying the total number of math problems, the number they...
Write a program IN PYTHON of the JUPYTER NOOTBOOK that keeps getting a set of numbers...
Write a program IN PYTHON of the JUPYTER NOOTBOOK that keeps getting a set of numbers from user until the user enters "done". Then shows the count, total, and average of the entered numbers. This should the answer when finished Enter a number: 55 Enter a number: 90 Enter a number: 12 Enter a number: done You entered 3 numbers, total is 157, average is 52.33333
Hello! Working with python This program asks user math questions and keeps track of answers... Allow...
Hello! Working with python This program asks user math questions and keeps track of answers... Allow the user to decide whether or not to keep playing after each math challenge. Ensure the user’s answer to each math problem is greater than or equal to zero. Keep track of how many math problems have been asked and how many have been answered correctly. When finished, inform the user how they did by displaying the total number of math problems, the number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT