Documente Academic
Documente Profesional
Documente Cultură
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_;
}
/*
* 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();