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 »
Almost everything is done for this. Essentially im just changing the structure from a linked list to a binary search tree;


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) { this.name = name; this.IDNo = ID; } } public static LinkedList readFile() { //method to read in files LinkedList list = new LinkedList<>(); try { File file = new File("C:\\Users\\seanp\\Desktop\\studentroster.txt"); //associated path Scanner scn = new Scanner(file); //create new scanner object while (scn.hasNextLine()) { //reads in the files by each line String data = scn.nextLine(); int i = 0; while (i < data.length())="" {="" take="" in="" data="" line="" by="" line="" (id="" firstname="" lastname)="" if="" (data.charat(i)="=" '="" ')="" {="" break;="" }="" i++;="" }="" int="" id="Integer.parseInt(data.substring(0," i));="" string="" name="data.substring(i" +="" 1);="" student="" student="new" student(name,="" id);="" list.addlast(student);="" }="" scn.close();="" }="" catch="" (ioexception="" e)="" {="" system.out.println("an="" error="" occurred.");="" e.printstacktrace();="" }="" return="" list;="" }="" public="" static="" void="" updatearray(student[]="" dataarray,=""> list) { //update array and sort int ind = 0; while (dataArray[ind] != null) { //updates array contents ind++; } while (list.size() > 0) { Student student = list.removeFirst(); dataArray[ind] = student; ind++; if (ind == dataArray.length) { break; } } int n = ind; //selection sort for (int i = 0; i < ind="" -="" 1;="" i++)="" {="" int="" min="i;" find="" min="" in="" array="" for="" (int="" j="i" +="" 1;="" j="">< n;="" j++)="" if="" (dataarray[j].idno="">< dataarray[min].idno)="" min="j;" student="" temp="dataArray[min];" swap="" min="" with="" first="" element="" dataarray[min]="dataArray[i];" dataarray[i]="temp;" }="" }="" public="" static="" void="" writefile(student[]="" dataarray)="" {="" take="" data="" from="" array="" to="" text="" file="" try="" {="" filewriter="" mywriter="new" filewriter("c:\\users\\seanp\\desktop\\studentroster.txt");="" int="" i="0;" while="" (dataarray[i]="" !="null" &&=""> 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) { System.out.println("Enter choice"); int choice = 0; if (scn.hasNextLine()) { choice = Integer.parseInt(scn.nextLine()); } if (choice == 1) { // load roster list = readFile(); } else if (choice == 2) { // add student System.out.println("Enter Student ID"); int ID = Integer.parseInt(scn.nextLine()); System.out.println("Enter Student Name"); String name = scn.nextLine(); list.add(new Student(name, ID)); } else if (choice == 3) { //remove student via ID System.out.println("Enter Student ID"); int ID = Integer.parseInt(scn.nextLine()); for (int i = 0; i < list.size();="" i++)="" {="" if="" (list.get(i).idno="=" id)="" {="" list.remove(i);="" break;="" }="" }="" }="" else="" if="" (choice="=" 4)="" {="" search="" for="" student="" via="" id="" student="" student="new" student();="" system.out.println("enter="" student="" id");="" int="" id="Integer.parseInt(scn.nextLine());" for="" (int="" i="0;" i="">< list.size(); i++) { if (list.get(i).idno == id) { list.size();="" i++)="" {="" if="" (list.get(i).idno="=" id)="">
Answered Same DayJul 28, 2021

Answer To: import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.*;...

Arun Shankar answered on Jul 29 2021
153 Votes
StudentRosterProject/.DS_Store
__MACOSX/StudentRosterProject/._.DS_Store
StudentRosterProject/bin/BST.class
StudentRosterProject/bin/Utilities.class

StudentRosterProject/bin/StudentRoster.class
StudentRosterProject/bin/studentroster.txt
102 hilary clinton
124 bob builder
353 rey mysterio
521 eddy guerrero
555 donald trump
666 bernie sanders
693 jennifer lawrence
839 john wick
StudentRosterProject/bin/Student.class
StudentRosterProject/bin/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=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
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.javabuilder
            
            
        
    
    
        ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here