martes, 9 de noviembre de 2010

dibujar un rectangulo java (netbeans)

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author alejandra
 */
import java.io.*;
public class Rectangulo {
    int l1;
    int l2;

    public void setL1(int l1) {
        this.l1 = l1;
    }

    public void setL2(int l2) {
        this.l2 = l2;
    }

    public int getL1() {
        return l1;
    }

    public int getL2() {
        return l2;
    }

    public void dibujar()throws IOException{
        BufferedReader s1=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("introdusca caracter con el que se imprimira la figura:");
        String  Z=s1.readLine();
        System.out.println("introdusca un numero: ");
        l1=Integer.parseInt(s1.readLine());
        System.out.println("introdusca un segundo numero: ");
        l2=Integer.parseInt(s1.readLine());
       System.out.println("\n");
            for(int x=0;x<l1;x++) {
                for(int y=0;y<l2;y++){
                 System.out.print(Z);}
                 System.out.println();
            }


}
       public void dibujar(int l1 , int l2)throws IOException{
           BufferedReader s0=new BufferedReader(new InputStreamReader(System.in));
            System.out.println("introdusca un caracter para empezar a dibujar: ");
            String Z=s0.readLine();
            System.out.println("\n");
            for(int x=0;x<l1;x++) {
                for(int y=0;y<l2;y++){
                 System.out.print(Z);}
                 System.out.println();
            }
}
    public int area()throws IOException{
        return l1*l2;
      
    }
}
-----------------------------------------------------------------------------------------------------------

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author alejandra
 */
import java.io.*;
public class Mdibujar {
     public static void main(String[]arg)throws IOException{
          BufferedReader s=new BufferedReader(new InputStreamReader(System.in));
          Rectangulo d=new Rectangulo();
         int op;
          do{
              System.out.println("MENU\n");
              System.out.println("1.Definir tamaño\n");
              System.out.println("2.Tamaño estandar\n");
              System.out.println("3.Calculra area\n");
              System.out.println("4.salir");
              System.out.println("elegir su opcion");
              op=Integer.parseInt(s.readLine());
              switch(op){
                  case 1 :
                   d.dibujar();
                   break;
                  case 2:
                    d.dibujar( 3, 3);
                      break;
                  case 3 :
                      System.out.println("el area es: "+d.area());
                      break;
                  case 4 :
                      break;
              }

  }while(op!=4);

}
}


1 comentario:

  1. hola gracias por el aporte me tiraba un error y cambie la linea
    public static void dibujar(int l1 , int l2)

    le agregue el void y me corrio perfecto gracias :)

    ResponderEliminar