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 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 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.

Just need some help

Data Structures and Algorithms Using Java. McAllister.

Solutions

Expert Solution

// Student.java

public class Student {
private int id;
private String name;
private char gender;

public Student(int myid, String myName, char myGender){
this.id = myid;
this.name = myName;
this.gender = myGender;
}

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

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

public void setGender(char myGender){
this.gender = myGender;
}

public int getId(){
return this.id;
}

public String getName(){
return this.name;
}

public char getGender(){
return this.gender;
}

@Override
public String toString() {
return this.id + "\t" + this.name + "\t\t" + this.gender;
}
}

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

public class StudentOperation implements Comparator<Student> {
String name;
int noOfStudents;
int maxStudent = 5;
Student student[];
  
public StudentOperation(int noOfStudents){
this.name = name;
this.noOfStudents = noOfStudents;
this.student = new Student[noOfStudents];
}

public void add(){
int id;
String name;
char gender;
  
Scanner input = new Scanner(System.in);
  
int i = 0;
while(true){
System.out.println("Enter an student id or -1 to stop:");
id = input.nextInt();
if(id == -1){
break;
}
System.out.println("Enter student name:");
name = input.next();
System.out.println("Enter student gender:(M/F)");
gender = input.next().charAt(0);
if(i < this.noOfStudents){
this.student[i] = new Student(id, name, gender);
}else{
System.out.println("Sorry, the data set reached it's capacity of students.");
}
i++;
}
}

public void print() {
System.out.println("Students details: ");
Arrays.sort(this.student, new StudentOperation(this.noOfStudents));
if(this.student.length > 0){
System.out.println("id\tname\t\ttgender");
for(int i = 0; i < this.student.length; i++){
if(this.student[i] != null){
System.out.println(this.student[i].toString());
}
}
}else{
System.out.println("No student found");
}
}

public void remove() {
Scanner input = new Scanner(System.in);
System.out.println("Enter the id of the student you want to remove");
int id = input.nextInt();
String name = null;
Student[] arrayData = new Student[this.noOfStudents];
for(int i = 0, k = 0; i < this.student.length; i++){
if(this.student[i] != null){
if(this.student[i].getId() == id){
name = this.student[i].getName();
continue;
}
arrayData[k++] = this.student[i];
}
}
this.student = arrayData;
if(name != null)
System.out.println("Student " + name + " has been removed.");
else
System.out.println("Sorry the student with id "+ id +" does not exist and cannot be removed.");
}

public void update() {
Scanner input = new Scanner(System.in);
System.out.println("Enter the id of the student you want to update");
int id = input.nextInt();
String name = null;
char gender;
Student[] arrayData = new Student[this.noOfStudents];
for(int i = 0, k = 0; i < this.student.length; i++){
if(this.student[i] != null){
if(this.student[i].getId() == id){
System.out.println("Enter the updated name: ");
name = input.next();
this.student[i].setName(name);
System.out.println("Enter the updated gender: ");
gender = input.next().charAt(0);
this.student[i].setGender(gender);
break;
}
}
}
if(name != null)
System.out.println("Student with id "+ id +" has been update.");
else
System.out.println("Sorry the student with id "+ id +" does not exist and cannot be removed.");
}

public void search() {
Scanner input = new Scanner(System.in);
System.out.println("Enter the id of the student you want to search");
int id = input.nextInt();
System.out.println("id\tname\tgender");
for(int i = 0; i < this.student.length; i++){
if(this.student[i] != null && this.student[i].getId() == id){
System.out.println(this.student[i].toString());
}
}
}

@Override
public int compare(Student a, Student b) {
return a.getId() - b.getId();
}
}

// StudentTest.java

import java.util.Scanner;

public class StudentTest {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int noOfStudents = 5;
System.out.println("Input the maximum size of the data set:");
noOfStudents = input.nextInt();
int option;
StudentOperation s = new StudentOperation(noOfStudents);
do{
System.out.println("Choose one of the following:");
System.out.println("----------------------------");
System.out.println("1) Insert a new student's information");
System.out.println("2) Fetch and output a student's information");
System.out.println("3) Delete a student's information");
System.out.println("4) Update a student's information");
System.out.println("5) Output all the student information in sorted order");
System.out.println("6) Exit");
option = input.nextInt();
switch(option){
case 1:
s.add();
break;
case 2:
s.search();
break;
case 3:
s.remove();
break;
case 4:
s.update();
break;
case 5:
s.print();
break;
}
}while(option < 6);
System.out.println("Thank you for using the program");
}
}

Output:

PS D:\xampp\htdocs\example\Student> java StudentTest
Input the maximum size of the data set:
5
Choose one of the following:
----------------------------
1) Insert a new student's information
2) Fetch and output a student's information
3) Delete a student's information
4) Update a student's information
5) Output all the student information in sorted order
6) Exit
1
Enter an student id or -1 to stop:
3
Enter student name:
student 3
Enter student gender:
Enter an student id or -1 to stop:
-1
Choose one of the following:
----------------------------
1) Insert a new student's information
2) Fetch and output a student's information
3) Delete a student's information
4) Update a student's information
5) Output all the student information in sorted order
6) Exit
3
Enter the id of the student you want to remove
3
Student student has been removed.
Choose one of the following:
----------------------------
1) Insert a new student's information
2) Fetch and output a student's information
3) Delete a student's information
4) Update a student's information
5) Output all the student information in sorted order
6) Exit
1
Enter an student id or -1 to stop:
3
Enter student name:
student3
Enter student gender:
F
Enter an student id or -1 to stop:
5
Enter student name:
asdad
Enter student gender:
M
Enter an student id or -1 to stop:
8
Enter student name:
sewr
Enter student gender:
M
Enter an student id or -1 to stop:
4
Enter student name:
fsdf
Enter student gender:
M
Enter an student id or -1 to stop:
9
Enter student name:
sdfsf
Enter student gender:
F
Enter an student id or -1 to stop:
7
Enter student name:
rwwe
Enter student gender:
F
Sorry, the data set reached it's capacity of students.
Enter an student id or -1 to stop:
-1
Choose one of the following:
----------------------------
1) Insert a new student's information
2) Fetch and output a student's information
3) Delete a student's information
4) Update a student's information
5) Output all the student information in sorted order
6) Exit
5
Students details:
id name gender
3 student3 F
4 fsdf M
5 asdad M
8 sewr M
9 sdfsf F
Choose one of the following:
----------------------------
1) Insert a new student's information
2) Fetch and output a student's information
3) Delete a student's information
4) Update a student's information
5) Output all the student information in sorted order
6) Exit
4
Enter the id of the student you want to update
9
Enter the updated name:
test
Enter the updated gender:
F
Student with id 9 has been update.
Choose one of the following:
9 test F
Choose one of the following:
----------------------------
1) Insert a new student's information
2) Fetch and output a student's information
3) Delete a student's information
4) Update a student's information
5) Output all the student information in sorted order
6) Exit

6
Thank you for using the program

Note: Instruction to be followed

Firstly compile all the files like below:

javac Student.java

javac StudentOperation.java

javac StudentTest.java

Run program using

java StudentTest

If you need anything more on this please add comment below. I'll reply ASAP.


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 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...
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