Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AsciiShop3 {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner input = new Scanner(System.in);
- AsciiImage a = new AsciiImage();
- boolean check = true;
- int i=-1;
- int lines=0;
- if(input.next().equals("read")){
- lines=input.nextInt();
- }else{
- check = false;
- }
- while(input.hasNext() && check==true){
- if(i==-1){
- String bugfix = input.nextLine(); //irgendwie wird durch die kombination aus der read abfrage und der while bedingung ein leerer input erzeugt welcher hiermit abgefangen wird
- i++;
- }else{
- check=a.addLine(input.nextLine());
- i++;
- if(i==lines || check==false){
- break;
- }
- }
- }
- if(check==false){
- System.out.print("INPUT MISMATCH");
- }else{
- /* System.out.println("OUPUT\n"+a.toString());
- a.toString(); */
- System.out.println("Tostring\n"+a.toString());
- a.transpose();
- System.out.println("Transpose\n"+a.toString());
- /* a.flipV();
- System.out.println("Flip\n"+a.toString());
- System.out.println(a); */
- }
- }
- }
- second file
- public class AsciiImage {
- private String s;
- private int w; //width
- private int h; //height
- private String output;
- public AsciiImage(){
- s ="";
- w=0;
- h=0;
- }
- public boolean addLine(String line){
- boolean b=false;
- if(line.length()!=0){ //bug: kein abbruch trotz leerer eingabe
- if(h==0){
- w=line.length();
- // System.out.println("passt");
- }
- b=true;
- // System.out.println("passt2");
- if(line.length() == w ){
- // s+=line+"\n";
- s+=line;
- h++;
- //System.out.println("w= "+w);
- }else{
- b = false;
- }
- }else{
- System.out.println("fehler2");
- }
- //System.out.println(w+"w<-->h"+h);
- return b;
- }
- public int getWidth(){
- return w;
- }
- public int getHeight(){
- return h;
- }
- public String toString(){
- output=s;
- //output=new StringBuffer(s).deleteCharAt(w*h).toString();
- //System.out.println("tostringfunktion - s: "+s+ "w = "+w);
- for(int i=1;i<=h;i++){
- output= new StringBuffer(output).insert(w*i+i-1, "\n").toString();
- }
- return output;
- }
- /* public int getUniqueChars(){
- }
- // gibt zurück wieviele unterschiedliche Zeichen im Bild vorkommen. So enthält das einzeilige Bild abaaabac 3 unterschiedliche Zeichen. */
- public void flipV(){
- int j=0;
- String temp="";
- for(int i=h*w;i>0;i--){
- j++;
- temp=new StringBuffer(s).insert(j, s.charAt(i)).toString();
- }
- s=temp;
- }
- // dreht das Bild vertikal um, sprich es vertauscht die Zeilen des Bildes (die erste mit der letzten, die zweite mit der vorletzten, usw.)
- public void transpose(){
- String temp=s;
- int tmp=0;
- for(int i=0;i<w*h;i++){
- //for(int j=1;j<w*h;j++){
- // if(w*i+i!=w*h){
- temp=new StringBuffer(s).insert(i, s.charAt((w*i+i)%(w*h))).toString();
- /* }else{
- temp=new StringBuffer(s).insert(i, s.charAt((w*i+i)%(w*h))).toString();
- } */
- //BUG: i+w*i%w*h irgendwas passt nicht
- // }
- }
- tmp=h;
- h=w;
- w=tmp;
- System.out.println(w+" "+h);
- //s=temp;
- }
- // vertauscht Zeilen und Spalten des Bildes, sprich aus der ersten Zeile im Bild wird die erste Spalte usw. Dabei ändern sich Höhe und Breite des Bildes (vgl. Matrix_(Mathematik)). Diese Methode muss sicherstellen, dass abhängige Eigenschaften des Bildes (Höhe, Breite) aktualisiert werden.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement