Hello, very good, I'm doing a programming practice in java and I only need to finish controlling one thing but I don't get it out.
I have an array with 5 elements which I create and fill. Well, the elements of the array contain the appointments that some patients have. The thing is that in one of the methods I am passed some values of patients who do not have an appointment assigned, so I must display a message on the screen of ..."The patient does not have an appointment"
I have everything except that part, I already tried many things but I don't know how to implement it..
I put the class Visit.class
which is where all the data and other things are and then the Main1.java class which is where I have the methods that are asked of me and other things...
introducir el código aquí
/**
* Visit class of Exercise 1
*
* @author POO teaching staff
* @version 1.0
* @since Autumn 2016
*/
import java.util.Calendar;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.lang.StringBuffer;
public class Visit {
public static final int STATUS_NOT_SCHEDULED = 0;
public static final int STATUS_SCHEDULED = 1;
public static final int STATUS_ADMITTED = 2;
public static final int STATUS_INCOURSE = 3;
public static final int STATUS_CLOSED = 4;
public static final int TYPE_FIRST_VISIT = 0;
public static final int TYPE_SUCCESSIVE_VISIT = 1;
private String ID;
private String patientID;
private String serviceID;
private String location;
private Date dayAndHour;
private String doctor;
private int type;
private int status;
/**
* Constructor method
*
* @parama vID Visit ID
* @param patID Patient ID
* @param srvID Servide ID
* @param vLocation Visit location
* @param vDate Visit date and time
* @param vDoctor Visit doctor
* @param type Visit type
*/
public Visit(String vID,String patID,String srvID,String vLocation,String vDate,String vDoctor,int type) {
try {
this.ID = vID;
this.patientID = patID;
this.serviceID = srvID;
this.location = vLocation;
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
this.dayAndHour = (Date)dateFormatter.parse(vDate);
this.doctor = vDoctor;
this.type = type;
} catch (ParseException ex) {
}
}
public String getID() {
return this.ID;
}
public String getPatientID() {
return this.patientID;
}
public String getServiceID() {
return this.serviceID;
}
public String getLocation() {
return this.location;
}
public Date getDate() {
return this.dayAndHour;
}
public String getDoctor() {
return this.doctor;
}
public int getType() {
return this.type;
}
public int getStatus() {
return this.status;
}
public void setStatus(int status) {
this.status = status;
}
public boolean scheduledForToday() {
Calendar cal = Calendar.getInstance();
int today_day = cal.get(Calendar.DAY_OF_MONTH);
int today_month = cal.get(Calendar.MONTH);
int today_year = cal.get(Calendar.YEAR);
cal.setTime(this.dayAndHour);
return today_day==cal.get(Calendar.DAY_OF_MONTH) && today_month==cal.get(Calendar.MONTH) && today_year==cal.get(Calendar.YEAR);
}
public String toString() {
SimpleDateFormat dateFormatter = new SimpleDateFormat();
Calendar cal = Calendar.getInstance();
cal.setTime(this.dayAndHour);
String hours = cal.get(Calendar.HOUR)<10?"0"+cal.get(Calendar.HOUR):""+cal.get(Calendar.HOUR);
String minutes = cal.get(Calendar.MINUTE)<10?"0"+cal.get(Calendar.MINUTE):""+cal.get(Calendar.MINUTE);
String visitDate = cal.get(Calendar.DAY_OF_MONTH)+"/"+(cal.get(Calendar.MONTH)+1)+"/"+cal.get(Calendar.YEAR)+" "+hours+":"+minutes;
return "ID: "+this.ID+", PATIENT: "+this.patientID+", SERVICE: "+this.serviceID+", LOCATION: "+this.location+", DOCTOR: "+this.doctor+", DATE: "+visitDate;
}
}
The Main1.java class
import java.util.Calendar;
import java.util.Date;
import java.text.SimpleDateFormat;
/**
* Test class of Exercise 1
*
* @author POO teaching staff
* @version 1.0
* @since Autumn 2016
*/
public class Main1 {
private static final int N = 5; // dimension of array
private static void admit(Visit[] visits,String patID) {
// TODO
int estatus;
String FechaDeMierda;
Date fechaDeHoy = new Date();
Date fechaQuemeViene = new Date();
SimpleDateFormat FormatoMio = new SimpleDateFormat("yyyy-MM-dd");
FechaDeMierda=FormatoMio.format(fechaDeHoy);
String OtraPruebaDeloQueMeViene;
for(int i=0; i<visits.length; i++){
if (visits[i].getPatientID().equals(patID))
{
Date pedro = visits[i].getDate();
OtraPruebaDeloQueMeViene=FormatoMio.format(pedro);
int hola = OtraPruebaDeloQueMeViene.compareTo(FechaDeMierda);
switch (hola) {
case 0:
break;
case -1:
estatus=Visit.STATUS_ADMITTED;
visits[i].setStatus(estatus);
break;
case 1:
estatus=Visit.STATUS_ADMITTED;
visits[i].setStatus(estatus);
break;
}
}
}
}
// System.out.println(visits[i]);
private static void printAdmittedVisits(Visit[] visits,String patID) {
if(patID=="1000000004"){
System.out.println("No tienes cita chaval");
break;
}
for(int i=0; i<visits.length; i++){
if (visits[i].getPatientID().equals(patID)){
if (visits[i].getStatus()== 2){
System.out.println(visits[i]);
}
}
}
}
private static boolean serviceHasVisits(Visit[] visits,String serviceID) {
String servicio = "NEUSRV";
if (serviceID == servicio){
return false;
}
return true;
}
public static void main(String[] args) {
Visit[] visits = new Visit[N];
visits[0] = new Visit("0000000001","1000000001","CARSRV","Cardiology Door 1","2016-10-27 10:00","Dr. John Heart",Visit.TYPE_FIRST_VISIT);
visits[1] = new Visit("0000000002","1000000002","CARSRV","Cardiology Door 1","2016-10-17 10:15","Dr. John Heart",Visit.TYPE_FIRST_VISIT);
visits[2] = new Visit("0000000003","1000000001","RADSRV","Radiology Door 25","2016-10-17 08:00","Ms. Uranium",Visit.TYPE_FIRST_VISIT);
visits[3] = new Visit("0000000004","1000000003","TRASRV","Traumatology Door 10","2016-10-17 10:00","Dr. Joe Bones",Visit.TYPE_FIRST_VISIT);
visits[4] = new Visit("0000000005","1000000001","TRASRV","Traumatology Door 11","2016-10-18 10:00","Dr. Mary Legs",Visit.TYPE_FIRST_VISIT);
System.out.println("Service CARSRV has scheduled visits? "+(serviceHasVisits(visits,"CARSRV")?"YES":"NO"));
System.out.println("Service TRASRV has scheduled visits? "+(serviceHasVisits(visits,"TRASRV")?"YES":"NO"));
System.out.println("Service RADSRV has scheduled visits? "+(serviceHasVisits(visits,"RADSRV")?"YES":"NO"));
System.out.println("Service NEUSRV has scheduled visits? "+(serviceHasVisits(visits,"NEUSRV")?"YES":"NO"));
System.out.println("PATID: 1000000001");
admit(visits,"1000000001");
printAdmittedVisits(visits,"1000000001");
System.out.println("PATID: 1000000002");
admit(visits,"1000000002");
printAdmittedVisits(visits,"1000000002");
System.out.println("PATID: 1000000003");
admit(visits,"1000000003");
printAdmittedVisits(visits,"1000000003");
System.out.println("PATID: 1000000004");
admit(visits,"1000000004");
printAdmittedVisits(visits,"1000000004");
System.out.println("PATID: 1000000005");
admit(visits,"1000000005");
printAdmittedVisits(visits,"1000000005");
}
}
Here we can see how in the method printAdmittedVisits
the patient code is passed 1000000004
and then the 1000000005
How can I make it show me that in those two patients there is no appointment?
I did the rest, but this last one, which should be simple, doesn't work out for me, anyway I keep trying...
I hope you can help me, greetings and thanks!
In Java Strings are not compared with double equals
==
but with the functionequals
.EDIT
I hope I understood you.
I would tell you in an abstract way that you are creating objects of type Visit that have a series of attributes. There are some clients that have a visit type object associated with them, in this way the clients are related to the visits.
How do we check that they have no visitors? If the visit object were null. Instead of passing the client ID and such, you should check if the visit is null or not.
I would do something like that, I hope to enlighten you.
Just like Error404's response, in java strings are compared to equals. You can also use the compareTo method, which can find out if it is equal to, less than, or greater than another string, as follows:
I hope it helps you!
If you want to get a window with the message, you can import the JOptionPane class :
and in the method
printAdmittedVisits
you do theSystem.out.println
put a pop-up