Javakurs/Übungsaufgaben/DDDText/Musterloesung
< Javakurs | Übungsaufgaben | DDDText
/** * This little java programm prints a given text in ascii-Art. * Start the programm with: * # java DDDText <Place you text here> * * e.g. * # java DDDText Java * * @author tkroenert * * * Warning: This programm is written on a little higher * programming level as you are on the first day learing * java. So you programm can be much simpler. * */ public class DDDText { public static void main(String[] arguments /*[0] is the message we want to print out */) { /* * This is for the case you do not give the programm a parameter */ if (arguments.length == 0) { System.out.println("Start the programm with:"); System.out.println("\t# java DDDText <Place you text here>\n"); System.out.println("e.g."); System.out.println("\t# java DDDText Java"); System.out.println(""); } /* * Here begins the formatted output of the 3D-Text. * * Test on your own how it works. Trial & error is * the best way. */ //Userfriendly case-ignoring trick arguments[0] = arguments[0].toLowerCase(); //take a character... for (int i = 0; i < arguments[0].length(); i++) { char nextChar = arguments[0].charAt(i); //...and have a look at it switch(nextChar) { case 'a': System.out.println(" ___ "); System.out.println(" / /\\ "); System.out.println(" / /::\\ "); System.out.println(" / /:/\\:\\ "); System.out.println(" / /:/~/::\\ "); System.out.println(" /__/:/ /:/\\:\\ "); System.out.println(" \\ \\:\\/:/__\\/"); System.out.println(" \\ \\::/ "); System.out.println(" \\ \\:\\ "); System.out.println(" \\ \\:\\ "); System.out.println(" \\__\\/ "); break; /* * case 'b': ... * case 'c': ... * case 'd': ... * etc. */ case 'j': System.out.println(" ___ "); System.out.println(" / /\\ "); System.out.println(" / /:/ "); System.out.println(" /__/::\\ "); System.out.println(" \\__\\/\\:\\ "); System.out.println(" \\ \\:\\ "); System.out.println(" \\__\\:\\ "); System.out.println(" / /:/ "); System.out.println(" /__/:/ "); System.out.println(" \\__\\/ "); break; case 'v': System.out.println(" ___ "); System.out.println(" /__/\\ "); System.out.println(" \\ \\:\\ "); System.out.println(" \\ \\:\\ "); System.out.println(" _ _ \\__\\:\\ "); System.out.println(" /__/\\ | |:| "); System.out.println(" \\ \\:\\| |:|"); System.out.println(" \\ \\:\\__|:| "); System.out.println(" \\__\\::::/ "); System.out.println(" ~~~~ "); break; default: System.out.println(nextChar); break; //this would never happen } //some ascii-cosmetics System.out.println(""); } } }