I once implemented the following..
Code:
import java.util.ArrayList;
/ ** * This class represents the model of an indexed-organized file with linked index dar.
* The file contains as many records of any structured to be defined or * simple type.
* methods for inserting, searching, issuing, changing, deleting a record and output
* all rates are to implemented.
* For ease of use was a record with the primitive string data type selected. * * @ author Daniel Pernold * @ version 3.0 * / public class File (/ / instance variables private ArrayList file; private int number;
/ ** * Constructor for objects of the class file management * /
public File ()
(/ / initialize instance variable file = new ArrayList (); int number = 0;)
/ ** * method for inserting a sentence in the array *
* @ param index the index value of the sentence in the array
* @ param set the contents of the corresponding index value * /
public void satzPaste (String content)
(// In the event that the rate Delete method, the value of the number variables
// does not reduce the delete if (datei.size () <number) (System.out.println ("Here is something gone wrong"); System.out.println ("------------- ------------------------");)
// If everything works correctly, add the sentence to datei.add else ((number, content); number + +;)
/ ** * method for outputting a record *
* @ param index the index value of the sentence in the array to be output) will * /
public void satzType (int index)
(// If the ArrayList is not empty if (! file . isEmpty ())
(// If we enter an index does not yet exist if (index> = datei.size ()) (System.out.println ("This script is not yet available");
System.out.println ("-------------------------------------");) else (System.out.println (index + ":" + datei.get (index)); System.out.println ("---------------------------- ---------");))
// If the ArrayList is empty else (System.out.println ("The file has set no store"); System.out.println ("---- ---------------------------------");)) / ** * Method to change a record *
* @ param index the index value of the sentence in the array to be changed * @ param content the content to Amending the set * /
public void satzSize (int index, String content)
(// If the ArrayList is not empty if (! datei.isEmpty ( )) (/ / If we enter an index does not yet exist if (index> = datei.size ())
(System.out.println ("This script is not yet available"); System.out.println ("- ------------------------------------");) else (datei.set (index content) , ("The record with the index" + index + "was"); System.out.println ("successfully to the value" + content + System.out.println "changed"); System.out.println ("- ------------------------------------");))
// If the ArrayList is empty else ( System.out.println ("The file has set no store"); System.out.println ("--------------------------- ))
/ ** * Method to delete a sentence is a sentence deleted * ----------"); shifts the index of following sentences *
* @ param index the index value of the sentence in the array to be deleted should */
public void rate Delete (int index) (// If the ArrayList is not empty, delete the sentence and in lower number by one if (! datei.isEmpty ())
(// If you enter an index does not yet exist if (index> = datei.size ()) (System.out.println ("This script is not yet available"); System.out.println ("---------------- ---------------------");) else (datei.remove (index) number - System.out.println ("The record with the index "+ index +" was deleted successfully "); System.out.println ("-------------------------------- -----");)) // If the ArrayList is empty else (System.out.println ("The file has set no store"); System.out.println ("-------- -----------------------------");))
/ ** * Method to output all records * /
public void alleSaetzeAusgeben () (// If the ArrayList is not empty if (! datei.isEmpty ()) (for (int index = 0; index <datei.size (); index + +) (System.out.println (index + ":" + file . get (index));) System.out.println ("----------------------------------- --");)
// If the ArrayList is empty else (System.out.println ("The file has set no store"); System.out.println ("------------ -------------------------");)) / ** * method for the sequential search of a set * /
public void rate search (String value)
( // If the ArrayList is not empty if (()) (boolean found = false datei.isEmpty for (int index = 0; index <datei.size (); index + +) (if (datei.get (index). equals (value)) (System.out.println ("Found!") System.out.println (index + ":" + datei.get (index)); System.out.println ("----- --------------------------------"); found = true;)) if (found == false) (System . out.println ("Nothing Found"); System.out.println ("------------------------------- ------");))
// If the ArrayList is empty else (System.out.println ("The file has set no store"); System.out.println ("------- ------------------------------");)) / ** * Method to delete all records * /
public void allClass ( ) (datei.removeAll (file);))
Please Help, it is supposed to be chained!! :
Bookmarks