Question
QUESTION : https://www.chegg.com/homework-help/questions-and-answers/java-discussed-details-assignment-class-basically-repeat-assignment-1-change-underlying-da-q108909723 CODE (PART 1) : https://www.chegg.com/homework-help/questions-and-answers/code-previous-assignment-part-1-import-javaio-import-javautil-public-class-database-privat-q108909934 CODE FROM PREVIOUS ASSIGNMENT (PART 2): import java.util.*; public class Driver { public static void main(String[] args)
QUESTION: https://www.chegg.com/homework-help/questions-and-answers/java-discussed-details-assignment-class-basically-repeat-assignment-1-change-underlying-da-q108909723
CODE (PART 1): https://www.chegg.com/homework-help/questions-and-answers/code-previous-assignment-part-1-import-javaio-import-javautil-public-class-database-privat-q108909934
CODE FROM PREVIOUS ASSIGNMENT (PART 2):
import java.util.*;
public class Driver { public static void main(String[] args) { DataBase d = new DataBase(); int response; Scanner keyboard = new Scanner(System.in); /* Read data into DB from the external text file * IMPORTANT: Duplicate ID numbers should not be added. Disregard * entire record for duplicate IDs. */
do { System.out.println(" 1 Add a new student"); System.out.println(" 2 Delete a student"); System.out.println(" 3 Find a student by ID"); System.out.println(" 4 List students by ID increasing"); System.out.println(" 5 List students by first name increasing"); System.out.println(" 6 List students by last name increasing"); System.out.println(" 7 List students by ID decreasing"); System.out.println(" 8 List students by first name decreasing"); System.out.println(" 9 List students by last name decreasing"); System.out.println(" "); System.out.println(" 0 End"); response = keyboard.nextInt(); switch (response) { case 1: d.addIt(); // Note: If user enters ID already in use, issue a warning and return to menu break; case 2: d.deleteIt(); // Note: Output either "Deleted" or "ID not Found" and return to menu break; case 3: d.findIt(); // Note: Output entire record or "ID not Found" and return to menu break; case 4: d.ListByIDAscending(); break; case 5: d.ListByFirstAscending(); break; case 6: d.ListByLastAscending(); break; case 7: d.ListByIDDescending(); break; case 8: d.ListByFirstDescending(); break; case 9: d.ListByLastDescending(); break; default: } } while (response != 0); } }
----------------------------------------------------------------------
public class IndexArray { // OrderedArray of IndexRecord private IndexRecord[] indexArr; private int maxSize; private int currentSize; private int pointer; private boolean primKey;
// Constructor to specify maximum size and if field is primary key public IndexArray(int maxSize, boolean primKey) { this.indexArr = new IndexRecord[maxSize]; this.maxSize = maxSize; this.currentSize = 0; this.pointer = currentSize; this.primKey = primKey; }
// Returns index of record with specified DB index public int searchByWhere(int where) { for(int i = 0; i < this.currentSize; i++) { if (this.indexArr[i].where == where) { return i; } } return -1; }
// Returns the index of record with specified key public
if (low > high) { mid = -1; } return mid; }
// Returns DB index of record with specified key public
return index; }
// Deletes record at specified index public void deleteIndex(int indexToDelete) { for (int i = indexToDelete; i < this.currentSize - 1; i++) { this.indexArr[i] = this.indexArr[i + 1]; } this.currentSize--; }
// Adds an IndexRecord into array public void add(IndexRecord IRec) { int i; for (i = this.currentSize - 1; i >= 0; i--) { if (this.indexArr[i].compareTo(IRec) < 0) break; this.indexArr[i + 1] = this.indexArr[i]; } this.indexArr[i + 1] = IRec; this.currentSize++; }
// Method to print entire array public void printIt() { String x = ""; for (int i = 0; i < this.currentSize; i++) { x += "(" + indexArr[i].key + ", " + indexArr[i].where + "), "; } System.out.println(x); }
// Initializes pointer to front of array public void pointerToFront() { this.pointer = 0; }
// Initializes pointer to back of array public void pointerToBack() { this.pointer = this.currentSize - 1; }
// Returns if pointer can move forward more public boolean hasNext() { return this.pointer < this.currentSize; }
// Returns if pointer can move backwards more public boolean hasPrevious() { return this.pointer > 0; }
// Returns next IndexRecord's where using pointer public int getNext() { return this.indexArr[this.pointer++].where; }
// Returns previous IndexRecord's where using pointer public int getPrevious() { return this.indexArr[this.pointer--].where; } }
----------------------------------------------------------------------
public class IndexRecord
// Constructor to pass key and where to public IndexRecord(K key, int where) { this.key = key; this.where = where; }
// Compares key of this record and another record public int compareTo(IndexRecord otherRec) { return this.key.compareTo((K) otherRec.key); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started