Doubt with java about content Array

6

Hello very good I'm doing a Java programming practice and I just need to finish controlling one thing but I do not take it out.

I have an array with 5 elements which I create and fill them with. Well, the elements of the array contain the quotes that some patients have. The fact is that in one of the methods I miss some of the values of patients who do not have appointments. then I have to get a message on the screen ... "The patient has no appointment"

I have everything I miss except that part, I already try many things but I do not know how to implement it ..

I put the class Visit.class which is where all the data is and others and then the Main1.java class, which is where I have the methods that I am asked for 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 you pass the patient code 1000000004 and then the 1000000005 How can I do to show me that there is no appointment in these two patients?

The rest I did everything, but this last thing that should be simple does not work out for me, anyway I'm still trying ...

Hopefully you can help, greetings and thanks!

    
asked by Roman345 27.10.2016 в 14:02
source

4 answers

3

In Java the Strings do not compare with double equal == if not with the function equals .

if(patID.equals("1000000004") || patID.equals("1000000005")){
      System.out.println("No tienes cita chaval");
      break;
}
    
answered by 27.10.2016 / 14:07
source
2

EDITO

I hope I have understood you.

I would say to you in an abstract way that you are creating Visits that have a series of attributes. There are some clients that have an object associated with a visit type, so the clients are related to the visits.

How do we verify that they do not have visitors? If the object visited was null. Instead of passing the customer ID and such, you should check if the visit is null or not.

private static void printAdmittedVisits(Visit[] visits) {
  for(int i=0; i<visits.lenght; i++){
         if(visits[i] == null)
            System.out.println("No tienes cita cliente "+visits.IDCliente);
            break;
  }

I would do something like that, I hope to enlighten you.

    
answered by 27.10.2016 в 14:07
2

Just like the answer of Error404, in java the strings are compared with equals. You can also use the compareTo method, which you can find out if it is the same, smaller or bigger than another string, in the following way:

    if (cadena1.compareTo(cadena2) == 0)
        System.out.println("cadena1 y cadena2 son iguales");
    else
    if (cadena1.compareTo(cadena2) < 0)
        System.out.println ("cadena1 va antes que cadena2");
    else
    if (cadena1.compareTo(cadena2) > 0)
        System.out.println("cadena2 va después que cadena1");

I hope it serves you!

    
answered by 27.10.2016 в 14:59
1

If you want a window with the message, you can import the class JOptionPane :

import javax.swing.JOptionPane

and in the printAdmittedVisits method that you make the System.out.println put a pop-up

JOptionPane.showMessageDialog(null, "No tiene cita", "Aviso", JOptionPane.INFORMATION_MESSAGE);
    
answered by 27.10.2016 в 14:08