Java Programmers wanted. Need Help please

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2004
Posts: 5
Reputation: jdl44lfhs is an unknown quantity at this point 
Solved Threads: 0
jdl44lfhs jdl44lfhs is offline Offline
Newbie Poster

Java Programmers wanted. Need Help please

 
0
  #1
Nov 15th, 2004
I am new to programming and I am trying to learn, I got a book and it has some problems in it,
Here is one of the problems that I would like some help with if anyone could help me through it
of if you have any code that is similar to what I am looking for that would be greatly appreciated.
The book did not give me any of the answers. Thanks in advance. Josh

I need a lot of help with writing a program that will read a file of text,
and accomplish the following:

1.) Read in a list of names, addresses, zip codes, and phone numbers.
2.) Allow the user to select subgroups on any field (e.g. lists who reside in
the State of Texas, or whose telephone numbers are in the area code.
3.) Maintain alphabetized sublists of the subgroups selected by the user
4.) Print a summary of individuals in each subgroup selected by the user
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Java Programmers wanted. Need Help please

 
0
  #2
Nov 15th, 2004
The idea of those problems is that you solve them yourself so you'll learn something in the process, it's not that you get others to solve them for you so you can show your teacher you've done your homework.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 5
Reputation: jdl44lfhs is an unknown quantity at this point 
Solved Threads: 0
jdl44lfhs jdl44lfhs is offline Offline
Newbie Poster

Re: Java Programmers wanted. Need Help please

 
0
  #3
Nov 15th, 2004
Im actually not in school anymore, this is something that I am wanting to learn on my own and I got a book and there are some questions in it, this was one of the questions that was in the book. I was just looking for some help thats all, a beginning point or some pointers. This is something that does not come easy to me and I was just looking for some help with it. I wish I were still in school then at least there would be someone for me to ask there. But I am not so that is why I have come here, I just heard that this is a really good well-established website on helping people out.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 84
Reputation: jerbo is an unknown quantity at this point 
Solved Threads: 1
jerbo jerbo is offline Offline
Junior Poster in Training

Re: Java Programmers wanted. Need Help please

 
0
  #4
Nov 15th, 2004
Take a stab at it first, then post what you have. It's easy to do the work for you, but then what would you learn from it? If you are interested in code, then check out something like: http://www.planet-source-code.com/
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,860
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Senior Bitch

Re: Java Programmers wanted. Need Help please

 
0
  #5
Nov 15th, 2004
>I was just looking for some help thats all
We'll be happy to help, when you ask a question that doesn't resemble "Help me with the problem I just pasted but haven't actually tried to solve yet".

>I just heard that this is a really good well-established website on helping people out.
It is. We just don't do your work for you, nor do we take problems cut out of a book and turn them into full blown tutorials. You're expecting too much and that will only result in your being disappointed.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 5
Reputation: jdl44lfhs is an unknown quantity at this point 
Solved Threads: 0
jdl44lfhs jdl44lfhs is offline Offline
Newbie Poster

Re: Java Programmers wanted. Need Help please

 
0
  #6
Nov 16th, 2004
Thanks Guys for all your posts, Im not looking for a hand out, I am sorry that I made it sound that way, its just for me I kind of feel like a blind man running through a mine field. Wondering which way to go where to start how I should start, stuff like that. But I am going to give it my best, and post what I get.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Java Programmers wanted. Need Help please

 
0
  #7
Nov 16th, 2004
Start from the beginning, and start coding.
You learn little from reading code, you got to get your hands dirty.

Type in those examples (most books have short ones), see what they do and play around with them.
Change them around to see what happens, apply that knowledge the book is trying to give you.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 4
Reputation: hurdy011 is an unknown quantity at this point 
Solved Threads: 1
hurdy011 hurdy011 is offline Offline
Newbie Poster

Re: Java Programmers wanted. Need Help please

 
0
  #8
Nov 16th, 2004
i pasted my problem on the correct forum and included more of the code so that you get a better idea of what im doing. any pointers will be appreciated, thanks!
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 5
Reputation: jdl44lfhs is an unknown quantity at this point 
Solved Threads: 0
jdl44lfhs jdl44lfhs is offline Offline
Newbie Poster

