The Artima Developer Community
Sponsored Link

Java Answers Forum
Please help me out it will be greatly appreciated

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
chris

Posts: 1
Nickname: bman
Registered: Mar, 2003

Please help me out it will be greatly appreciated Posted: Mar 11, 2003 4:49 PM
Reply to this message Reply
Advertisement
hello and thank you for taking the time to look at my problem.
I have some of hte code done out but i need help.
I need to know what goes inside where the dots are.
Thast is where the problems are. Thanks again and any help will be appreciated


class AddressBook {

String []fieldNames;

String [][] book;

public void initAddressBook (String [] fields, String[][] records) {

fieldNames = fields;

book = records;

}// end of initAddress

private int translate(String field) { //covert field name to index into array book

int result;

for (result = 0; !fieldNames[result].equals(field); result++)

;

return result;

} // end of translate

private String [][] storeIt (String results[][], String record[]) {

int records =0;

String temp[][] =null;

if (results == null){

results = new String[1][];

results[0] = record;

} //end of storeIt

else {

records = results.length;

temp = new String[records+1][];

temp[records] = record;

for (int i =0 ; i <records; i++)

temp = results;

results = temp;

}

return results;

}

public AddressBook find( String aField, String key) {





int field = translate(aField);

int records = book.length;

String results[][]=null;

AddressBook resultingSet = new AddressBook();

................................

..........................

. ...............................

// careful here!

// We are creating an AddressBook with the same fieldsandcontaining the records that matched

// write here the code to create it and initialize it before returning it

return resultingSet;

} // end of find





public void sort( String aField)

{

int a, b;

int field = translate(aField);

...................................................

...... ......................................

if(book[field].compareTo(book[b + 1][field]) > 0)//Compares the strings

......................................................

}





public void printRecords() {





int records = book.length;





int fields = book[0].length;





for (int i = 0 ; i < records; i++) {

for (int j =0 ; j < fields; j++)

System.out.print(book[j] + " ");

System.out.println("");

}

}









} //end of class





public class AddressBookTest {

public static void main (String [] args) {





String [] fields = {"Name", "Phone", "Address","City","State","Zip"};





String data [] [] = { {"John", "2126223456", "123 X Road", "Histown", "PA", "12345"},

{"Mary", "5084567898", "5 Yo Street", "Hertown", "MA", "23456"},

{ "Bill", "2124356788", "13 Badluck St", "Histown", "PA", "12345"},

};

AddressBook addrBook = new AddressBook();

addrBook.initAddressBook(fields,data);





AddressBook s = addrBook.find("Name", "ry"); //return all records containing 123 in the ZIP





s.printRecords();





addrBook.sort( "Name") ; // sort all records by zip code





addrBook.printRecords();





} // end of main





} // end of class

Topic: Interface Previous Topic   Next Topic Topic: how to implement a search engine ?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use