Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Lausekielinen ohjelmointi 2 Syksy 2017 UTA
- * Tallinen Anna (tallinen.anna.e@student.uta.fi)
- * Harjoitustyö 2
- */
- /* A program that will print ascii art
- * and make it possible for the user to do certain command-line arguments
- * concerning the array based ascii art. These commands are print, rotate,
- * and info. Info will show the stats of array, such as size and different types
- * of elements.
- */
- public class ASCIIArt17{
- public static int[] readFile(String fileName){
- /* a method for reading the file that
- * contains the ascii art picture
- */
- //counter for rows
- //saves the longest row, i.e. the amount of columns
- int columns = 0;
- int rows = 0;
- int[] helperArray = new int[2];
- //checking exceptions
- try{
- //opening the file
- File filetree = new File("file_tree.txt");
- Scanner reader = new Scanner(file_tree);
- //reading
- while(reader.hasNextLine()){
- // reading one row
- String rows = reader.nextLine();
- if(rows.length > columns){
- longestColumn = rows.length;
- }
- //next row
- rows++;
- }
- //closing the reader
- reader.close();
- }
- //catching exceptions
- catch (Exception e){
- rows = -1;
- }
- helperArray[0] = columns;
- helperArray[1] = rows;
- // returning the array containing column and row sizes
- return helperArray;
- }
- public static char[][] readASCII(int rows, int columns){
- char[][] helperArray2 = new char[rows][columns];
- try{
- //opening the file
- File file_tree = new File("file_tree.txt");
- Scanner reader = new Scanner(file_tree);
- int c = 0;
- //reading
- while(reader.hasNextLine()){
- // reading one row
- String elements = reader.nextLine();
- for(int i = 0; i < elements.length; i++){
- helperArray2[c][i] = elements.charAt(i);
- }
- c++;
- }
- //closing the reader
- reader.close();
- }
- //catching exceptions
- catch (Exception e){
- rows = -1;
- }
- }
- public static char[][] fillArray(String fileName){
- int rows = readFile(fileName);
- //luentokalvot 6. esimerkki lukemisesta ja tulostamisesta
- int columns = 0;
- return null;
- }
- public static void printBanner(){
- /* a method for printing the opening banner
- * i.e. program's name
- */
- System.out.println("-----------------------");
- System.out.println("| A S C I I A r t 1 7 |");
- System.out.println("-----------------------");
- }
- public static void printArray(char[][] gatheredASCIIpicture){
- if(array != null){
- //amount of rows and columns
- int totalRows = gatheredASCIIpicture.length;
- int totalCol = gatheredASCIIpicture[0].length;
- //printing rows
- for (int row = 0; row < totalRows; row ++){
- //printing row
- for (int column = 0; column < totalCol; column++){
- System.out.print(gatheredASCIIpicture[row][column]);
- }
- //new line
- System.out.println();
- }
- }
- }
- public static void main (String[] args){
- if(args.length == 1){
- printBanner();
- int[] arraySizeValues = readFile(fileName);
- int rows = arraySizeValues[1];
- int columns = arraySizeValues[0];
- char[][] gatheredASCIIpicture = readASCII(rows, columns);
- char[][] chars = fillArray(args[0]);
- char[] charArray = new char[]{'#', '@', '&', '$', '%', 'x', '*', 'o', '|', '!', ';',
- ':', '\'', ',', '.', ' '};
- System.out.println("Please, enter a command:");
- if(args[0] == "print"){
- printArray(gatheredASCIIpicture);
- }
- /*
- for(int i = 0; i < args.length; i++){
- int totalColumns;
- if(args[i] == print){
- fillArray(totalRows, columns);
- }
- else{
- if()
- }
- }
- */
- }
- else{
- printBanner();
- System.out.println("Invalid command-line argument!");
- System.out.println("Bye, see you soon.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement