ENGG4450_LabTest_F23

pdf

School

University of Guelph *

*We aren’t endorsed by this school

Course

4450

Subject

Computer Science

Date

Dec 6, 2023

Type

pdf

Pages

8

Uploaded by JudgeEnergy7876

Report
Student Name: Student ID: This is a test. Therefore there should be no communicating (verbally or electronically) with other students in the class. You are free to use command-line help or man pages (e.g. man git, git --help ) but written notes, web browsing, and opening files that are not explicitly named in this test are forbidden. The only tools that should be open on your computer are the Bash shell, a text editor of choice (e.g. gedit, vim, emacs) and Astah. All forms of chat, messaging and email are forbidden. Personal electronic devices (including laptops and phones) are also forbidden. This test has 6 questions, for a total of 100 points. You have 110 minutes to complete this test Getting Started Create a directory in your home directory called lab_test in which to save your work. Open a Bash shell, and issue the following commands: mkdir lab_test cd lab_test mkdir uml When asked, save all of your UML diagrams to the uml directory. In question 1, you will be asked to clone a repository. Clone the repository into the lab_test directory. The lab_test will have two subdirectories: one for UML and the other for code. We’re not assessing your typing speed. The code for the questions can be found in the github repository in the resources folder. The Test 1. For this lab test, we’re going to look at some simple Java classes for managing a com- pany’s fleet of boats. Unfortunately someone on the dev team has accidentally deleted the design specs (including all of their UML diagrams) and the company doesn’t keep backups. They’ve been fired so you’ve been asked to reverse engineer the Java code and get the design back. Before starting please open the below URL address then fork the lab test project with your account. Forking is necessary because based on that we can evaluate you. (a) (5 points) Clone the boattracker repository from https://github.com/uoguelph-engg4450/boattracker_public_lab_test.git
Note: if you do not know how to clone the repository or find the source code you can ask one of the facilitators to clone the repository and show you how to find the source code. However, you will lose 5 points. (b) (15 points) Examine the following classes: Company.java Employee.java Boat.java Using the Astah Community tool, draw a class diagram which shows all classes, their dependencies, attributes, and methods. Interpret the relationship between Company and Employee like this: if the company goes backrupt, all of Employees will be fired and the Employee records will be destroyed. Save your class diagram to boattracker_class.asta . Export a png image to boattracker_class.png . 2. The company has decided that it wants to assign boats to multiple employees. Let’s break all the rules we discussed in lectures and jump right into development! Go back to the terminal and locate the repository you cloned. (a) (5 points) Create a branch (starting from master ) called experimental . Switch to this branch. (b) (5 points) Change the directory to boattracker/src/main/java/boattracker . Edit the existing file as follows: Boat.java package boattracker; import java.util.ArrayList; public class Boat { private String modelNumber; private String boatColor; private double boatPrice = 0.0; private ArrayList<Employee> users = new ArrayList<Employee>(); public Boat(String modelNumber){ this.modelNumber = modelNumber; } public String getBoatColor() { return boatColor; } public double getBoatPrice() { return boatPrice; } Page 2
public void addUser(Employee employee){ this.users.add(employee); } public void removeUser(Employee employee){ this.users.remove(employee); } } Commit Boat.java to the experimental branch. Use the commit message “Boats now support multiple employees”. (c) (5 points) The model has changed. Go back to Astah and retrieve your ear- lier class diagram: boattracker_class.asta . Save it under a different name: boattracker_multi.asta . Modify the diagram to reflect the changes you just made. Be explicit about multiplicities. Save your diagram and export a png image to boattracker_multi.png . 3. The company has decided that the Employee class should also keep track of the boats to which a given employee is assigned. (a) (5 points) Modify the existing code as follows: Boat.java package boattracker; import java.util.ArrayList; public class Boat { private String modelNumber; private String boatColor; private double boatPrice = 0.0; private ArrayList<Employee> users = new ArrayList<Employee>(); public Boat(String modelNumber){ this.modelNumber = modelNumber; } public String getBoatColor() { return boatColor; } public double getBoatPrice() { return boatPrice; } Page 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
public void addUser(Employee employee){ this.users.add(employee); employee.addBoat(this); } public void removeUser(Employee employee){ this.users.remove(employee); } } Employee.java package boattracker; import java.util.ArrayList; public class Employee { private int empId; private String department; private String name; private ArrayList<Boat> boats = new ArrayList<Boat>(); public Employee(int employeeId, String department) { this.empId = employeeId; this.department = department; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } public String getDepartment() { return this.department; } public void addBoat(Boat boat){ this.boats.add(boat); boat.addUser(this); } } Page 4
Commit your changes to the experimental branch. Use the commit message “Em- ployees keep track of assigned boats”. (b) (5 points) Oops! That was a bad idea. We seem to have introduced a circular dependency. When we add an employee to a boat, it adds itself to that employee, which adds itself to the boat, and so on... We better fix that. Let’s introduce a new class for keeping track of employee-boat pairings. Create a new file in the boattracker/src/main/java/boattracker directory, as follows: BoatTable.java package boattracker; import java.util.HashMap; import java.util.Map; import java.util.ArrayList; import java.util.Iterator; public class BoatTable { // maps boats to a list of users private HashMap hm = new HashMap(); public void addPair(Boat boat, Employee employee){ //create new list if it doesn't exist ArrayList<Employee> boatlist = (ArrayList)hm.get(boat); if (boatlist == null){ ArrayList<Employee> l = new ArrayList<Employee>(); l.add(employee); hm.put(boat, l); } else { boatlist.add(employee); } } public void removePair(Boat boat, Employee employee){ ArrayList<Employee> boatlist = (ArrayList)hm.get(boat); boatlist.remove(employee); if (boatlist.isEmpty()) { hm.remove(boat); } } public ArrayList<Employee> getUserList(Boat boat){ // return a list of employees assigned to a boat return (ArrayList<Employee>) hm.get(boat); Page 5
} public ArrayList<Boat> getBoatList(Employee employee){ //return a list of boats assigned to a user ArrayList<Boat> l = new ArrayList<Boat>(); Iterator it = hm.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); Boat key = (Boat) entry.getKey(); Employee value = (Employee) entry.getValue(); if (value == employee) l.add(key); } return l; } } The existing files, Employee.java and Boat.java should be modified to remove the logic associated with the employee-boat pairings. Restore these two files to their state before Question 3. Do this with git commands, not by replacing the contents of the files. Make sure you do this without losing any earlier commits (i.e. do not do a git reset --hard ). Just to make sure you did this, tell us how you did it by writing your answer here: (c) (5 points) Now commit the updates using the message: “Broke circular depen- dency”. (d) (5 points) Squash the last two commits together so that the last two steps (intro- ducing the bidirectional dependency and moving the logic to BoatTable ) appear as a single commit. Use the commit message: “Introduce BoatTable for employee-boat pairings”. (e) (5 points) Tag this commit with: boattable . 4. Management has come back to you and said that they would like to improve the organi- zation of the system. Specifically, they would like to separate the Company and Employee classes from the Boat and BoatTable classes. (a) (5 points) Create a new directory, boattracker/src/main/java/boattracker/internal . Move Company.java and Employee.java from boattracker/src/main/java/boattracker to the new directory. Page 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Now create another directory, boattracker/src/main/java/boattracker/boats . Move Boat.java and BoatTable.java from boattracker/src/main/java/boattracker to the new directory. Update the source code to reflect the new dependency struc- ture: Company.java package boattracker.internal; public class Company { private Employee[] employees; } Employee.java package boattracker.internal; import boattracker.boats.*; public class Employee { ... Boat.java package boattracker.boats; import boattracker.internal.*; public class Boat { ... BoatTable.java package boattracker.boats; import boattracker.internal.*; import java.util.HashMap; import java.util.Map; import java.util.ArrayList; import java.util.Iterator; public class BoatTable { ... Commit the new structure with the message “Separated into internal and boats packages”. (b) (10 points) Go back to Astah and create a UML package diagram that shows the various packages and their dependencies. Save your class diagram to boattracker_package.asta . Export a png image to boattracker_package.png . 5. We’re not done yet with our project, but our teammates want to see how we’re doing on the code. Let’s submit the current state of the code for review on ReviewBoard. Create a file called .reviewboardrc file in the repository root and carefully set the file contents to: Page 7
REPOSITORY = 'boattracker' (a) (5 points) Submit a code review. Use the command (the following should be on one line and don’t type the “ <> ” brackets, they are placeholders): rbt post --guess-summary --guess-description --username=<your RBCommons username> --parent=master --tracking-branch=origin/master --publish --target-people=baucas The --target-people=baucas argument sets the reviewer to be the TA. (b) (5 points) Switch back to the master branch. Add a file README.md with the fol- lowing content: README.md Boat Fleet Tracker Software (c) 2019, ENGG*4450 Consulting, Inc. Commit this file with the message “Added README describing the application” (c) (10 points) Oops, if we were to merge the change in the experimental branch back into master , git would have to do a three-way merge and this would result in a forked history. Switch back to the experimental branch and perform the necessary actions to merge experimental back into master while producing a linear commit history. Hint: you will need to use the rebase , checkout and merge git commands. Submitting Your Work We assume that your directory structure looks like this: $HOME lab test uml boattracker Create a single zip file called <username>_lab_test.zip which contains all of your work: cd zip -r <username>_lab_test.zip lab_test Replace <username> with your actual University of Guelph username. 6. (5 points) Upload the zip file to the “Lab Test” Dropbox on the Courselink site. You are now allowed to use the web browser (e.g. Firefox) but you must go di- rectly to the Courselink Dropbox and submit your work. Once you have opened Firefox you are not allowed to make any more changes to your sub- mission. If you have problems with the submission, talk to one of the facilitators before your time is up . Page 8 21 2021 .reviewboardrc REVIEWBOARD_URL =