Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. import java.io.*;
  2. import java.lang.*;
  3. import java.util.*;
  4.  
  5. public class HW4
  6. {
  7. public static void main(String[] args)
  8. {
  9. int limit = 0;
  10. String blank = "";
  11. try
  12. {
  13. File file = new File("prg4.txt");//first buffer reader, for length of file
  14. FileReader read = new FileReader(file);
  15. BufferedReader buffer = new BufferedReader(read);
  16. StringBuffer stringBuff = new StringBuffer();
  17. String line;
  18. while((line = buffer.readLine()) != null)
  19. {
  20. limit = limit + 1;
  21. }
  22. read.close();// closes reader
  23.  
  24. FileReader read2 = new FileReader(file);//second bufferreader, this time
  25. //for an array
  26. BufferedReader buffer2 = new BufferedReader(read2);
  27. StringBuffer stringBuff2 = new StringBuffer();
  28. System.out.println(limit);
  29. String[] scatMan = new String[limit];
  30. for(int i=0;i<limit;i++) //fills scatMan[] with values from file
  31. {
  32. scatMan[i] = blank;
  33. scatMan[i] = buffer2.readLine();
  34. }
  35. //First section (commalist)
  36. System.out.println(scatMan[0]);
  37. System.out.println("Length is " + scatMan[0].length());
  38. System.out.println("Capacity is hard and I didn't figure out how to do it");
  39. String[] commaList = scatMan[0].split(",");
  40. int size = commaList.length;
  41. for(int j=0;j<size;j++)
  42. {
  43. System.out.print(commaList[j] + " ");
  44.  
  45. }
  46.  
  47. //Second section (e->z)
  48. System.out.println();
  49. System.out.println(scatMan[1]);
  50. String eed = scatMan[1].replace("e", "z"); //creates a string, uses replace method
  51. System.out.println(eed);
  52.  
  53. //Third section (append)
  54. System.out.println(scatMan[2]);
  55. System.out.println(scatMan[3]);
  56. String s = scatMan[2].concat(scatMan[3]); //leaves a space but is still appended
  57. System.out.println(s);
  58.  
  59. //Fourth Section (delete+insert)
  60. System.out.println(scatMan[4]);
  61. s = scatMan[4].substring(0,1)+scatMan[4].substring(2);
  62. System.out.println(s);//substring manipulation statements
  63. s = "Q" + s.substring(0, s.length());
  64. System.out.println(s);
  65.  
  66. //Fifth Section (reverse)
  67. s = scatMan[5];
  68. String rev = new StringBuffer(s).reverse().toString();
  69. System.out.println(rev);
  70. rev = rev.substring(0,4) + "J" + rev.substring(5, rev.length());
  71. System.out.println(rev);
  72. //Sixth section (selective substring)
  73. s = scatMan[6];
  74. String z = s.substring(5,s.length());
  75. s = s.substring(0,5);
  76. System.out.println(s);
  77. System.out.println(z);
  78. //Seventh section (primitive vs method equality)
  79. System.out.println("Scatman @ 7: " + scatMan[7]);
  80. System.out.println("Scatman @ 8: " + scatMan[8]);
  81. if("Lumberjacks" == "Lumberjacks")
  82. {
  83. System.out.println("True, literally it is equal");
  84. } else {
  85. System.out.println("FALSE! Literally it is not equal");
  86. }
  87.  
  88. if(scatMan[7] == scatMan[8])
  89. {
  90. System.out.println("True, they are methodically equal");
  91. } else {
  92. System.out.println("FALSE!!! Methodically they are not equal");
  93. }
  94.  
  95. //8th section (compareTo)
  96. System.out.println("Scatman 9-11: " + "\n" + scatMan[9]);
  97. System.out.println(scatMan[10]); //print statements
  98. System.out.println(scatMan[11]);
  99. int var1, var2, var3;
  100. var1 = scatMan[9].compareTo( scatMan[10]);
  101. var2 = scatMan[11].compareTo( scatMan[9]);
  102. var3 = scatMan[10].compareTo( scatMan[11]);
  103. System.out.println("Values are " + var1 + ", " + var2 + ", " + var3); //creats + sorts array of results
  104. int[] sorter = new int[] {var1,var2,var3};
  105. Arrays.sort(sorter);
  106.  
  107. System.out.println("Sorted: " + scatMan[9] +", " + scatMan[10] +", " + scatMan [11]);//hardcoded values because I'm lazy and can't figure it out
  108.  
  109.  
  110. }
  111. catch (IOException e) //de-breaking mechanism
  112. {
  113. e.printStackTrace();
  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. //scabadabadoobadabadoobadibeydaboo, im the scatMan
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement