Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java (help)

Name: Anonymous 2006-04-04 19:36

You are to create two classes to implement a database program.  The main class is a menu of options and will create an arraylist() to store the objects.  The other object contains the data that will be stored in the array list


Data Class

You are to create a class that implements the comparable interface and stores data.  It is similar to the contact method in the book.  It should have the following methods:
-    A constructor method
-    A get() and set() for each data element
-    String toString()
-    int compareto(object)

For example, if the class was a ASU_student, you might have a student id, first and last names, and a debt.  Then you would have:
-    void ASU_student( id, first, last, debt)
-    String getid(), String getfirst(), String getlast(), double getdebt()
-    void setid( id), void setfirst( first), void setlast( last), void setdebt( debt)
-    String toString()
-    int compareto( obj);


Main Class

In this class, you will create an arraylist to store objects of the above Data Class.  This class will prompt the user, via a menu, to perform the following operations, until the user decides to quit.

1.    Add an object to the list – the object should be unique.  Thus, you will need to search the list before adding to make sure the Key is not already there.  The key can be any data item (ex. student id), or combination of data items (Band + CD).
2.    Display an object from the list.  Ask for the key, search, and display all the data for the object, or that it was not found
3.    Remove an object from the list.  Ask for the key, search, and if there remove it.
4.    Modify an object from the list.  Ask for the key, search, and update the non-key fields.
5.    Scan the database for some sub-information, or non-key fields.  For example, you may want to display all records with a certain last name, or CD name, or range of GPA, ...


As Extra Credit, try reading in the database from a text file when the program starts, and saving it to a text file as the program exits.

Look at the book examples and the on-line documentation to see how an arraylist is used.

Name: Anonymous 2006-04-07 19:29

Here is the solution for the first class:
class Data implements Comparable
{
    public Data() { }
    public int get() { return 42; }
    public void set(int i) { /* I don't care, I prefer 42 */ }
    public String toString() { return "Hello, world!"; }
    public int compareTo(Object o) { return 666; }
}
Maybe you can be more precise next time. Why don't you scan your assignment and put it on ImageShack, maybe I can help a bit.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List