samedi 8 mai 2021

Opening Times Statements: Overlapping of times

for school I need to code a program which gives returns me the for different days and times the right statement if a store is open or closed.

There are two variants of TimeTable. The code I need to write but should return the right statement for both different time tables.

We are very beginners so I tried to do it with a lot of if-statements but I lost the overview.

The problem is that, the times overlap in the next day. For example: On Tuesday in variant A the store is open from 22 to 4. So the program should run for Wednesday 0-4 open.

I don't get how to code that..

They handed out templates with methods for us, which we must use for the task. So the methods we can use for this are:

static int getOpeningHour(int day)
Returns the time at the given day when the shop opens.

static int getClosingHour(int day)
Returns the time at the given day when the shop closes.

static String getNameOfDay(int day)
Returns the name of the given day.

static void selectTimeTable(String[] args)
Changes the timeTable to the users selection. Note: The args-Argument should be the one passed to your main-Method.

static int getDayFromInput(String[] args)
Returns the day selected by the user.

static int getHourFromInput(String[] args)
Returns the hour selected by the user.

The first Time Table is this enter image description here

The second Time Table is this enter image description here

And the selection for the test if the store is open is possible with an drop down enter image description here

Important to know is that it is very important that in case of TimeTable A the store is open from 0-4 and on Wednesday evening the store opens at 20 and closes at 2 on Thursday. I don't know how to do this overlapping.

I tried it like thisenter image description here but it does not work.. Maybe you can help me out of this situation. I would be very thankful.

Thanks in advance,

Aucun commentaire:

Enregistrer un commentaire