Sie sind auf Seite 1von 9

EJERCICIOD DE APLICACIÓN JAVA

1.

1.1. Persona.java

public class Persona{

private double idPersona;


private String nombre;
private int edad;
private String genero;

public Persona(){}

public Persona(double idPersona,String nombre,int edad){

setIdPersona(idPersona);
setNombre(nombre);
setEdad(edad);
}

public Persona(double idPersona,String nombre,int edad, String genero){

setIdPersona(idPersona);
setNombre(nombre);
setEdad(edad);
setGenero(genero);
}

public void setGenero(String valor){

if(valor.equals("F") || valor.equals("M"))
{
this.genero=valor;
}
else
{
System.out.println("el genero debe ser F o M");
}
}

public void setEdad(int valor){

if(valor<55)
{
this.edad=valor;
}
else
{
System.out.println("la edad debe ser menor a 55");
}
}

public void setIdPersona(double valor){


this.idPersona=valor;
}

public void setNombre(String valor){


this.nombre=valor;
}

public double getIdPersona(){


return this.idPersona;
}

public String getNombre(){


return this.nombre;
}

public int getEdad(){


return this.edad;
}

public String getGenero(){


return this.genero;
}

1.2. TestPersona.java

public class TestPersona{

public static void main(String[]arreglo){

Persona p=new Persona();


Persona p1=new Persona(22,"Marcos",54);
Persona p2=new Persona(21,"Lucia",55,"F");

System.out.println(p1.getIdPersona()+" "+p1.getNombre()+"
"+p1.getEdad());
System.out.println(p2.getIdPersona()+" "+p2.getNombre()+"
"+p2.getEdad()+" "+p2.getGenero());
}
}

2.

2.1. Animal.java

public class Animal{

private String raza;


private int edad;

public Animal(){}

public Animal(String raza){


setRaza(raza);
}

public Animal(String raza, int edad){

setRaza(raza);
setEdad(edad);
}

public void setRaza(String value){


this.raza=value;
}

public void setEdad(int value){


this.edad=value;
}

public String getRaza(){


return this.raza;
}

public int getEdad(){


return this.edad;
}
}

2.2. TestAnimal.java

public class TestAnimal{


public static void main(String []animal){

Animal A1=new Animal();


Animal A2=new Animal("LABRADOR");
Animal A3=new Animal("PINCHER",15);
System.out.println(A2.getRaza());
System.out.println(A3.getRaza()+" "+A3.getEdad());
}

3. .
3.1. Empleado.java

public class Empleado{

private String nombre;


private String cargo;
private int sueldo;

public Empleado(){}

public Empleado(String nombre){


setNombre(nombre);
}

public Empleado(String nombre, String cargo, int sueldo){


setNombre(nombre);
setCargo(cargo);
setSueldo(sueldo);
}

public void setNombre(String value){


this.nombre=value;
}

public void setCargo(String value){

if (value.equals("Planta") || value.equals("Provisional"))
{
this.cargo=value;
}
else
{
System.out.println("El empleado debe ser de planta o
provisional");
}
}

public void setSueldo(int value){

if (value>=550000)
{
this.sueldo=value;
}
else
{
System.out.println ("El empleado es asalariado");
}
}

public String getNombre(){


return this.nombre;
}

public String getCargo(){


return this.cargo;
}

public int getSueldo(){


return this.sueldo;
}

3.2. TestEmpleado.java

public class TestEmpleado{

public static void main(String[]arg){

Empleado e1=new Empleado();


Empleado e2=new Empleado("Martha");
Empleado e3=new Empleado("Julian","Servicios",600000);

System.out.println(e2.getNombre());
System.out.println(e3.getNombre()+" "+e3.getCargo()+"
"+e3.getSueldo());
}
}
4. .
4.1. X.java

public class X{
private int idX;
private int ab;
private int cx;

public X (){}

public X (int idx, int ab){


setIdX(idX);
setAb(ab);
}

public X (int idX, int ab, int cx){


setIdX(idX);
setAb(ab);
setCx(cx);
}

public void setIdX(int value){


this.idX=value;
}

public void setAb(int value){

if((value==0) || (value==1))
{
this.ab=value;
}
else
{
System.out.println("El valor debe ser 1 o 0");
}
}

public void setCx(int value){


this.cx=value;
}

public int getIdX(){


return this.idX;
}

public int getAb(){


return this.ab;
}

public int getCx(){


return this.cx;
}
}

4.2. TestX.java

public class TestX{

public static void main (String[]arg){

X x1=new X();
X x2=new X(3,1);
X x3=new X(2,3,1);

System.out.println(x2.getIdX()+""+x2.getAb());
System.out.println(x3.getIdX()+""+x3.getAb()+""+x3.getCx());
}
}

5. .

5.1. Docente.java

public class Docente {

private String codigo;


private String nombre;
private int edad;
private String materia;

public Docente(String nombre){


setNombre(nombre);
}

public Docente(String nombre,int edad,String materia){


setNombre(nombre);
setEdad(edad);
setMateria(materia);
}

public void setCodigo(String value){


this.codigo=value;
}

public void setNombre(String value){


this.nombre=value;
}

public void setEdad(int value){


this.edad=value;
}

public void setMateria(String value){


this.materia=value;
}

public String getCodigo(){


return this.codigo;
}

public String getNombre(){


return this.nombre;
}

public int getEdad(){


return this.edad;
}

public String getMateria(){


return this.materia;
}

5.2. TestDocente.java

public class TestDocente{

public static void main(String[]arg){

Docente D1=new Docente("Mary");


Docente D2=new Docente("Tatiana",35,"Matematicas");

System.out.println(D1.getNombre());
System.out.println(D2.getNombre()+" "+D2.getEdad()+"
"+D2.getMateria());
}
}

Das könnte Ihnen auch gefallen