473,383 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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,451239813,401 Mercer Street,Ambridge,PA,15003
Quentin McCord,612012775,3521 Poderosa Way,Genoa City,WIS,51091
William Fenton,210882265,89 Winnie Pooh Lane,Disney City,FL,69102
Jay Siverheels,319887217,1234 Silver Bullet Road,Tombstone,AZ,85412
Shasha Fenster,110359876,3 Coast Highway,Santa Monica,CA,98234
Herman Glick,213905678,2145 Tulip Street,Aliquippa,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 setCreditsEarned(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(Object 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...hopefully someones solution will help me figure out my bugs...thanks again and happy coding
Mar 8 '08 #1
0 1283

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: jehugaleahsa | last post by:
Hello: I got tired of trying to find good implementations of collections and other data structures in C#. So, I started implementing my own. However, data structures is a wholly different...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.