I'm struggling to understand 2D arrays and my exam is in 2 days, I've tried myself but I just can't get my head around it so this is basically my last resort and I really need help understanding them.
An example question which would require you to implement 2D arrays:
"Write a Java program for a taxi driver to keep track of the takings from working from different stations at different times of the day over a period of 4 weeks (28 days). The driver wishes to use the information to make better decisions about where to work in the future. Each day the driver chooses a station to work from. They choose from Kings Cross, Liverpool Street, Paddington and Euston and work from that station all day. They work up to three periods each day: morning, afternoon and evening. Your program should allow the cab driver to input the place they will work that day, and for each period whether they are working that period or not. It should then repeatedly allow them to enter the fare charged, giving them an option to quit for that period. At the end of each day, it should summarise that day’s takings for each period. At the end of the four weeks, the program should list the summary for every day."
What I need help with: How would you declare this 2D array? What would the outputs look like? (This is what I am struggling with as I cannot visualize it)
A further question for the really smart Java programmers: How to abstract it?
Please keep in mind I'm a first-year student, although any help would be good at this point I would much appreciate it if you could simplify it or make it in Procedural Programming style so I could understand and learn.
Thank you.
The 2D Array, in this case, is PeriodRecord, I don't want help solving it, I just want to understand how they work in which I can then go give this another try, but as of now, I am stuck. I want to understand.
public static void main (String [] param)
{
String [] stations = {"Kings Cross", "Liverpool Street",
"Paddington","Euston"};
String [] periods = {"Morning", "Afternoon", "Evening"};
PeriodRecord [] [] periodrecords = createPeriodRecords(MAX_DAYS,
MAX_PERIODS, periods);
for(int day = 0; day < MAX_DAYS; day++)
{
workDay(periodrecords, day, periods, stations);
summariseDay(periodrecords, day);
}
printFullSummary(periodrecords);
}