Archaeology Rocks is a global company that provides groups of people to perform excavations (archaeological digs) in all parts of the world. You are continuing your coding of the DIGS (Data Involving Groups Sent) system that the company uses to manage people sent on field trips.

PLEASE make a new directory in your latcs account for Assignment 3.

In Progress Check 2, you developed a utility class, Identity.java, that allowed the company to extract or update information on a person’s identity card. You will need a copy of that class in the directory where you develop Assignment 3 (or you can copy a sample solution with the following command when in your new directory):

cp /home/1st/csilib/cse1oof/Identity.java .

More classes needed by the DIGS system are developed in the following tasks.

Task 1 – A Person Class

Details kept on each person available to send on field trips include a name and an identity code (formatted as discussed in Progress Check 2). A boolean onDig indicates whether the person is currently on a field trip and a fieldDays array stores how many days the person has been on field trips in Europe, Asia and The Americas in the first, second and third elements of the array respectively.

Begin coding your Person class, providing attributes as indicated in the class diagram. Then provide the following functionality for the Person class:

  • A constructor that takes a string name and string code (assumed valid) as arguments. Initialise onDig to false and set the elements of the fieldDays array to 0.
  • Add another constructor that takes a string name and string code as arguments as well as a boolean onDig and three integer arguments to initialise the Europe, Asia and The Americas elements (indexes 0, 1 and 2 respectively) of the fieldDays array.
  • Provide accessor (get) methods for all four attributes. (Consider privacy leaks with getFieldDays().)
  • The ability to update a name is NOT required and any changes to the code should be done by the instance methods changeFirstAidLevel(int newLevel) and changeLicences(String newLicences). Use your utility class Identity.java when you code these methods.
  • Provide a mutator (set) method called setOnDig(boolean flag) that sets the value of the onDig attribute to the flag parameter value.
  • Add an addFieldDays() method that takes an integer argument index (0 for Europe, 1 for Asia and 2 for The Americas) and increases the appropriate element in the fieldDays array by the value of another integer argument days.
  • Add a toString() method that returns a string containing all the current values of the attributes formatted as in the following example for a person named Daniel Jackson, with code M321A2CR, currently on a dig with values of 99, 999, 9999 in the fieldDays array.
name: Daniel Jackson code: M321A2CR onDig: true fields days in Europe: 99 Asia: 999 The Americas: 9999

Before continuing to Task 2, you should run some tests in a driver to verify that your Person class is correct.

Task 2 – Adding and displaying

A menu-based interactive driver program DIGSDriver.java and an array-based collection of persons in RockStaff.java have been partly coded.

See the end of this assignment for skeleton code in DIGSDriver.java and the array-based collection of Person objects in RockStaff.java. Instructions for copying the files from the csilib area are given.

Copy the files into the same directory as your Person and Identity classes, understand the code, compile and see how the menu works. The menu displays as follows and currently outputs messages that a selected option is not yet implemented.

********************
DIGS ROCKS
********************
S) Show all persons
E) Edit submenu
A) Add a person
R) Read from file
C) Choose a group
H) Handle field days
?) Relax
Q) Quit
********************
Please select:

This menu repeatedly displays after each (case-insensitive) user selection, until the user chooses ‘Q’ or ‘q’ to quit the program. Selecting ‘E’ or ‘e’ displays a submenu to make changes to a person’s identity code.

The RockStaff class is designed to contain an array of references to Person objects as one of its attributes. You may assume no more than 2000 people are on the DIGS system. Required functionality for this class includes a constructor (already coded). Write methods to:

In RockStaff.java

  • Add a new person to the staff (with the new person and their code sent as parameters to the method). You may assume the name of each person added is unique.
  • Display the details of all people in the staff to screen. (You may use the toString() method of each Person object.)

In DIGSDriver.java

  • Option ‘A’ requires the user to be prompted to supply the person’s name (which could be more than one word) and their code. Then call the appropriate method in RockStaff to add the person.
  • Option ‘S’ calls the appropriate method in RockStaff to show details of all people on the screen.

Task 3 – Reading from file

You are required to add more functionality to the RockStaff class and then complete more of the DIGSDriver class.

In the RockStaff class write a method to do the following: Given an input file name as parameter, append people from the input file into the array. You may assume that the file exists and contains the details (or record) for each person in 4 lines; that is, name, code, whether they are “on a dig” or “available” and a line containing three integers separated by a space (indicating field days in Europe, Asia and The Americas). A sample input file follows (Note you can use this option any time during the program):

Daniel Jackson
M321A2CR
on a dig
99 999 9999
Indiana Jones
M339A0R
available
1000 867 28
Amy Pond
F246V1RCH
on a dig
50 100 34

Now in the DIGSDriver class implement menu option ‘R’: Option ‘R’ prompts the user for the name of the file and calls the appropriate method in the RockStaff class.

Task 4 – Handling updates to days on field trips

In the RockStaff class write a method to do the following: Given a String parameter corresponding to a person’s name, an integer parameter (value of 0, 1 or 2 corresponding to Europe, Asia or The Americas) and another integer parameter corresponding to the extra days to be added, update that person’s field days and set their onDig attribute to false. If the person does not exist, output an error message to screen. The method heading could be:

public void addDays(String name, int where, int days)

Hint: You may wish to write a search() helper method in RockStaff. It could return the index of the person or -1 if the person does not exist. The method heading could be:

private int search(String name)

Now in the DIGSDriver class implement menu option ‘H’: Option ‘H’ should prompt the user for the person’s name and whether the field trip was in Europe, Asia or The Americas and how many days should be added.

Task 5 – Edit submenu

  • In the RockStaff class write a method that has a name and first aid level as parameter: Find that person and update the first aid level. If the person does not exist display a message to screen.
  • In the DIGSDriver class implement menu option ‘E’: Option ‘E’ displays a submenu with 2 options to change a person’s identity code. Implement each option. For example, for option ‘F’ you will need to prompt for a name and a new first aid level then send that information to a method in RockStaff to find that person and update their first aid level.
  • Do what is required in DIGSDriver and RockStaff to implement the other option ‘L’ in the submenu (displaying a message if the person does not exist). Option ‘L’ should ask for a string with the new licences (as well as the name).

Task 6 – Choosing a new field group

  • In the RockStaff class write a method (that has no parameters) to select a new field group of three members, one from each category (one archaeologist, one student and one volunteer). To be selected, the person must not be currently on a dig. Set each group member’s onDig attribute to true and display the group to screen. If a category has no available person, then still select and display the other members and indicate which category still needs to be filled.
  • Now in the DIGSDriver class implement menu option ‘C’

CSE4OOF Task 7 – Optional bonus for CSE1OOF

  • In the RockStaff class write an overloaded method (that has one string parameter indicating the area Europe, Asia or The Americas) to select a new field group of three members, one from each category (one archaeologist, one student and one volunteer). To be selected, the person must not be currently on a dig and the person with the most days on a dig in that area from those available will be selected in each category. Display the group to screen and set each group member’s onDig attribute to true.
  • If a category has no available person, then still select and display the other members and indicate which category still needs to be filled.
  • Now in the DIGSDriver class modify menu option ‘C’ to ask the user if they wish to nominate an area and then call the appropriate method in RockStaff.

CSE4OOF Task 8 – Optional bonus for CSE1OOF

  • Ensure the names are unique, whether added interactively or from a file. If a name is not unique, do not add that person

Optional Task 1:

  • Redesign menu option ‘S’ so that a submenu is displayed giving options for how to show persons on the screen. Allow options that:
    • Sort all persons by name so that they are displayed in alphabetical order
    • Sort all persons by gender with a subsort on name
    • Ask the user for a licence set and only show those persons with all those licences
    • Ask the user for a minimum number of days in the field and only show those people who have been in the field for that many days or more

Optional Task 2:

Menu option ‘?’ Design a two- dimensional board game to amuse the user during their lunch break. For example, a player could start in the top left hand corner of the board and proceed left to right along each row, until the bottom right-hand corner is reached. Certain board positions could be lucky or unlucky in some way. Display the board, player(s), and other information using characters output to screen, and redisplay the board after each move. Perhaps the ability to stop playing part way through the game (to return to work) would be useful (without saving the game state). On completion of the game, the user is returned to the main menu. Note Math.random( ) is a useful method for generating random numbers.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.