Question

In: Computer Science

Code an application program that keeps tracks of srudent information at your college:names, identification numbers, and...

Code an application program that keeps tracks of srudent information at your college:names, identification numbers, and grade point averages in a fully encapsulated (homogenous) sorted array-based data structure. When launched, the user will be asked to input the maximum size of 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 info
2 to fetch and out put a student's info
3 to delete student info
4 to update student info
5 to output all the student info in sorted order
6 to exit program
note: please use Java language to create this program and please write comments for each statement that what is happening. i know there are same questions solution posted in chegg, but i want some unique from others

Solutions

Expert Solution

I have created two file as below and mentioned inline comments as well. Do let me know in case of any doubt.

Sorting of array is done in switch-case statements whenever there is update/delete/insertion in studentList array.

Student.java

public class Student{

    Integer id;
    String name;
    double grade;

    public Student(Integer id, String name, double grade) {
        this.id = id;
        this.name = name;
        this.grade = grade;
    }

    public Student() {
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", grade=" + grade +
                '}';
    }
}

Screenshot:

StudentDB.java

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class StudentDB {

    static Student[] studentList;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter max size of data set: ");
        int maxSize = sc.nextInt();
        studentList = new Student[maxSize];
        System.out.print("Enter no of students: ");
        int students = sc.nextInt();
        System.out.print("Enter space separated student details: ");
        sc.nextLine();// to consume enter character which is left in input stream by nextInt()
        int i = 0;
        while (i < students) {
            String line[] = sc.nextLine().split(" ");
            studentList[i] = new Student(Integer.parseInt(line[0]), line[1], Double.parseDouble(line[2]));
            i++;
        }
        Arrays.sort(studentList, 0, i, Comparator.comparing(obj -> obj.id));
        System.out.println("Menu:");
        System.out.println("Enter:1 to insert a new student's info\n" +
                "2 to fetch and out put a student's info\n" +
                "3 to delete student info\n" +
                "4 to update student info\n" +
                "5 to output all the student info in sorted order\n" +
                "6 to exit program");
        int choice = sc.nextInt();

        while (choice >= 1 && choice <= 6) {
            switch (choice) {
                case 1:
                    if (i < maxSize) {
                        System.out.print("Enter space separated student details: ");
                        sc.nextLine(); // to consume enter character
                        String line[] = sc.nextLine().split(" ");
                        studentList[i] = new Student(Integer.parseInt(line[0]), line[1], Double.parseDouble(line[2]));
                        i++;
                        Arrays.sort(studentList, 0, i, Comparator.comparing(obj -> obj.id));
                    } else System.out.println("Student list is full. New students can't be stored.");
                    break;
                case 2:
                    System.out.print("Enter id to search");
                    int searchId = sc.nextInt();
                    for (int l = 0; l < i; l++) {
                        if (studentList[l].id.equals(searchId))
                            System.out.println(studentList[l]); // toString() will be used to print details
                    }
                    break;
                case 3:
                    System.out.print("Enter id to be deleted: ");
                    int delId = sc.nextInt();
                    int j = 0, index = -1;
                    while (j < i) {
                        if (studentList[j].id.equals(delId)) {
                            index = j; // store the index where student is found
                            break;
                        }
                        j++;
                    }
                    if (index == -1) System.out.println("Student id not found");
                    else {
                        j = index;
                        //move all student obj one index back from index where the student to be deleted is found
                        while (j < i - 1) {
                            studentList[j] = studentList[j + 1];
                            j++;
                        }
                        i--; // decrement i as one student is deleted
                        System.out.println("Student deleted.");
                    }
                    Arrays.sort(studentList, 0, i, Comparator.comparing(obj -> obj.id));
                    break;
                case 4:
                    System.out.print("Enter student details to be updated with id: ");
                    sc.nextLine(); // to consume enter character
                    String line[] = sc.nextLine().split(" ");
                    Student updstudent = new Student(Integer.parseInt(line[0]), line[1], Double.parseDouble(line[2]));
                    int updId = Integer.parseInt(line[0]);
                    // loop over students and update when id matches
                    for (int k = 0; k < i; k++) {
                        if (studentList[k].id.equals(updId))
                            studentList[k] = updstudent;
                    }
                    Arrays.sort(studentList, 0, i, Comparator.comparing(obj -> obj.id));
                    break;
                case 5:
                    //print all the student records
                    for (int m=0;m<i;m++) {
                        System.out.println(studentList[m]); // toString() will be used to print details
                    }
                    break;
                case 6:
                    System.exit(0);
                default:
                    System.err.println("Wrong choice.");
            }
            System.out.print("Enter choice: ");
            choice = sc.nextInt();
        }
    }
}

Screenshot:

Output:


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...
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...
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 Java program that implements a song database. The SongsDatabase class keeps tracks of song...
Write a Java program that implements a song database. The SongsDatabase class keeps tracks of song titles by classifying them according to genre (e.g., Pop, Rock, etc.). The class uses a HashMap to map a genre with a set of songs that belong to such a genre. The set of songs will be represented using a HashSet. Your driver output should sufficiently prove that your code properly implements the code below. public class SongsDatabase { private Map<String, Set<String>> genreMap =...
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
Write a C++ code that keeps reading integer numbers (x) until a negative number is entered....
Write a C++ code that keeps reading integer numbers (x) until a negative number is entered. Every time x is entered, the program does the following: calculates and prints the product of odd numbers. calculates and prints the count of numbers that ends with 19. Example, 19, 3219, 50619,....etc calculates and prints the percentage of the numbers that contain 3 digits exactly, such as, 301, 500, 206,...etc.
For segments (a) and (b), use the information below. The personal identification numbers (PINs) for ATMs...
For segments (a) and (b), use the information below. The personal identification numbers (PINs) for ATMs usually consist of four digits, chosen from 0, 1, 2, ….., 9. Suppose you notice that most of the PINs you hold have at least one “1,” which makes you wonder if the issuers of these numbers include many ones so that users will remember them more easily.                 Assume PIN numbers of 4 digits are assigned randomly. How many unique PIN numbers are...
Python Jupiter Notebook Write a program that keeps getting a set of numbers from user until...
Python Jupiter Notebook Write a program 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. Example: 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
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
PROGRAM INSTRUCTIONS: 1. Code an application that asks the customer for a log-in and password. 2....
PROGRAM INSTRUCTIONS: 1. Code an application that asks the customer for a log-in and password. 2. The real log-in is "Buffet2011" and the real password is "Rank1Bill2008". 3. Allow the customer two (2) attempts to type either. a. Each time the customer enters an invalid log-in or password issue an error message. b. If the customer fails all two (2) log-in attempts, issue another error message and exit the program. c. If the log-in is successful, the customer can calculate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT