Advertisement
Guest User

Untitled

a guest
Dec 7th, 2017
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. /* Lausekielinen ohjelmointi 2 Syksy 2017 UTA
  2. * Tallinen Anna (tallinen.anna.e@student.uta.fi)
  3. * Harjoitustyö 2
  4. */
  5.  
  6. /* A program that will print ascii art
  7. * and make it possible for the user to do certain command-line arguments
  8. * concerning the array based ascii art. These commands are print, rotate,
  9. * and info. Info will show the stats of array, such as size and different types
  10. * of elements.
  11. */
  12.  
  13. public class ASCIIArt17{
  14.  
  15. public static int[] readFile(String fileName){
  16. /* a method for reading the file that
  17. * contains the ascii art picture
  18. */
  19.  
  20. //counter for rows
  21. //saves the longest row, i.e. the amount of columns
  22.  
  23. int columns = 0;
  24. int rows = 0;
  25. int[] helperArray = new int[2];
  26.  
  27. //checking exceptions
  28. try{
  29. //opening the file
  30. File filetree = new File("file_tree.txt");
  31.  
  32. Scanner reader = new Scanner(file_tree);
  33.  
  34. //reading
  35. while(reader.hasNextLine()){
  36. // reading one row
  37. String rows = reader.nextLine();
  38. if(rows.length > columns){
  39. longestColumn = rows.length;
  40. }
  41.  
  42. //next row
  43. rows++;
  44. }
  45. //closing the reader
  46. reader.close();
  47. }
  48. //catching exceptions
  49. catch (Exception e){
  50. rows = -1;
  51. }
  52. helperArray[0] = columns;
  53. helperArray[1] = rows;
  54.  
  55. // returning the array containing column and row sizes
  56. return helperArray;
  57. }
  58. public static char[][] readASCII(int rows, int columns){
  59. char[][] helperArray2 = new char[rows][columns];
  60.  
  61. try{
  62. //opening the file
  63. File file_tree = new File("file_tree.txt");
  64.  
  65. Scanner reader = new Scanner(file_tree);
  66.  
  67. int c = 0;
  68. //reading
  69. while(reader.hasNextLine()){
  70. // reading one row
  71. String elements = reader.nextLine();
  72. for(int i = 0; i < elements.length; i++){
  73. helperArray2[c][i] = elements.charAt(i);
  74. }
  75.  
  76. c++;
  77. }
  78. //closing the reader
  79. reader.close();
  80. }
  81. //catching exceptions
  82. catch (Exception e){
  83. rows = -1;
  84. }
  85. }
  86.  
  87. public static char[][] fillArray(String fileName){
  88. int rows = readFile(fileName);
  89. //luentokalvot 6. esimerkki lukemisesta ja tulostamisesta
  90. int columns = 0;
  91. return null;
  92.  
  93. }
  94. public static void printBanner(){
  95. /* a method for printing the opening banner
  96. * i.e. program's name
  97. */
  98. System.out.println("-----------------------");
  99. System.out.println("| A S C I I A r t 1 7 |");
  100. System.out.println("-----------------------");
  101. }
  102. public static void printArray(char[][] gatheredASCIIpicture){
  103. if(array != null){
  104. //amount of rows and columns
  105. int totalRows = gatheredASCIIpicture.length;
  106. int totalCol = gatheredASCIIpicture[0].length;
  107.  
  108. //printing rows
  109. for (int row = 0; row < totalRows; row ++){
  110. //printing row
  111. for (int column = 0; column < totalCol; column++){
  112. System.out.print(gatheredASCIIpicture[row][column]);
  113. }
  114. //new line
  115. System.out.println();
  116. }
  117. }
  118. }
  119. public static void main (String[] args){
  120. if(args.length == 1){
  121. printBanner();
  122. int[] arraySizeValues = readFile(fileName);
  123. int rows = arraySizeValues[1];
  124. int columns = arraySizeValues[0];
  125. char[][] gatheredASCIIpicture = readASCII(rows, columns);
  126.  
  127. char[][] chars = fillArray(args[0]);
  128.  
  129. char[] charArray = new char[]{'#', '@', '&', '$', '%', 'x', '*', 'o', '|', '!', ';',
  130. ':', '\'', ',', '.', ' '};
  131.  
  132. System.out.println("Please, enter a command:");
  133.  
  134.  
  135. if(args[0] == "print"){
  136. printArray(gatheredASCIIpicture);
  137. }
  138. /*
  139. for(int i = 0; i < args.length; i++){
  140.  
  141. int totalColumns;
  142.  
  143. if(args[i] == print){
  144. fillArray(totalRows, columns);
  145. }
  146. else{
  147. if()
  148. }
  149. }
  150. */
  151. }
  152. else{
  153. printBanner();
  154. System.out.println("Invalid command-line argument!");
  155. System.out.println("Bye, see you soon.");
  156. }
  157. }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement