Você está na página 1de 13

package laboratorio08;

import java.util.InputMismatchException;

import java.util.Scanner;

public class Laboratorio08 {

public static void main(String[] args) {

float Q = 0,W = 0,E = 0,R = 0;

Scanner sn = new Scanner(System.in);

sn.useDelimiter("\n");

boolean salir = false;

int opcion; //Guardaremos la opcion del usuario

System.out.println("Tenemos objetos aleateorio");

Rectangulo A=new Rectangulo("verde",1,1,"Rectangulo",2,5);

Circulo B=new Circulo("azul",1,2,"Circulo",1,5);

elipse C=new elipse("verde",1,2,"elipse",2,3);

cuadrado D=new cuadrado("rojo",1,2,"cuadrado",4,5);

while (!salir) {

System.out.println("1. IMPRIMIR");

System.out.println("2. AREA");

System.out.println("3. MOVER FORMA");


System.out.println("4. CAMBIAR COLOR");

System.out.println("5. CAMBIO DE DATOS");

System.out.println("6. QUE FIGURA TIENE MAS AREA");

System.out.println("7. Salir");

try {

System.out.println("que metodo quiere utilizar");

opcion = sn.nextInt();

switch (opcion) {

case 1:System.out.println("rectangulo");

A.IMPRIMIR();

System.out.println("circulo");

B.IMPRIMIR();

System.out.println("elipse");

C.IMPRIMIR();

System.out.println("cuadrado");

D.IMPRIMIR();

break;

case 2:

System.out.println("rectangulo");

Q= A.AREA();

System.out.println("circulo");

W=B.AREA();

System.out.println("elipse");

E=C.AREA();

System.out.println("cuadrado");

R=D.AREA();

break;

case 3:
System.out.println("rectangulo");

A.moverforma();

System.out.println("circulo");

B.moverforma();

System.out.println("elipse");

C.moverforma();

System.out.println("cuadrado");

D.moverforma();

break;

case 4:

System.out.println("rectangulo");

A.CAMBIARCOLOR();

System.out.println("circulo");

B.CAMBIARCOLOR();

System.out.println("elipse");

C.CAMBIARCOLOR();

System.out.println("cuadrado");

D.CAMBIARCOLOR();

break;

case 5:

System.out.println("rectangulo");

A.CAMBIARDATOS();

System.out.println("circulo");

B.CAMBIARDATOS();

System.out.println("elipse");

C.CAMBIARDATOS();

System.out.println("cuadrado");

D.CAMBIARDATOS();

break;
case 6:

if (Q>W && Q>E && Q>R)

System.out.println("el mayor es el RECTANGULO");

A.IMPRIMIR();

}else

if(W>Q && W>E && W>R)

System.out.println("el mayor es el CIRCULO");

B.IMPRIMIR();

else

if(E>Q && E>W && E>R)

System.out.println("el mayor es el ELIPSE");

C.IMPRIMIR();

else

System.out.println("el mayor es el CUADRADO");

D.IMPRIMIR();

case 7:

salir = true;

break;

default:
System.out.println("Solo números entre 1 y 8");

} catch (InputMismatchException e) {

System.out.println("Debes insertar un número");

sn.next();

package laboratorio08;

import javax.swing.JOptionPane;

import java.util.Scanner;

/**

* @author Darwin

*/

public class Forma {


protected String color ;

protected int x;

protected int y;

protected String forma;

public Forma(String color, int x, int y, String forma) {

this.color = color;

this.x = x;

this.y = y;

this.forma = forma;

public String getColor() {

return color;

public void setColor(String color) {

this.color = color;

public int getX() {

return x;

public void setX(int x) {

this.x = x;

}
public int getY() {

return y;

public void setY(int y) {

this.y = y;

public String getForma() {

return forma;

public void setForma(String forma) {

this.forma = forma;

public void IMPRIMIR()

System.out.println ("su color es "+this.getColor());

System.out.println("si punto de centro es "+this.x+"y"+this.y);

System.out.println("su forma es de "+this.forma);

public void CAMBIARCOLOR()

Scanner sn = new Scanner(System.in);

sn.useDelimiter("\n");

System.out.println ("su color es "+this.getColor());

System.out.println("a que color desea cambiar?");


this.color=sn.next();

public void moverforma()

Scanner sn = new Scanner(System.in);

sn.useDelimiter("\n");

System.out.println("si punto de centro es "+this.x+"y"+this.y);

System.out.println("a que coordenadas quiere cambiar usted ");

System.out.println("coloce la coordenada X?");

this.x=sn.nextInt();

System.out.println("coloce la coordenada X?");

this.y=sn.nextInt();

package laboratorio08;

import java.util.Scanner;

public class Rectangulo extends Forma {

protected int Ladomenor;

protected int Ladomayor;


public Rectangulo(String color,int x,int y,String forma,int Ladomenor,int Ladomayor)

super(color,x,y,forma);

this.Ladomayor=Ladomayor;

this.Ladomenor=Ladomenor;

this.forma="Rectangulo";

@Override

public void IMPRIMIR()

super.IMPRIMIR();

@Override

public void CAMBIARCOLOR()

super.CAMBIARCOLOR();

public float AREA()

System.out.println("su area es de "+Ladomayor*Ladomenor);

return 0;

public void PERIMETRO()

System.out.println("su perimetro es "+2*Ladomayor*Ladomenor);


}

public void CAMBIARDATOS()

Scanner sn = new Scanner(System.in);

sn.useDelimiter("\n");

System.out.println("ingrese su nuevo lado mayor");

this.Ladomayor=sn.nextInt();

System.out.println("ingrese su nuevo lado menor");

this.Ladomenor=sn.nextInt();

package laboratorio08;

import java.util.Scanner;

public class cuadrado extends Rectangulo{

public cuadrado(String color,int x,int y,String forma,int Ladomenor,int Ladomayor)

super (color,x,y,forma,Ladomenor,Ladomayor);

this.Ladomenor=this.Ladomayor;

this.forma="cuadrado";

@Override

public float AREA()


{

System.out.println("el Area del cuadrado es :"+ Math.pow(this.Ladomayor, 2));

return 0;

@Override

public void IMPRIMIR()

super.IMPRIMIR();

@Override

public void CAMBIARCOLOR()

super.CAMBIARCOLOR();

public void PERIMETRO()

System.out.println("su perimetro es "+4*Ladomayor);

public void CAMBIARDATOS()

Scanner sn = new Scanner(System.in);

sn.useDelimiter("\n");

System.out.println("ingrese uno de los lados");

this.Ladomayor=sn.nextInt();
}

package laboratorio08;

import java.util.Scanner;

public class elipse extends Forma {

protected int Radiomayor;//modificador de acceso.permite el acceso de las clases hijas

protected int Radiomenor;

public elipse(String color,int x,int y,String forma,int Radiomayor,int Radiomenor)

super(color,x,y,forma);

this.Radiomayor=Radiomayor;

this.Radiomenor=Radiomenor;

this.forma="elipse";

public float AREA()

System.out.println("Su area es :"+Radiomayor*Math.PI*Radiomenor);

return 0;

}
@Override

public void IMPRIMIR()

super.IMPRIMIR();

@Override

public void CAMBIARCOLOR()

super.CAMBIARCOLOR();

public void PERIMETRO()

System.out.println("su perimetro es "+2*Math.PI*(Radiomayor+Radiomenor));

public void CAMBIARDATOS()

Scanner sn = new Scanner(System.in);

sn.useDelimiter("\n");

System.out.println("ingrese su nuevo lado mayor");

this.Radiomayor=sn.nextInt();

System.out.println("ingrese su nuevo lado menor");

this.Radiomenor=sn.nextInt();

Você também pode gostar