Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1.  
  2. import java.io.FileNotFoundException;
  3. import java.io.FileReader;
  4. import java.util.NoSuchElementException;
  5. import java.util.Scanner;
  6.  
  7. /**
  8. * Course: EECS 114 Fall 2015
  9. *
  10. * First Name: Franklin Last Name: Hool Lab Section: 1A email address:
  11. * fhool@uci.edu
  12. *
  13. * Assignment: Lab 2 Filename : Main
  14. *
  15. * I hereby certify that the contents of this file represent my own original
  16. * individual work. Nowhere herein is there code from any outside resources such
  17. * as another individual, a website, or publishings unless specifically
  18. * designated as permissible by the instructor or TA.
  19. */
  20. public class Main {
  21. static FileReader reader;
  22.  
  23. public static void main(String[] args) {
  24. // TODO: Input a file name from args[0] (it can be have a directory
  25. // appended to it) and open file to store in Scanner object.
  26.  
  27. DoublyLinkedList<Integer> numLinkedList = new DoublyLinkedList<Integer>();
  28.  
  29. numLinkedList.add(0, 1);
  30. System.out.println(numLinkedList.head.t);
  31. numLinkedList.add(0, 5);
  32. System.out.println(numLinkedList.head.t);
  33. numLinkedList.add(0, 6);
  34. System.out.println(numLinkedList.head.t);
  35. numLinkedList.remove(0);
  36. System.out.println(numLinkedList.head.t);
  37. System.out.println("size: "+numLinkedList.size());
  38. numLinkedList.remove(new Integer(5));
  39. System.out.println("HERE: "+numLinkedList.head.t);
  40. System.out.println("Size: "+ numLinkedList.size());
  41. System.out.println("Empty: "+numLinkedList.isEmpty());
  42. for(int i=0;i<numLinkedList.size();i++)
  43. {
  44. System.out.println(numLinkedList.get(i));
  45. }
  46. /*Scan all the lines of the file and add them to the Doubly Linked List
  47. * Traces exception when there are no more lines */
  48.  
  49. DoublyLinkedList<String> stringLinkedList = new DoublyLinkedList<String>();
  50.  
  51. try {
  52. Scanner fileScanner = new Scanner(new FileReader(args[0]));
  53. String line;
  54.  
  55. while ((line = fileScanner.nextLine()) != null) {
  56. stringLinkedList.add(-1, line);
  57. System.out.println(line);
  58. }
  59. fileScanner.close();
  60. System.out.println(stringLinkedList.size());
  61. } catch (FileNotFoundException e) {
  62. // TODO Auto-generated catch block
  63. e.printStackTrace();
  64. } catch (NoSuchElementException e) {
  65. System.out.println("No more Lines");
  66. e.printStackTrace();
  67. }
  68.  
  69.  
  70.  
  71. // TODO: Add code to print the elements in numLinkedList
  72. // TODO: Add more test cases for DoublyLinkedList, which should contain
  73. // number elements inputted from Scanner object. Include test case for
  74. // String.
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement