Using Arrays
UsingArrays.java☑ Add the class Worker to your project. Add to Worker an instance variable daysWorking which is an array of booleans. We generally don't provide accessors and mutators for array instance variables.
☑ In the default constructor, set up the array to be 7 long. The elements of this array represent what days of the week the worker works on. We'll assume the week starts on Monday, so the last two elements in the array will represent the weekend. By default, the Worker is working no days.
☑ To Worker, add a method, workWeekday(), which sets all the elements in the array for weekdays to true, and the ones for weekend to false. For full credit, use a loop for the weekdays at least. This method should work no matter what days were or weren't true previously (i.e. don't assume you start with all days false).
[EC] Also add workWeekend() which does the opposite. (Test this later in main if you do it)
☑ Add a method daysWorked which returns an int. It should go through the array and count how many days the worker is working, then return that number.
☑ In the toString, use daysWorked to generate something like
worker Constance (working 3 days this week).
☑ In your main, create a worker, print them, then have them work week days and print again.
[EC]
Add to Worker a method schedule which takes as parameters an int day and a boolean isWorking. day should be a number from 1 to 7 indicating the day of the week worked, with 1 being Monday, etc. Check that day has a valid value, and if so set the appropriate day in daysWorking to the value of working. (hint: day runs from 1 to 7 but the array runs from . . . )
So myWorker.schedule(3,true) means that myWorker is working on Wednesday, and myWorker.schedule(2,false) means myWorker is not working on Tuesday.
In your main, make a worker and randomly choose three days out of the week and have them work those days (you don't have to worry about the case where the same random number happens to come up twice). Print out the worker.
[EC]
In Worker's toString, add a local array dayLetters which is an array of Strings for the letters representing each day of the week (MTWRFSU). Think of this as a parallel array with daysWorking array of booleans. In the result of the toString also include which days are worked by putting either the letter if they work that day or a dash if they don't, so for someone who is working Monday, Thursday, and Sunday it would look like
worker Constance (working 3 days this week: M--R--U).
(hint: you should never actually have to change dayLetters after you
have set it up; it is just holding the values in the right order)