Clase Mascota:
public class Mascota {
private String nombre;
private String especie;
private Dueño dueño;
public Mascota(String nombre, String especie, Dueño dueño) {
setNombre(nombre);
setEspecie(especie);
setDueño(dueño);
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getEspecie() {
return especie;
}
public void setEspecie(String especie) {
this.especie = especie;
}
public Dueño getDueño() {
return dueño;
}
public void setDueño(Dueño dueño) {
this.dueño = dueño;
}
}
Clase Consulta:
public class Consulta {
private String fecha;
private String motivo;
private Mascota mascota;
public Consulta(String fecha, String motivo, Mascota mascota) {
setFecha(fecha);
setMotivo(motivo);
setMascota(mascota);
}
public String getFecha() {
return fecha;
}
public void setFecha(String fecha) {
this.fecha = fecha;
}
public String getMotivo() {
return motivo;
}
public void setMotivo(String motivo) {
this.motivo = motivo;
}
public Mascota getMascota() {
return mascota;
}
public void setMascota(Mascota mascota) {
this.mascota = mascota;
}
Clase Dueño:
public class Dueño {
private String nombre;
private double nroContacto;
private String direccion;
public String getNombre() {
return nombre;
}
public Dueño(String nombre, double nroContacto, String direccion) {
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public double getNroContacto() {
return nroContacto;
}
public void setNroContacto(double nroContacto) {
this.nroContacto = nroContacto;
}
public String getDireccion() {
return direccion;
}
public void setDireccion(String direccion) {
this.direccion = direccion;
}
Principal:
import java.util.Scanner;
public class Principal {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
Dueño jose;
Mascota oliver;
Consulta consulta;
int opcion;
do {
System.out.println("Menú" + "\n1- Registrar nuevo Dueño" + "\n2-
Registrar nueva Mascota" + "\n3- Registrar nueva Consulta" + "\n4- Salir");
System.out.println("Ingrese opción");
opcion = s.nextInt();
s.nextLine();
if (opcion == 1) {
System.out.println("Ingrese nombre: ");
String nombre = s.nextLine();
System.out.println("Ingrese numero de contacto: ");
double nroContacto = s.nextDouble();
s.nextLine();
System.out.println("Ingrese direccion:");
String direccion = s.nextLine();
jose = new Dueño(nombre, nroContacto, direccion);
} else if (opcion == 2) {
System.out.println("Ingrese nombre:");
String nombre = s.nextLine();
System.out.println("Ingrese especie:");
String especie = s.nextLine();
oliver = new Mascota(nombre, especie, jose);
} else if (opcion == 3) {
System.out.println("Ingrese fecha de la consulta:");
String fecha = s.nextLine();
System.out.println("Ingrese motivo: ");
String motivo = s.nextLine();
consulta = new Consulta(fecha, motivo, oliver);
} else if (opcion != 4) {
System.out.println("Error.");
}
} while (opcion != 4);
if(opcion == 4) {
System.out.println("Ha salido del programa.");
}
}
}
Main:
import java.util.Scanner;
public class Principal {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
Dueño jose = null;
int opcion;
do {
System.out.println("Menú" + "\n1- Registrar nuevo Dueño" + "\n2-
Registrar nueva Mascota" + "\n3- Registrar nueva Consulta" + "\n4- Salir");
System.out.println("Ingrese opción");
opcion = s.nextInt();
s.nextLine(); // Consumir la nueva línea
if (opcion == 1) {
System.out.println("Ingrese nombre: ");
String nombre = s.nextLine();
System.out.println("Ingrese numero de contacto: ");
double nroContacto = s.nextDouble();
s.nextLine(); // Consumir la nueva línea
System.out.println("Ingrese direccion:");
String direccion = s.nextLine();
jose = new Dueño(nombre, nroContacto, direccion);
} else if (opcion == 2) {
System.out.println("Ingrese nombre:");
String nombre = s.nextLine();
System.out.println("Ingrese especie:");
String especie = s.nextLine();
} else if (opcion == 3) {
System.out.println("Ingrese fecha de la consulta:");
String consulta = s.nextLine();
System.out.println("Ingrese motivo: ");
String motivo = s.nextLine();
} else if (opcion != 4) {
System.out.println("Error.");
}
} while (opcion != 4);
if(opcion == 4) {
System.out.println("Ha salido del programa.");
}
}
}