0

I'm designing a simple covid 19 tracking system. The system creates Visits object that is stored in an ArrayList everytime a Customer(objects in ArrayList) visits a Shop(objects in ArrayList).

The superclass Details.

public class Details {

  private String name;
  private String phoneNumber;
  private Status status;

  // Customer
  public Details(String name, String phoneNumber, Status status) {
    this.name = name;
    this.phoneNumber = phoneNumber;
    this.status = status;
  }

I'm using java.time package to create the datetime along with Visit object like so

public class Visit extends Details {
    
    private String dateTimeFinal;
    private String shopName;
    
    public Visit(String name, String phoneNumber,String shopName, Status status) {
        super(name, phoneNumber, status);
        this.shopName = shopName;
        LocalDateTime dateTime = LocalDateTime.now();
        DateTimeFormatter dateTimeFormatted = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
        dateTimeFinal = dateTime.format(dateTimeFormatted);
    }

My customer class constructor looks like this

public class Customer extends Details {
  
  private String password;

  public Customer (String name, String phoneNumber, String password, Status status){
    super(name, phoneNumber, status);
    this.password = password;
  }

My shop class constructor looks like this

public class Shop extends Details{

  private String managerName;
  
  public Shop(String name, String phoneNumber, Status status, String managerName){
    super(name, phoneNumber, status);
    this.managerName = managerName;
  }

I also have a Status enum in another file that looks like this

public enum Status{
  NORMAL,
  CASE,
  CLOSE    
}

What I'm trying to accomplish now is, if a customer that has been flagged as CASE visits a Shop, all customers that also visit the shop within a 1 hour time range before & after automatically gets flagged as a close contact (CLOSE). I also want know how to create time&date that is not localdatetime.now, because I need to generate visits to test if the flagging algorithm works or not.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • What is the purpose of `Details`? Is this a class you made? Could you provide it if so? – Adrian Russo Jan 10 '21 at 04:13
  • Yes I made the class, I've updated the post. I apologize for the confusion. – mayfly orin Jan 10 '21 at 04:19
  • Don’t store date and time on a `String` in your object. Keep the `LocalDateTime` you have (or a `ZonedDateTime`). A formatted stirng is for users to see, not for keeping data in your program. You can always format the `LocalDateTime` when you need to display the date and time. – Ole V.V. Jan 10 '21 at 07:29
  • For how to test with times that are not now: [How to test date created with LocalDateTime.now()](https://stackoverflow.com/questions/39527752/how-to-test-date-created-with-localdatetime-now). – Ole V.V. Jan 10 '21 at 07:31

1 Answers1

1

Use one of the LocalDateTime.of() methods (found here) to create a specific time.

To keep track of possible flags, one solution would be to keep track of the last risky Visit for a Shop, and each time a new visit is made to that Shop to check if it is recent enough, and if so update the Status of the Visit, Shop, and Customer. Use LocalDateTime.minusHours() to compare the times.

Adrian Russo
  • 546
  • 4
  • 16