Sunteți pe pagina 1din 2

UNIVERSIDAD UNION BOLIVARIANA

Nombre: Valentin Yujra Suri Carrera: Ing. Sistemas Semestre: Tercero


PRACTICA 4 TALLER DE PROGRAMACION II

1. Teniendo la clase Persona con los atributos “nombre, apellido y edad”, realizar un programa para hacer uso de la clase
mencionada, los datos necesarios sean introducidos por teclado, y los mismos deberán ser asignados a los atributos de la clase
mediante un solo constructor, donde haciendo uso de los métodos de la clase nos permita realizar la verificación si la persona es
mayor o menor de edad, teniendo que imprimir que imprimir en pantalla los siguientes mensajes correspondientes:
Si la edad es mayor que 18 debe imprimir: ¨La persona xxxxx yyyyyyy es mayor de edad¨
Caso contrario deberá imprimir: ¨La persona xxxxx yyyyyyy es menor de edad.

Sol:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package persona_;

/**
*
* @author valentin.yujra
*/
public class LeerPersona {
String nombre;
String apellido;
int edad;
public LeerPersona(String nombre_, String apellido_, int edad_)
{
nombre=nombre_;
apellido=apellido_;
edad=edad_;
}

public void mostrar()


{
System.out.println("Nombre :"+nombre+"\n Apellido: "+apellido+"\n Edad: "+edad);
}

public void mayor_edad()


{
if(edad>=18)
{
System.out.println("La persona de Nombre :"+nombre+"\n Apellido: "+apellido+"\n es
Mayor de edad ");
}
else
{
System.out.println("La persona de Nombre :"+nombre+"\n Apellido: "+apellido+"\n es
Menor de edad ");
}
}
}

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package persona_;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
*
* @author valentin.yujra
*/
public class Persona_ {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
String nombre;
String apellido;
int edad;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
System.out.println("Clase PERSONA");
System.out.print("Intriduzca Nombre: ");
nombre = br.readLine();
System.out.print("Intriduzca Apellido: ");
apellido = br.readLine();
System.out.print("Intriduzca Edad: ");
edad = sc.nextInt();
LeerPersona p1 = new LeerPersona(nombre,apellido,edad);
p1.mostrar();
p1.mayor_edad();

S-ar putea să vă placă și