use two built-in collection classes in JavaCollectionsFramework:Stack+Arraylist

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • batbrandman
    New Member
    • Mar 2008
    • 1

    #1

    use two built-in collection classes in JavaCollectionsFramework:Stack+Arraylist

    Need help with this...I tihnk it would be easier to see what someones developed program looks like, I keep getting stuck on a few major parts...Thanks very much!!!!!!!!!!
    The data will be found in a student.txt file . A sample is shown below. I also want to implement the string tokenizer


    Clark Kent,190409211, 1209 Lynn Lane,Burton,OH, 21091
    Lois Lane,524673319, 57 Wilson Avenue,Wheeling ,WVA,35120
    Carl Sampson,4512398 13,401 Mercer Street,Ambridge ,PA,15003
    Quentin McCord,61201277 5,3521 Poderosa Way,Genoa City,WIS,51091
    William Fenton,21088226 5,89 Winnie Pooh Lane,Disney City,FL,69102
    Jay Siverheels,3198 87217,1234 Silver Bullet Road,Tombstone, AZ,85412
    Shasha Fenster,1103598 76,3 Coast Highway,Santa Monica,CA,98234
    Herman Glick,213905678 ,2145 Tulip Street,Aliquipp a,PA,15001
    Willis Reed,451029869, 3451 West 57th Street,New York,NY,32198


    The first step in this question is to build the class called Student outlined below.

    class Student implements Comparable{ //note you are making these objects comparable
    private String FirstName;
    private String LastName;
    private String SSN;
    private String StreetAddress;
    private String City;
    private String State;
    private String Zip;
    private double GPA;
    private int CreditsEarned;

    Student(String line){
    //Extracts the first name, last name, social security number, street address, city,
    //state and zip code from the string line.
    }


    public String SSN(){
    //Returns the hyphenated SSN to the caller.
    }


    public void setCreditsEarne d(int credits){
    //Set the total credits earned by a student.
    }


    public void setGPA(double gpa){
    //Set the grade point average of a student.
    }

    public int compareTo(Objec t other){
    //Return -1 if the receiver’s last name is smaller than other’s last name or
    // the receiver’s last name is equal to other’s last name and the receiver’s first name
    //is smaller than other’s first name.
    //Return 0 if the receiver’s last name is equal to other’s last name and the receiver’s
    //first name is equal to other’s first name.
    //Return 1 the receiver’s last name is greater than other’s last name or
    // the receiver’s last name is equal to other’s last name and the receiver’s first name
    //is greater than other’s first name.
    }


    public String toString(){
    //Returns a student’s information as shown below as a string.
    //Name: Kent, Clark (last name first)
    //SSN: 190-40-9211 (don’t forget to hyphenate)
    //Address:
    //1209 Lynn Lane
    //Burton, OH 21091 (don’t forget to concatenate the city, state, and zip)
    //Credits Earned: 75
    //GPA: 3.0

    }
    }




    A second class StudentDatabase is outlined below:


    class StudentDatabase {
    private ArrayList StudentRecords;
    private Stack stack;
    private String studentFile; //Name of file contaning students
    private String expressionFile; //Name of file containing expression

    public StudentDatabase (String sf, String ef){
    //Initialize the studentFile and expressionFile based on user input of the file names.
    //Open the studentFile. For each line of input in the studentFile, create and
    //initialize a new Student. Store this student into the ArrayList StudentRecords.
    //
    //Open the expressionFile. For each line of input in the expression file, grab the
    //social security number, RPN (reverse polish notation) expression, and credits
    //earned. Locate the student in StudentRecords with this SSN, update the creditsEarned
    //and GPA fields.
    }


    public static int find(String ssn, ArrayList ar){
    //This static function locates the student in the ArrayList ar and returns the index
    //of where it is located. If it isn’t found, return -1.
    }

    public static double evaluate(String exp){
    //You will need a StringTokenizer to extract the operands and operators. Note that
    //operands are separated from one another by either a blank space or an operator.
    //If a token is an operand, push it as a Double onto the stack.
    //If a token is an operator, pop off the (second operand), pop off the (first
    //operand), compute (first operand) operator (second operand), push this value onto
    //the stack. Continue until you run out of tokens, the final result is at the top of
    //the stack. Example: 110. 5.+2.*103./ evaluates to approximately 2.23.
    }

    public void display(){
    //Move the contents of StudentRecords to an array, sort the students, display them one
    //at a time at the console.
    }
    }

    An example of the expression file is shown below:

    110-35-9876,110. 5.+2.*103./,44
    190-40-9211,1 1 1++,75
    210-88-2265,65 31-7-10/,67
    213-90-5678,600 420 80//60/,13
    319-88-7217,3 3 5^+12/18-,81
    451-02-9869,2 2+2^5/,49
    451-23-9813,2 1+2^4/,102
    524-67-3319,50 12 24+-10/,23
    612-01-2775,6 2*5+2^100/,74


    Note: the first line contains SSN 110-35-9876 which is Shasha Fenster’s social security number. The last token 44 is the credits Shasha earned. Let’s evaluate her expression 110. 5.+2.*103./
    The first two tokens are operands so they get pushed into the stack.




    The next token is the addition operator (+) so pop, pop, add, then push. In addition, the next token is the number 2 which is pushed into the stack. We should have the following
    5
    110
    The next token is the multiplication operator (*) so pop, pop, multiply, then push. In addition, the next token is the number 103 which is pushed into the stack. We have the following
    2
    115
    The next token is the division operator (/) so pop, pop, divide, then push. We have the final result sitting at the top of the stack.
    103
    230
    Shasha Fenster’s record contains:
    Name: Fenster, Shasha
    SSN: 110-35-9876
    Address:
    3 Coast Highway
    Santa Monica, CA 98234
    Credits Earned: 44
    GPA: 2.23



    Thanks again...hopeful ly someones solution will help me figure out my bugs...thanks again and happy coding
Working...