[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Search funtion not working

Asked by spoilerbalto in New to Java Programming, Java Programming Language

Can someone please help me with my program?
I have tried to get my search funtion to work in my program, but it is not working.
Please help me with what is not correct.
I can not use a database and I can not use GUI. I can only use arrays and loops.
What is happening is, the search promps are showing up, but when  I am finished entering the information, I receive an error "Exception in thread "main" java.lang.NullPointerException with additional lines beneth it.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
mport java.io.*;  //Java input and output
import java.util.Arrays;  // Allows for arrays in the program
 
 
 
public class teamprojectkelly   //Beginning of the class
 
{
	static  BufferedReader buf =
				 new BufferedReader(new InputStreamReader(System.in));
 
	public static void main(String [] args)  throws Exception //This is the signature of entry point of all desktop apps.
 
		{       // Search chars on output
				String [] Computer = new String[30];
       			String [] Description =  new String[30];
				int [] Price = new int[30];
				int [] Quantity = new int[30];
 
				//Data for the arrays
	            Computer[0] = "Dell OptiPlex";
	            Computer[1] = "Dell Studio Hybrid";
	            Computer[2] = "Dell Optiplex";
	            Computer[3] = "Ahkr-LoCO2PC";
	            Computer[4] = "Akhter-LoCO2PC";
	            Computer[5] = "Akhter-LoCO2PC";
	            Computer[6] = "Akhter-LoCO2PC";
	            Computer[7] = "AMI Computera AIM PC";
				Computer[8] = "PDS PC Vendor JQ";
			    Computer[9] = "Dell OptiPlex";
			    Computer[10] = "Dell OptiPlex";
			    Computer[11] = "Dell OptiPlex";
			    Computer[12] = "MPC ClientPro";
			    Computer[13] = "Dell Insprion";
			    Computer[14] = "Lenovo ThinkCentre M58/M58p Eco uSFF";
			    Computer[15] = "Lenovo ThinkCentre M58/M58p TOWER";
			    Computer[16] = "Lenovo ThinkCentre M58/M58p SFF";
			    Computer[17] = "Lenovo ThinkCentre M57";
			    Computer[18] = "Samsung 711NT";
			    Computer[19] = "Transource Mirage";
			    Computer[20] = "ZMAX Industria E Comercio LTDA Merchant 3200";
 
				Description[0] = "960Desktop";
				Description[1] = "140g";
				Description[2] = "19-AIO-DT-2.6 Vista";
				Description[3] = "19-AIO-XP";
				Description[4] = "19-AIO-DT.3.0-Vista";
				Description[5] = "19-AIO-DT-3.0-XP";
				Description[6] = "2xx";
				Description[7] = "314272";
				Description[8] = "330 Desktop";
				Description[9] = "330 Mini Tower";
				Description[10] = "360 Desktop";
				Description[11] = "385 Mini Tower";
				Description[12] = "6139";
				Description[13] = "6239";
				Description[14] = "6258";
				Description[15] = "6393";
				Description[16] = "711NT";
				Description[17] = "775";
				Description[18] = "9041100140";
				Description[19] = "XL-NT90-23";
				Description[20] = "XPS-9000-2008";
 
				Price[0] = 600;
				Price[1] = 375;
				Price[2] = 855;
				Price[3] = 698;
				Price[4] = 565;
				Price[5] = 479;
				Price[6] = 1255;
				Price[7] = 659;
				Price[8] = 999;
				Price[9] = 479;
				Price[10] = 896;
				Price[11] = 456;
				Price[12] = 685;
				Price[13] = 1123;
				Price[14] = 1525;
				Price[15] = 1246;
				Price[16] = 1685;
				Price[17] = 989;
				Price[18] = 675;
				Price[19] = 1245;
				Price[20] = 1100;
 
 
				Quantity[0] = 2;
	            Quantity[1] = 3;
	            Quantity[2] = 3;
	            Quantity[3] = 2;
	            Quantity[4] = 45;
	            Quantity[5] = 3;
	            Quantity[6] = 23;
	            Quantity[7] = 23;
				Quantity[8] = 25;
			    Quantity[9] = 12;
			    Quantity[10] = 34;
			    Quantity[11] = 1;
			    Quantity[12] = 3;
			    Quantity[13] = 5;
			    Quantity[14] = 3;
			    Quantity[15] = 3;
			    Quantity[16] = 2;
			    Quantity[17] = 2;
			    Quantity[18] = 5;
			    Quantity[19] = 3;
			    Quantity[20] = 3;
 
		//Getting Strings from the command line
 		String str = new String();
	    String name;
	    int no;
	    int counter=0;
 
					//Call Main Menu
 					do {
 
           					str = MainMenu();
        					no = Integer.parseInt(str);
 
        						switch(no) //Beginning of switch
        							{
										case 1:
					   						System.out.println("Add Inventory");
					    					counter = AddComp(Computer, Description, Price, Quantity);
					   						break;
										case 2:
										    System.out.println("Search Menu");
										    counter = SearchMode(Computer, Description, Price, Quantity);
											break;
										case 3:
											for (int i=0; i <= counter-1; i++)
												{
											        System.out.println(" Computer Name: " + Computer[i] + " Description : " + Description[i] + " Price: " + Price[i]);
												}
	            									  break;
										case 4:
											System.out.println("Sell Inventory");
											counter = SearchMode(Computer, Description, Price, Quantity);
      	    							    break;
										case 5:
												break;
 
										default:
										     System.out.println("Welcome to Web420!");
										     break;
		   							 } //end of switch
							}
        			while (no !=5);
 
 
	 } // end of main
 
 
	 private static String MainMenu()
	 {
        String response =""; // Display for options and options for input
 
        System.out.println("\t\t\t*******************\n\t\t\tComputer Inventory\n\t\t\t*******************\n\t\t\t");
	    System.out.println("\t\t\t(1) Add Computers");
	    System.out.println("\t\t\t(2) Seach Mode");
	    System.out.println("\t\t\t(3) Display Inventory");
	    System.out.println("\t\t\t(4) Sell Inventory");
	    System.out.println("\t\t\t(5) Quit");
 
	    System.out.println("\t\t\tSelect (1-5): ");
// This is the start for adding a computer
		try {
  	    response = buf.readLine();
	    } catch (Exception e) {
	 			   System.out.println("\t\t\tbad input");
	    }
  	    return response;
      }
	private static int AddComp(String[] Computer, String[] Description,int[] Price, int[] Quantity)
	{
			    String str = new String();
			    String Comp;
			    String De;
			    int Worth;
			    String Quant;
			    int counter=0;
 
 
		try{
 
			do {
				System.out.print("");
			 	System.out.print("\t\t\tEnter The Computer Name: ");
				Comp = buf.readLine();
		        Computer[counter] = Comp;
 
				System.out.print("");
		        System.out.print("\t\t\tEnter The Computer Description: ");
				De = buf.readLine();
				Description[counter] = De;
 
				System.out.print("");
		  		System.out.print("\t\t\tEnter The Price: ");
			    str = buf.readLine();
				Worth = Integer.parseInt(str);
				Price[counter] = Worth;
				System.out.print("");
 
				System.out.print("");
				System.out.print("\t\t\tEnter the Quantity: ");
				Quant = buf.readLine();
				Quantity[counter] = Integer.parseInt(Quant);
 
 
		        System.out.println();
 
 
		        System.out.println("Congratulations! You added " + Computer[counter] + ", " + Description [counter] + ", Priced at $" + Price[counter] + ", with " + Quantity[counter] + " in stock");
 
		  		System.out.print("\t\t\tTo finish Enter (E) or (C) to continue: ");
			    str = buf.readLine();
 
 
		        counter++;
 
			}
	        while ( !(str.compareToIgnoreCase("E") == 0));
 
 
		    System.out.println("\n");
 
		}
 
 
		catch (Exception e) {
			System.out.println("\t\t\tbad input");
	    }  //end catch
	    return counter;
 
    } // end of method AddComputer
 
 
// Start to add inventory
 
private static int SearchMode(String[] Computer, String[] Description,int[] Price, int[]Quantity) throws Exception
 
{								String str = new String();
 
			    				int counter=0;
								int no;
 
	           					str = SearchMenu();
	        					no = Integer.parseInt(str);
 
 
    do {
 
 
 
 
	        						switch(no)
	        							{
											case 1:
						   						System.out.println("Add Inventory - Computer");
						   						System.out.print("");
												System.out.print("\t\t\tEnter The Computer Name to Search: ");
												String Comp_Input = buf.readLine();
												System.out.println("\t\t\tYour Entered: "+ Comp_Input);
						   						Arrays.sort(Computer);
						    					int Computer_Search = Arrays.binarySearch(Computer, Comp_Input);
						   						break;
											case 2:
											    System.out.println("Search Menu - Description");
											    System.out.print("");
												System.out.print("\t\t\tEnter The Descripton to Search: ");
												String Description_Input = buf.readLine();
												System.out.println("\t\t\tYour Entered: "+ Description_Input);
											    Arrays.sort(Description);
											    int Description_search = Arrays.binarySearch(Description, Description_Input);
												break;
											case 3:
												System.out.println("Search Menu - Prices");
												System.out.print("");
												System.out.print("\t\t\tEnter The Descripton to Search: ");
												String Price_Input = buf.readLine();
												System.out.println("\t\t\tYour Entered: "+ Price_Input);
   											 	Arrays.sort(Price);
											    int Price_Search = Arrays.binarySearch(Price, Integer.parseInt(Price_Input));
											    break;
											case 4:
	        	    							    //return main(String [] args);
													break;
	        	    						case 5:
	        	    								break;
											default:
											     System.out.println("Welcome to Web420!");
											     break;
			   							 } //end of switch
								}
	        			while (no !=5);
	        			return 0;
 
}
//End to add inventory
 
 
 
private static String SearchMenu()
	 {
        String response ="";
 
        System.out.println("\t\t\t*******************\n\t\t\tSearch Menu\n\t\t\t*******************\n\t\t\t");
	    System.out.println("\t\t\t(1) Search by Computer Name");
	    System.out.println("\t\t\t(2) Search by Computer Description");
	    System.out.println("\t\t\t(3) Search by Prices");
	    System.out.println("\t\t\t(4) Return to Main Menu");
	    System.out.println("\t\t\t(5) Quit.");
 
	    System.out.println("\t\t\tSelect (1-5): ");
 
		try {
  	    response = buf.readLine();
	    } catch (Exception e) {
	 			   System.out.println("\t\t\tbad input");
	    }
  	    return response;
      }
}
[+][-]01/21/09 12:54 AM, ID: 23427910Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: New to Java Programming, Java Programming Language
Sign Up Now!
Solution Provided By: humanonomics
Participating Experts: 2
Solution Grade: A
 
[+][-]01/20/09 06:47 PM, ID: 23426482Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/20/09 07:58 PM, ID: 23426760Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/21/09 01:01 AM, ID: 23427934Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]01/21/09 01:11 AM, ID: 23427975Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02/02/09 11:41 PM, ID: 23534838Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93 - Hierarchy / EE_QW_3_20080625