Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.*; public class StudentRoster { static int maxSize=10; public static class Student { String name; int IDNo;...

1 answer below »
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
public class StudentRoster {
    static int maxSize=10;
    
public static class Student {
String name;
int IDNo;
Student() {}
Student(String name, int ID) {
XXXXXXXXXXthis.name = name;
XXXXXXXXXXthis.IDNo = ID;
}
}
public static LinkedList readFile() {
method to read in files
LinkedList list = new LinkedList
();
try {
XXXXXXXXXXFile file = new File("C:\\Users\\seanp\\Desktop\\studentroster.txt");
associated path
XXXXXXXXXXScanner scn = new Scanner(file);
create new scanner object
XXXXXXXXXXwhile (scn.hasNextLine()) {
eads in the files by each line
XXXXXXXXXXString data = scn.nextLine();
XXXXXXXXXXint i = 0;

XXXXXXXXXXwhile (i < data.length()) {
take in data line by line (ID firstname lastname)
XXXXXXXXXXif (data.charAt(i) == ' ') {

eak;
}
XXXXXXXXXXi++;
}
XXXXXXXXXXint ID = Integer.parseInt(data.substring(0, i));
XXXXXXXXXXString name = data.substring(i + 1);
XXXXXXXXXXStudent student = new Student(name, ID);
XXXXXXXXXXlist.addLast(student);
}
XXXXXXXXXXscn.close();
} catch (IOException e) {
XXXXXXXXXXSystem.out.println("An e
or occu
ed.");
XXXXXXXXXXe.printStackTrace();
}
return list;
}
public static void updateA
ay(Student[] dataA
ay, LinkedList list) {
update a
ay and sort
int ind = 0;
while (dataA
ay[ind] != null) {
updates a
ay contents
XXXXXXXXXXind++;
}
while (list.size() > 0) {
XXXXXXXXXXStudent student = list.removeFirst();
XXXXXXXXXXdataA
ay[ind] = student;
XXXXXXXXXXind++;
XXXXXXXXXXif (ind == dataA
ay.length) {

eak;
}
}
int n = ind;
selection sort
XXXXXXXXXXfor (int i = 0; i < ind - 1; i++) {
XXXXXXXXXXint min = i;
find min in a
ay
XXXXXXXXXXfor (int j = i + 1; j < n; j++)
XXXXXXXXXXif (dataA
ay[j].IDNo < dataA
ay[min].IDNo)
XXXXXXXXXXmin = j;
XXXXXXXXXXStudent temp = dataA
ay[min];
swap min with first element
XXXXXXXXXXdataA
ay[min] = dataA
ay[i];
XXXXXXXXXXdataA
ay[i] = temp;
}
}
public static void writeFile(Student[] dataA
ay) {
take data from a
ay to text file
try {
XXXXXXXXXXFileWriter myWriter = new FileWriter("C:\\Users\\seanp\\Desktop\\studentroster.txt");
XXXXXXXXXXint i = 0;
XXXXXXXXXXwhile (dataA
ay[i] != null && i XXXXXXXXXXStudent student = dataA
ay[i];
XXXXXXXXXXString data = student.IDNo + " " + student.name;
XXXXXXXXXXmyWriter.write(data + "\n");
XXXXXXXXXXi++;
}
XXXXXXXXXXmyWriter.close();
} catch (IOException e) {
XXXXXXXXXXSystem.out.println("An e
or occu
ed.");
XXXXXXXXXXe.printStackTrace();
}
}
public static void Menu() {
main menu program
Student[] dataA
ay = new Student[maxSize];
LinkedList list = new LinkedList
();
System.out.println("1. Load Roster");
System.out.println("2. Add a Student");
System.out.println("3. Remove a Student");
System.out.println("4. Search Student by ID");
System.out.println("5. Search Student by Name");
System.out.println("6. Save");
System.out.println("7. Save Changes");
System.out.println("8. Exit Program");
Scanner scn = new Scanner(System.in);
create scanner to receive user input for menu
while (true) {
XXXXXXXXXXSystem.out.println("Enter choice");
XXXXXXXXXXint choice = 0;
XXXXXXXXXXif (scn.hasNextLine()) {
XXXXXXXXXXchoice = Integer.parseInt(scn.nextLine());
}
XXXXXXXXXXif (choice == 1) {
load roste
XXXXXXXXXXlist = readFile();
} else if (choice == 2) {
add student
     System.out.println("Enter Student ID");
XXXXXXXXXXint ID = Integer.parseInt(scn.nextLine());
XXXXXXXXXXSystem.out.println("Enter Student Name");
XXXXXXXXXXString name = scn.nextLine();
XXXXXXXXXXlist.add(new Student(name, ID));
} else if (choice == 3) {
emove student via ID
XXXXXXXXXXSystem.out.println("Enter Student ID");
XXXXXXXXXXint ID = Integer.parseInt(scn.nextLine());
XXXXXXXXXXfor (int i = 0; i < list.size(); i++) {
XXXXXXXXXXif (list.get(i).IDNo == ID) {
XXXXXXXXXXlist.remove(i);

eak;
}
}
} else if (choice == 4) {
search for student via ID
XXXXXXXXXXStudent student = new Student();
XXXXXXXXXXSystem.out.println("Enter Student ID");
XXXXXXXXXXint ID = Integer.parseInt(scn.nextLine());
XXXXXXXXXXfor (int i = 0; i < list.size(); i++) {
XXXXXXXXXXif (list.get(i).IDNo == ID) {
Answered Same Day Jul 28, 2021

Solution

Arun Shankar answered on Jul 29 2021
144 Votes
StudentRosterProject/.DS_Store
__MACOSX/StudentRosterProject/._.DS_Store
StudentRosterProject
in/BST.class
StudentRosterProject
in/Utilities.class
StudentRosterProject
in/StudentRoster.class
StudentRosterProject
in/studentroster.txt
102 hilary clinton
124 bob builde
353 rey mysterio
521 eddy gue
ero
555 donald trump
666 bernie sanders
693 jennifer lawrence
839 john wick
StudentRosterProject
in/Student.class
StudentRosterProject
in/BSTNode.class
StudentRosterProject/.classpath

    
        
            
        
    
    
    
StudentRosterProject/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=14
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=14
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=e
o
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=e
o
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=14
StudentRosterProject/.project

     StudentRosterProject
    
    
    
    
        
             org.eclipse.jdt.core.javabuilde
            
            
        
    
    
        ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here