this is one assignment
There will be a discussion in class about this assignment
What to do.
Create a simple database with three fields : ID, LastName,FirstName all as Strings. You should define a class calledStudentRecord or DataBaseRecordwith three private String elements (the three fields), along withthe appropriate methods. Here's what mine looked like:
public class StudentRecord{
   private String fname;
   private String lname;
      private String ID;
   DataBaseRecord(String f,String l,Stringi)
   {
     this.fname=f;
       this.lname=l;
     this.ID=i;
   }
 Â
  Â
public String toString()
   {
       return(fname+\"\"+lname+\" \"+ID);
   }
 Â
   public int compareTo(StudentotherStudent)
   {
       return(LastName.compareTo(otherStudent.LastName));
   }
     Â
}
You should also declare an object called DataBaseArray which isan array of DatabaseRecords. Records of type DataBaseRecord shouldbe added at the end of the DataBaseArray. Create an IndexRecordclass:
public class IndexRecord {
private String key;
private int where;
//other stuff here
}
Now create an IndexArray. This is an array of IndexRecord and isto be implemented That is, insertions must maintain the order inthe array, where order is maintained by the key value. Note thatthis means you need to define a compareTo method in the IndexRecordobject.
The OrderedArray class was an array of objects of type Student.To print out the array, we included a method called printIt() thatprinted out the entire array. But suppose we wanted to do thefollowing: we wish to retrieve an element from the array, dosomething with it, and then retrieve the next element in the array.Why (or when) you might wish to do this will become apparent as youwork on the programming assignment.
We need an iterator.
An iterator is an element that is part of the OrderedArray object;it is a current pointer to an element in the array. We caninitialize this pointer to the beginning of the array or the end.We can advance the pointer forward or backward.
Finally, and most importantly, we can retrieve the element in arrayreferenced by the iterator. The declaration of an iterator in ourexample would be:
public class OrderedArray
{
   private Student data[ ];
   private int nextElem;
   private int maxSize;
   private int theIterator;          //we add an iterator;
   .......
  Â
We can initialize the iterator to reference the beginning of thearray or the end of the array. We agree that if the array is empty,either initialization should set the iterator to -1:
public void setIteratorBegin()
{
   theIterator=(nextElem>0? 0 : -1);
}
public void setIteratorEnd()
{
   theIterator=(nextElem>0 ? nextElem-1 :-1);
}
Finally, there are three methods that return an instance of aStudent:
/* getIterator returns a reference to the Student currentlyreferenced by theIterator
/*Â Â Â Â Â if theIterator==1 return -1
public Student getIterator()
{
   return(theIterator==-1 ? null:data[theIterator]);
}
/* advance theIterator. If we run off end, set to -1
/* if theIterator==-1 return null, else the reference to the entryin the array
public Student getIteratorNext()
{
  theIterator=(theIterator==nextElem-1? -1:theIterator+1);
  return(theIterator==-1? null :data[theIterator]);
}
/* decrement theIterator. If we run offthe beginning of the array, set to -1
/* if theIterator==-1 return null, else the reference to the entryin the array
public Student getIteratorPrev()
{
   theIterator=(theIterator==0? -1:theIterator-1);
   return(theIterator==-1?null:data[theIterator]);
}
So what does all this get us ? See the following code to traversethe array foward or in reverse:
public class UseOrderedArray {
   public static void main(String[] args)
   {
     Â
      Student s;
      OrderedArray myArray=newOrderedArray(20);
           Â
      myArray.insert(newStudent(\"smith\",16,(float)2.7));
      myArray.insert(newStudent(\"adams\",15,(float)3.1));
      myArray.insert(newStudent(\"morris\",17,(float)3.3));
     Â
      // print in reverseorder
     Â
      myArray.setIteratorEnd();
      for(s=myArray.getIterator();s!=null;s=myArray.getIteratorPrev())
         System.out.println(s);
     Â
      // print in forwardorder
     Â
      myArray.setIteratorBegin();
      for(s=myArray.getIterator();s!=null;s=myArray.getIteratorNext())
         System.out.println(s);
        Â
   }
}
The data! Please note the format is: last_name first_name student_IDRead into your own file Dunn Sean 31111 Duong Geoffrey 29922 Fazekas Nicholas 31100 Prezioso Stefano 22223 Puvvada Mohana 11224 Ravikumar Rakhi 11226 Salyers Matthew 11227 Gillespie William 49587 Hess Caleb 29282 Armatis Jared 34512 Beckman Allan 35176 Wang Zhen 22113 Wingett Jordan 12345 Belt Keith 34987 Bixler Tyler 22234 Chambers Quentin 22567 Chinni Adithya 28456 Donheiser Michael 28456 Kondrashov Mikhail 33331 Kraus Laura 33332 Krupp Phillip 49888 Maass John 44112 McCarty Amanda 44223 Moldovan Gregory 44335 Oshiyoye Adekunle 44556 Pagalos Frank 33112 Perski Zackery 33221 Saunders Jordan 77556 Simpson Ashlynne 77665 Szalai Kyle 33112 Witting Robert 21354
/**
* This will be the main driver program for many of your programs.Specifically,
* you will need to define a data structure and related algorithmsto use with this program.
* We will be using the data file I have provied for you: a file of68 records. Each record is composed
* of three fields:
*Â Â Â Â Â String lastName
*Â Â Â Â Â String firstName
*Â Â Â Â Â String ID
* ID may be implemented as an integer, but it is easier toimplement as a string. Both lastName and firstName
* may not be unique, but the ID **is** unique.
*
*
*/
import java.util.*;
public class COSC311Driver
{
      Â
  Â
   public static void main(String[] args)
   {
       /*The followingdeclaration declares a data structure that will change from oneassignment to the next. For example, you will need toimplement
        * the following asa doubly linked list, as well as a tree.
        */
      Â
   Â
       DataBase d=newDataBase();
      int response;
       Scanner keyboard=newScanner(System.in);
      Â
      Â
       /* Read the data intothe database from the external disk file here
        * IMPORTANT:duplicate ID numbers should not be added. Disregard
        * the entirerecord 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 nameincreasing\");
           System.out.println(\" 6 List students by last nameincreasing\");
           System.out.println(\" 7 List students by ID decreasing\");
           System.out.println(\" 8 List students by first namedecreasing\");
           System.out.println(\" 9 List students by last namedecreasing\");
           System.out.println(\" \");
           System.out.println(\" 0 End\");
          Â
           response=keyboard.nextInt();
          Â
           switch (response)
           {
               case 1: d.addIt();   //Note: if the user enters an IDalready in use, issue a warning and return to the menu
                       break;
               case 2: d.deleteIt(); //Note: output either \"Deleted\" or \"ID notFound\" and return to menu
                       break;
               case 3: d.findIt();  //Note: output the entire record orthe message \"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);
   }
}