0

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);
}
abidm98
  • 9
  • 2
  • show us the code you've written so far to try to answer this question – RAZ_Muh_Taz May 02 '18 at 23:00
  • Visualize a 2D array like an excel spreadsheet. the first dimension could be the rows. you'll need 28 rows,one for each day. then you'll need 3 columns to track morning, afternoon and evening for each day. Add all the fares for that day/time, and store them in the proper cell. Then you could have a seperate 1d string array with 28 elements to store the location. – Chris H May 02 '18 at 23:18
  • I don’t understand how my arrays are being stored as part of the record. I know how to code through trial however I don’t understand the logic behind the arrays and record. @chris H I understand the concept of 2D arrays now thank you :) – abidm98 May 02 '18 at 23:29

0 Answers0