jdalbey

GenericSearch Student Submissions

Jan 17th, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.78 KB | None | 0 0
  1. dwong28
  2.  
  3. /**
  4. * Write a description of class GenericUtilities here.
  5. *
  6. * @author (your name)
  7. * @version (a version number or a date)
  8. */
  9. public class GenericUtilities
  10. {
  11.  
  12. public static <SomeType> boolean search (SomeType [] theArray, SomeType target)
  13. {
  14. for (int arrayPosition = 0; arrayPosition < theArray.length; arrayPosition++)
  15. {
  16. if (theArray[arrayPosition].equals(target))
  17. {
  18. return true;
  19. }
  20. }
  21. return false;
  22. }
  23.  
  24. public static <SomeType> void print (SomeType [] theArray)
  25. {
  26. for(SomeType arrayValue : theArray)
  27. {
  28. System.out.println(arrayValue);
  29. }
  30.  
  31. }
  32. }
  33. cflorka
  34.  
  35. /**
  36. * Lab04 Generic search and print.
  37. *
  38. * @author Clint Florka
  39. * @author Samuel Stearns
  40. * @version 1-13-14
  41. */
  42. public class GenericUtilities
  43. {
  44. /**
  45. * Searches an array.
  46. *
  47. * @param theArray the array to check
  48. * @param target the Object checked
  49. * @return true if the target is in the array, false else
  50. */
  51. public static <SomeType> boolean search (SomeType [] theArray, SomeType target)
  52. {
  53. boolean inArray = false;
  54. for(int index = 0; index < theArray.length; index++)
  55. {
  56. if(theArray[index].equals(target))
  57. {
  58. inArray = true;
  59. }
  60. }
  61. return inArray;
  62. }
  63.  
  64. /**
  65. * Prints each element of the array.
  66. *
  67. * @param theArray the array to print
  68. */
  69. public static <SomeType> void print (SomeType [] theArray)
  70. {
  71. for(int index = 0; index < theArray.length; index++)
  72. {
  73. System.out.println(theArray[index]);
  74. }
  75. }
  76. }
  77. goscott
  78. icotteng
  79.  
  80. /**
  81. * Write a description of class GenericUtilities here.
  82. *
  83. * @author Ian Cottengim, Akshay Sharma
  84. * @version 1/13/14
  85. */
  86. public class GenericUtilities
  87. {
  88. public static <SomeType> boolean search (SomeType [] theArray, SomeType target)
  89. {
  90. boolean found = false;
  91. for(SomeType generic : theArray)
  92. {
  93. if(generic.equals(target))
  94. {
  95. found = true;
  96. }
  97. }
  98. return found;
  99. }
  100. public static <SomeType> void print (SomeType [] theArray)
  101. {
  102. for(SomeType generic : theArray)
  103. {
  104. System.out.print(generic + " ");
  105. }
  106. System.out.println();
  107. }
  108. }
  109. iswilson
  110. import java.util.*;
  111.  
  112. /**
  113. * Searches and Prints lists of Objects
  114. *
  115. * @author Ian Meeder & Ian Wilson
  116. * @version Lab 4
  117. */
  118.  
  119.  
  120. public class GenericUtilities
  121. {
  122.  
  123.  
  124. /**
  125. * Searches through and finds target in object array.
  126. * @param theArray array of objects
  127. * @param target the element to be searched for
  128. * @return true if found, false otherwise
  129. */
  130. public static <SomeType> boolean
  131. search(SomeType [] theArray, SomeType target)
  132. {
  133. boolean bool = false;
  134. for (int count = 0; count < theArray.length; count++)
  135. {
  136. if (theArray[count].equals(target))
  137. {
  138. bool = true;
  139. }
  140. }
  141. return bool;
  142. }
  143.  
  144. /**
  145. * Prints out all elements in an array.
  146. * @param theArray the array to print
  147. */
  148. public static <SomeType> void print (SomeType [] theArray)
  149. {
  150. for (SomeType item : Arrays.asList(theArray))
  151. {
  152. System.out.print(item + " ");
  153. }
  154. }
  155. }
  156. jchoi30
  157. /**
  158. * Implements generic methods to be used on arrays of any type.
  159. *
  160. * @author Josh Choi and John Shamshoian
  161. * @version Lab 4
  162. */
  163.  
  164. public class GenericUtilities
  165. {
  166. /**
  167. * Linear search method.
  168. *
  169. * @param theArray The array to be passed in.
  170. * @param target The object that the method searches for.
  171. */
  172. public static < SomeType > boolean search
  173. (SomeType [] theArray, SomeType target)
  174. {
  175. boolean result = false;
  176. for (int itor = 0; itor < theArray.length; itor++)
  177. {
  178. if (theArray[itor].equals(target) || result == true)
  179. {
  180. result = true;
  181. }
  182. else
  183. {
  184. result = false;
  185. }
  186. }
  187. return result;
  188. }
  189. /**
  190. * Prints every element in the array.
  191. *
  192. * @param theArray the generic array to print.
  193. */
  194. public static < SomeType > void print (SomeType [] theArray)
  195. {
  196. for (SomeType item : theArray)
  197. {
  198. System.out.println(item.toString());
  199. }
  200. }
  201.  
  202. }
  203. jlroman
  204.  
  205. /**
  206. * This class will search and print elements of any type in an array.
  207. *
  208. * @author Connor Batch, Jose Roman
  209. * @version 1/13/14
  210. */
  211. public class GenericUtilities
  212. {
  213. /**
  214. * Searches for element in array.
  215. *
  216. * @SomeType[] array containing all the elements.
  217. * @SomeType element that is being searched for.
  218. *
  219. * @return boolean true or false if found.
  220. */
  221. public static <SomeType> boolean search(SomeType[] theArray, SomeType target)
  222. {
  223. boolean found = false;
  224.  
  225. /*Will iterate through the array.*/
  226. for (int index = 0; index < theArray.length; index++)
  227. {
  228. /*Determine if found.*/
  229. if (theArray[index].equals(target))
  230. {
  231. found = true;
  232. }
  233. }
  234. return found;
  235. }
  236.  
  237. /**
  238. * Prints out elements in array
  239. *
  240. * @SomeType[] array containing all the elements.
  241. */
  242. public static <SomeType> void print(SomeType[] theArray)
  243. {
  244. /*Will iterate and print elements.*/
  245. for (SomeType element : theArray)
  246. {
  247. System.out.println(element);
  248. }
  249. }
  250. }
  251. jsvillat
  252.  
  253. /**
  254. * A class that searches through an array of a generic type
  255. * and prints out every element.
  256. *
  257. * @author Saul Villatoro
  258. * @author Mitch Lane
  259. * @version 1/13/14
  260. */
  261. public class GenericUtilities
  262. {
  263. /**
  264. * Searches through the array of generic objects for a specific element.
  265. *
  266. * @param <SomeType> The method type
  267. * @param theArray An array of type SomeType of generic objects.
  268. * @param target A SomeType object being searched for.
  269. * @return toReturn A boolean of true if found.
  270. */
  271. public static <SomeType> boolean search(SomeType [] theArray, SomeType target)
  272. {
  273. boolean toReturn = false;
  274.  
  275. // Goes through each element in the array
  276. for(SomeType element : theArray)
  277. {
  278. // If the element being searched is found
  279. if(target.equals(element))
  280. {
  281. toReturn = true;
  282. }
  283. }
  284. return toReturn;
  285. }
  286.  
  287. /**
  288. * Prints each element in an array of generic objects.
  289. * @param <SomeType> The method type
  290. * @param theArray An array to be printed
  291. */
  292. public static <SomeType> void print(SomeType [] theArray)
  293. {
  294. // Goes through each element in the array
  295. for(SomeType element : theArray)
  296. {
  297. System.out.println(element.toString());
  298. }
  299. }
  300. }
  301. katong
  302. import java.util.*;
  303. import java.lang.*;
  304. /**
  305. * GenericUtilities contains a search and print method.
  306. *
  307. * @author Zach Ho
  308. * @author Ka Tong
  309. * @version 1/13
  310. */
  311. public class GenericUtilities
  312. {
  313. /**
  314. * A simple linear search method
  315. *
  316. * @param theArray input array
  317. * @param target what you're searching for
  318. * @return did you find what you were looking for? t/f
  319. */
  320. public static <SomeType> boolean search(SomeType[] theArray, SomeType target)
  321. {
  322. boolean found = false;
  323. for(int i = 0; i< theArray.length; i++)
  324. {
  325. if(theArray[i].equals(target))
  326. {
  327. found = true;
  328. }
  329. }
  330. return found;
  331. }
  332.  
  333. public static <SomeType> void print(SomeType[] theArray)
  334. {
  335. for(int i = 0; i<theArray.length; i++)
  336. {
  337. System.out.println(theArray[i]);
  338. }
  339. }
  340. }
  341. mjzhang
  342. /**
  343. * Implements a generic linear seach method and generic print method.
  344. *
  345. * @author Marek Zhang, Neha Jagannath, Darren Mistica
  346. *
  347. * @version 2014.0
  348. */
  349.  
  350. public class GenericUtilities
  351. {
  352. public static <SomeType> boolean search (SomeType [] theArray, SomeType target)
  353. {
  354. int index;
  355. boolean result = false;
  356.  
  357. for(index = 0; index < theArray.length; index++)
  358. {
  359. if(theArray[index].equals(target))
  360. {
  361. result = true;
  362. }
  363. }
  364.  
  365. return result;
  366.  
  367. }
  368.  
  369. public static <SomeType> void print (SomeType [] theArray)
  370. {
  371. int index;
  372.  
  373. for(index = 0; index < theArray.length; index++)
  374. {
  375. System.out.println(theArray[index]);
  376. }
  377. System.out.println();
  378. }
  379. }
  380. ptran17
  381. /**
  382. * A class containing methods that can used for generic classes.
  383. *
  384. * @author Dat Tran, Liam Kirsh
  385. * @version 1-13-2014
  386. */
  387. public class GenericUtilities
  388. {
  389. /**
  390. * Performs a sequential search of an array
  391. *
  392. * @param theArray the array of SomeType to be searched
  393. * @param target the target to search for
  394. * @return true if found, false otherwise
  395. */
  396. public static <SomeType> boolean search(SomeType[] theArray,
  397. SomeType target)
  398. {
  399. boolean result = false;
  400. for (int index = 0; index < theArray.length && !result; ++index)
  401. {
  402. if (theArray[index].equals(target))
  403. {
  404. result = true;
  405. }
  406. }
  407. return result;
  408. }
  409.  
  410. /**
  411. * Prints the array
  412. *
  413. * @param theArray the array of SomeType to be printed
  414. */
  415. public static <SomeType> void print(SomeType[] theArray)
  416. {
  417. for (SomeType value : theArray)
  418. {
  419. System.out.println(value);
  420. }
  421. }
  422. }
  423. tduong08
  424.  
  425. /**
  426. * GenericUtilities aims to provide simple methods that programmers can reuse for both
  427. * debuging and other purposes.
  428. *
  429. * @author Nikolai Shkurkin, Tommy Duong
  430. * @version Lab 4
  431. *
  432. */
  433. public class GenericUtilities
  434. {
  435.  
  436. /**
  437. * Blah blah
  438. *
  439. * @param <SomeType> The type of the array that is to be searched
  440. * @param theArray A C-style array to be searched
  441. * @param target The item to try to find
  442. * @return A boolean representing if the target was found in the array.
  443. */
  444. public static <SomeType> boolean search(SomeType [] theArray, SomeType target)
  445. {
  446. boolean found = false;
  447.  
  448. //Iterates through tehArray and stops if target is found
  449. for (int index = 0; (index < theArray.length) && !found; index++)
  450. {
  451. SomeType element = theArray[index];
  452.  
  453. //Determining if element was found
  454. if (target == null || element == null) //Either is "null"
  455. {
  456. found = (element == target);
  457. }
  458. else //Objects are initialized
  459. {
  460. found = element.equals(target);
  461. }
  462. }
  463.  
  464. return found;
  465. }
  466.  
  467. /**
  468. * Prints the contents of any array.
  469. *
  470. * @param <SomeType> The type of the array that is to be printed
  471. * @param theArray The C-style array whose contents are to be displayed
  472. */
  473. public static <SomeType> void print(SomeType [] theArray)
  474. {
  475. //Prints each element of the array
  476. for (SomeType element : theArray)
  477. {
  478. System.out.println(element);
  479. }
  480. }
  481. }
  482. vmvilla
  483. import java.util.*;
  484.  
  485. /**
  486. * This class recieves an array of any type.
  487. * Contains methods to search array for specified object
  488. * and to print all Objects in the array.
  489. *
  490. * @author Cory Kross, Vanessa Villa
  491. * @version Lab4
  492. */
  493. public class GenericUtilities
  494. {
  495.  
  496. public GenericUtilities()
  497. {
  498.  
  499. }
  500.  
  501. /**
  502. * Searches array for specified object
  503. *
  504. * @param target The object that will be searched for
  505. * @param <SomeType> A generic object
  506. * @param theArray The array to search through
  507. *
  508. * @return boolean True if object found
  509. */
  510. public static <SomeType> boolean search(SomeType [] theArray, SomeType target)
  511. {
  512. boolean res = false;
  513.  
  514. //loops through array until target found
  515. for(int indx = 0; indx < theArray.length ; indx++ )
  516. {
  517. //Checks index for target
  518. if( theArray[indx].equals(target) )
  519. {
  520. res = true;
  521. indx = theArray.length;
  522. }
  523. }
  524. return res;
  525. }
  526.  
  527. /**
  528. * Prints the objects within the array
  529. *
  530. * @param theArray The Array which will print
  531. * @param <SomeType> A generic object
  532. */
  533. public static <SomeType> void print(SomeType [] theArray)
  534. {
  535. //Loops through the entire array
  536. for(SomeType type : theArray)
  537. {
  538. System.out.println(type);
  539. }
  540.  
  541. }
  542. }
  543. zho
  544.  
  545. /**
  546. * GenericUtilities contains a search and print method.
  547. *
  548. * @author Zach Ho and Ka Tong
  549. * @version 1/13
  550. */
  551.  
  552. import java.util.*;
  553. import java.lang.*;
  554.  
  555. public class GenericUtilities
  556. {
  557. /**
  558. * A simple linear search method
  559. *
  560. * @param theArray input array
  561. * @param target what you're searching for
  562. * @return did you find what you were looking for? t/f
  563. */
  564. public static <SomeType> boolean search(SomeType[] theArray, SomeType target)
  565. {
  566. boolean found = false;
  567. for(int i = 0; i< theArray.length; i++)
  568. {
  569. if(theArray[i].equals(target))
  570. {
  571. found = true;
  572. }
  573. }
  574. return found;
  575. }
  576.  
  577. public static <SomeType> void print(SomeType[] theArray)
  578. {
  579. for(int i = 0; i<theArray.length; i++)
  580. {
  581. System.out.println(theArray[i]);
  582. }
  583. }
  584. }
  585. apolcyn
  586.  
  587. /**
  588. * Linear Search and Print methods on generic types.
  589. *
  590. * @author Alex Polcyn, Sank Yang
  591. * @version 01/13/14
  592. */
  593.  
  594.  
  595. public class GenericUtilities
  596. {
  597.  
  598. /**
  599. * Implementation of a linear search.
  600. *
  601. * @param theArray an array of generic objects
  602. * @param target the item being search for in the array
  603. *
  604. * @return boolean Whether or not the target is found
  605. */
  606. public static <SomeType> boolean search (SomeType [] theArray, SomeType target)
  607. {
  608. int index = 0; // The index used to iterate through the array
  609. boolean found = false; // The flag used to tell if the target has been found
  610.  
  611. // Searches for the target in the list. Ends when target has been found or
  612. // end of list has been reached.
  613. while(found == false && index < theArray.length)
  614. {
  615. // Checking if the list item at the current index matches the target.
  616. if(theArray[index].equals(target))
  617. {
  618. found = true;
  619. }
  620. index++;
  621. }
  622. return found;
  623. }
  624.  
  625. /**
  626. * Prints all the items in the array.
  627. *
  628. * @param theArray the array of generic objects
  629. */
  630. public static <SomeType> void print (SomeType [] theArray)
  631. {
  632. // Iterates through the array and prints every item
  633. for(SomeType element : theArray)
  634. {
  635. System.out.println(element.toString());
  636. }
  637. }
  638.  
  639. }
Advertisement
Add Comment
Please, Sign In to add comment