Re: Java Programmers wanted. Need Help please

 
0
  #9
Dec 16th, 2004
ok I think I did it alright. Anyone wanna comment please do, all comments are welcome. THanks so much. Josh

Author: Joshua
Language: Java
Date Created: 12-6-2004


The purpose of this program is to prompt a user to search for someone or someplace, or both
and then to show the results of the search.







  1. /**
  2.  * This class holds information about a record.
  3.  * i.e, will have name, address, city state, zip code, phone number
  4.  *
  5.  * This class assumes that records will be in following format.
  6.  *
  7.  * |Name
  8.  * |Address
  9.  * |City, ST ZIP
  10.  * |Phone
  11.  *
  12.  * ST = Short name (2 chars) State
  13.  * ZIP = 5 Number zip code.
  14.  */
  15. public class DataRecord
  16. {
  17. /**
  18.   * Individual Name
  19.   */
  20. private String name = "";
  21.  
  22. /**
  23.   * Individual Address
  24.   */
  25. private String address = "";
  26.  
  27. /**
  28.   * Individual City
  29.   */
  30. private String city = "";
  31.  
  32. /**
  33.   * Individual State
  34.   */
  35. private String state = "";
  36.  
  37. /**
  38.   * Individual Zip
  39.   */
  40. private String zip = "";
  41.  
  42. /**
  43.   * Individual Phone
  44.   */
  45. private String phone = "";
  46.  
  47. /**
  48.   * Constructor which initializes the record.
  49.   * @param String line1 First line of record from the file.
  50.   * @param String line2 Second line.
  51.   * @param String line3 Third line.
  52.   * @param String line4 Fourth line.
  53.   */
  54. public DataRecord(String line1, String line2, String line3, String line4)
  55. {
  56. setName(line1);
  57. setAddress(line2);
  58. setCityStateZip(line3);
  59. setPhone(line4);
  60. }
  61.  
  62. /**
  63.   * Parse the line 3 to set City state and zip code.
  64.   * @param String line3 third line of record as reaad from data file.
  65.   */
  66. public void setCityStateZip(String line3)
  67. {
  68. int index = line3.indexOf(',');
  69.  
  70. if (index < 1)
  71. {
  72. throw new RuntimeException("Invalid Record. comma not found." +
  73. "Expected: \"city,ST ZIP\". " +
  74. "Got: " + line3);
  75. }
  76.  
  77. String tmpLine = line3.substring(index+1).trim();
  78. if ((tmpLine.length() < 5) ||
  79. (tmpLine.charAt(2) != ' '))
  80. {
  81. throw new RuntimeException("Invalid Record. " +
  82. "Expected: \"city,ST ZIP\". " +
  83. "Got: " + line3);
  84. }
  85.  
  86. setCity(line3.substring(0, index));
  87. setState(tmpLine.substring(0,2));
  88. setZip(tmpLine.substring(4));
  89. }
  90.  
  91. /**
  92.   * Returns the Individual's city.
  93.   * @return String, city.
  94.   */
  95. public String getCity()
  96. {
  97. return city;
  98. }
  99.  
  100. /**
  101.   * Returns the Individual's name.
  102.   * @return String, name.
  103.   */
  104. public String getName()
  105. {
  106. return name;
  107. }
  108.  
  109. /**
  110.   * Returns the Individual's Phone number.
  111.   * @return String, phone number.
  112.   */
  113. public String getPhone()
  114. {
  115. return phone;
  116. }
  117.  
  118. /**
  119.   * Returns the Individual's state.
  120.   * @return String, state.
  121.   */
  122. public String getState()
  123. {
  124. return state;
  125. }
  126.  
  127. /**
  128.   * Returns the Individual's zip code.
  129.   * @return String, Zip code.
  130.   */
  131. public String getZip()
  132. {
  133. return zip;
  134. }
  135.  
  136. /**
  137.   * Sets the Individual's city.
  138.   * @param String string city.
  139.   */
  140. public void setCity(String string)
  141. {
  142. city = string;
  143. }
  144.  
  145. /**
  146.   * Sets the Individual's name.
  147.   * @param String string name.
  148.   */
  149. public void setName(String string)
  150. {
  151. name = string;
  152. }
  153.  
  154. /**
  155.   * Sets the Individual's phone.
  156.   * @param String string phone.
  157.   */
  158. public void setPhone(String string)
  159. {
  160. phone = string;
  161. }
  162.  
  163. /**
  164.   * Sets the Individual's state.
  165.   * @param String string state
  166.   */
  167. public void setState(String string)
  168. {
  169. state = string;
  170. }
  171.  
  172. /**
  173.   * Sets the Individual's zip code.
  174.   * @param String string Zip code.
  175.   */
  176. public void setZip(String string)
  177. {
  178. zip = string;
  179. }
  180.  
  181. /**
  182.   * @return String, User Address
  183.   */
  184. public String getAddress()
  185. {
  186. return address;
  187. }
  188.  
  189. /**
  190.   * @param String address UserAddress
  191.   */
  192. public void setAddress(String address)
  193. {
  194. this.address = address;
  195. }
  196.  
  197. /**
  198.   * Gives String representation of this record.
  199.   * @return String, represntation of this record.
  200.   */
  201. public String toString()
  202. {
  203. StringBuffer result = new StringBuffer();
  204. /*
  205.   result.append("Name:" + getName() + "; " );
  206.   result.append("Address:" + getAddress() + "; " );
  207.   result.append("City:" + getCity() + "; " );
  208.   result.append("State:" + getState() + "; " );
  209.   result.append("Zip:" + getZip() + "; " );
  210.   result.append("Phone:" + getPhone());
  211.   */
  212. result.append(getName() + "; " );
  213. result.append(getAddress() + "; " );
  214. result.append(getCity() + "; " );
  215. result.append(getState() + "; " );
  216. result.append(getZip() + "; " );
  217. result.append(getPhone());
  218. return result.toString();
  219. }
  220.  
  221. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 5
Reputation: jdl44lfhs is an unknown quantity at this point 
Solved Threads: 0
jdl44lfhs jdl44lfhs is offline Offline
Newbie Poster

Re: Java Programmers wanted. Need Help please

 
0
  #10
Dec 16th, 2004
Author: Joshua
Language: Java
Date Created: 12-10-2004


The purpose of this program is to take user inputs and to read data and to store data, and
subgroups. It also controls the user menu






  1. import java.io.BufferedReader;
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7.  
  8. /**
  9.  * This is the main class. It controls the user menus, take user inputs,
  10.  * reads the data file and manages the subgroups.
  11.  * It also maintains subgroups selected by the user.
  12.  */
  13. public class MList
  14. {
  15.  
  16. /**
  17.   * Reader to read user inputs from command line.
  18.   */
  19. private BufferedReader in = null;
  20.  
  21. /**
  22.   * Root/first node of the linked list which holds the Data Records.
  23.   */
  24. private List individuals = null;
  25.  
  26. /**
  27.   * This list will contain the subgroups selcted by the user.
  28.   */
  29. private List subGroups = new ArrayList();
  30.  
  31. /**
  32.   * Initializes the reader.
  33.   */
  34. private void init()
  35. {
  36. in = new BufferedReader(new InputStreamReader(System.in));
  37. System.out.println("At any given point of time enter \"EXIT\" to exit the application.");
  38. }
  39.  
  40. /**
  41.   * gets file name from the user & then read the data
  42.   */
  43. private void readfile()
  44. {
  45. while (true)
  46. {
  47. System.out.print("Please enter the path and name of Data File: ");
  48. try
  49. {
  50. String fileName = getLine();
  51. readfile(fileName);
  52. break;
  53. }
  54. catch (IOException e)
  55. {
  56. System.out.println("Please enter a valid file name. ");
  57. }
  58. }
  59. }
  60.  
  61.  
  62. /**
  63.   * Reads the data file.
  64.   * @param String fileName Filename of the data file as provided by user.
  65.   * @throws IOException
  66.   */
  67. private void readfile(String fileName)throws IOException
  68. {
  69. BufferedReader reader = new BufferedReader(
  70. new InputStreamReader(
  71. new FileInputStream(fileName)));
  72.  
  73. String line1 = null;
  74. String line2 = null;
  75. String line3 = null;
  76. String line4 = null;
  77. String blankLine = null;
  78.  
  79. individuals = new ArrayList();
  80. while(true)
  81. {
  82. //Read first line of the record.
  83. line1 = reader.readLine();
  84. if (line1 == null)
  85. {
  86. break;
  87. }
  88. //Read Sec line of the record.
  89. line2 = reader.readLine();
  90. if (line2 == null)
  91. {
  92. System.out.println("WARNING: Incomplete record at the end of the file.");
  93. break;
  94. }
  95.  
  96. //Read third line of the record.
  97. line3 = reader.readLine();
  98. if (line3 == null)
  99. {
  100. System.out.println("WARNING: Incomplete record at the end of the file.");
  101. break;
  102. }
  103. //Read fourth line of the record.
  104. line4 = reader.readLine();
  105. if (line4 == null)
  106. {
  107. System.out.println("WARNING: Incomplete record at the end of the file.");
  108. break;
  109. }
  110. //create a record.
  111. DataRecord rec = new DataRecord(line1,line2,line3,line4);
  112. individuals.add(rec);
  113. //System.out.println(rec);
  114. //Read blank line.
  115. blankLine = reader.readLine();
  116. if (blankLine == null)
  117. {
  118. break;
  119. }
  120. }
  121. }
  122.  
  123. /**
  124.   * Reads the information enterd by the user on console. It also stops
  125.   * the program if user enters exit.
  126.   * @return String, the line entered by the user.
  127.   * @throws IOException
  128.   */
  129. private String getLine() throws IOException
  130. {
  131. String line = in.readLine();
  132. if ("EXIT".equalsIgnoreCase(line))
  133. {
  134. System.exit(0);
  135. }
  136. return line;
  137. }
  138.  
  139. /**
  140.   * Start method which manages the follow.
  141.   */
  142. private void start() throws IOException
  143. {
  144. readfile();
  145. manageSubGroups();
  146. }
  147.  
  148. /**
  149.   * Prints subgroup menu
  150.   *
  151.   */
  152. private void printSubGroupMenu()
  153. {
  154. System.out.println("Please select your choice of the SubGroup by field: ");
  155. System.out.println("1. SubGroup by matching name");
  156. System.out.println("2. SubGroup by matching Address");
  157. System.out.println("3. SubGroup by City");
  158. System.out.println("4. SubGroup by State");
  159. System.out.println("5. SubGroup by ZipCode");
  160. System.out.println("6. SubGroup by Phone Area Code(first 3 digits)");
  161. System.out.println("7. SubGroup by matching phone number");
  162. System.out.println("8. Print selected SubGroups");
  163. System.out.println("0. Exit");
  164. System.out.print("Please enter your choice:");
  165. }
  166.  
  167. /**
  168.   * This method Manages Subgroups, prints menu, takes user input and
  169.   * then prints the summary.
  170.   */
  171. private void manageSubGroups() throws IOException
  172. {
  173. String choice = "";
  174. int iChoice = -1;
  175. String criteria = "";
  176. String msg = "";
  177. subGroups = new ArrayList();
  178. while(!"0".equals(choice))
  179. {
  180. printSubGroupMenu();
  181. choice = getLine();
  182. if ("1".equals(choice))
  183. {
  184. //Matching name
  185. iChoice = 1;
  186. System.out.print("Enter matching name: ");
  187. msg = "Individuals with matching name";
  188. }
  189. else if ("2".equals(choice))
  190. {
  191. //matching address
  192. iChoice = 2;
  193. System.out.print("Enter matching Address: ");
  194. msg = "Individuals with matching Address";
  195. }
  196. else if ("3".equals(choice))
  197. {
  198. //matching city
  199. iChoice = 3;
  200. System.out.print("Enter City starting with: ");
  201. msg = "Individuals with in the specified City";
  202. }
  203. else if ("4".equals(choice))
  204. {
  205. //matching state
  206. iChoice = 4;
  207. System.out.print("Enter State starting with (2 letters): ");
  208. msg = "Individuals with in the specified state";
  209. }
  210. else if ("5".equals(choice))
  211. {
  212. //matching zip
  213. iChoice = 5;
  214. System.out.print("Enter matching Zip Code: ");
  215. msg = "Individuals with matching Zip code";
  216. }
  217. else if ("6".equals(choice))
  218. {
  219. //matching area code
  220. iChoice = 6;
  221. System.out.print("Enter Phone area code starting with (3 digits): ");
  222. msg = "Individuals with matching Area code";
  223. }
  224. else if ("7".equals(choice))
  225. {
  226. //matching phone number
  227. iChoice = 7;
  228. System.out.print("Enter matching phone number: ");
  229. msg = "Individuals with matching Phone";
  230. }
  231. else if ("8".equals(choice))
  232. {
  233. //print all the selected subGroups
  234. printsubList(subGroups);
  235. break;
  236. }
  237. else if ("0".equals(choice))
  238. {
  239. return;
  240. }
  241. else
  242. {
  243. System.out.println("Invalid choice. Please enter again a Valid choice.");
  244. continue;
  245. }
  246. criteria = getLine();
  247.  
  248. prepareSubList(iChoice, criteria, msg);
  249. }
  250. }
  251.  
  252. /**
  253.   * Prints all the details of the subgroups selcted by users and the
  254.   * correspondings sublists.
  255.   * @param List userSubGroups List of user subgroups
  256.   */
  257. private void printsubList(List userSubGroups)
  258. {
  259. for(int i = 0 ; i < subGroups.size(); i++)
  260. {
  261. ((SubGroup)userSubGroups.get(i)).print();
  262. }
  263. }
  264.  
  265. /**
  266.   * Adds the subgroup selected by the user, prepares the subList associated
  267.   * with the user selected sub group.
  268.   * @param int iChoice User Choice
  269.   * @param String criteria SubGroup selection criteria
  270.   * @param String msg Message to be printed
  271.   */
  272. private void prepareSubList(int iChoice,
  273. String criteria, String msg)
  274. {
  275. SubGroupSelector selector = getSelector(iChoice, criteria);
  276. SubGroup subGroup = new SubGroup(iChoice, criteria, msg);
  277.  
  278. for(int i = 0 ; i < individuals.size(); i++)
  279. {
  280. DataRecord rec = (DataRecord)individuals.get(i);
  281. if (selector.isEligibleForSubGroup(rec))
  282. {
  283. subGroup.addIndividual(rec);
  284. }
  285. }
  286. subGroups.add(subGroup);
  287. }
  288.  
  289. /**
  290.   * This method creates and returns appropriate selector based on
  291.   * user choice.
  292.   * @param int iChoice User choice.
  293.   * @param String criteria Criteria String to used for selection
  294.   * @return SubGroupSelector, based on user choice.
  295.   */
  296. private SubGroupSelector getSelector(int iChoice, String criteria)
  297. {
  298. switch(iChoice)
  299. {
  300. case 1: return new SelectorByName(criteria);
  301. case 2: return new SelectorByAddress(criteria);
  302. case 3: return new SelectorByCity(criteria);
  303. case 4: return new SelectorByState(criteria);
  304. case 5: return new SelectorByZip(criteria);
  305. case 6: return new SelectorByAreaCode(criteria);
  306. case 7: return new SelectorByPhone(criteria);
  307. }
  308. return null;
  309. }
  310.  
  311. /**
  312.   * Main method as called by the JVM.
  313.   * @param args
  314.   */
  315. public static void main(String[] args)
  316. {
  317. MList mlist = new MList();
  318. try
  319. {
  320. mlist.init();
  321. mlist.start();
  322. }
  323. catch(Exception e)
  324. {
  325. System.out.println("**** ERROR ****");
  326. System.out.println(e);
  327. }
  328. }
  329.  
  330. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 3005 | Replies: 9
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC