Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

EECS 2030 Programming Exam 1

Fall 2022

In the first programming exam, we are going to assess your ability for the following skills:

•    Ability to design recursive functions.

•    Ability to test your code thoroughly, through Junit tests.

•    Ability to encapsulate data.

•    Ability to copy objects as requested.

•    Ability to document your code.

Setting up the environment:

❖ Download the attached zip file.

❖ Open eclipse.

❖ Click on File and select Import

❖ Choose Existing Projects into Workspace and click Next

❖ Click on Select Archive File and then Browse.

❖ Find the zip file that you have already downloaded and click Finish

❖ Please make sure that you do not already have a project called EECS2030_Fall22_PE1

❖ Now you should see the following settings in the package explorer.

 

Before you start, I would like to remind you that this assignment is different from the labs that you have done until now, as this assignment is an exam that you take home. This means you can neither discuss your solution with peers nor get help from peers/others. Therefore, please carefully read the statement at the top of PE1.java before you start doing the assignment. If you only see one line, there is a + sign next to the text that opens the text for you. When you finished, you will be needed to sign this statement by writing your information (full name and student number and section) in the gap provided. Please be aware that your exam WILL NOT be marked if you do not sign the declaration. Also, I would like to inform you that your code will be checked by both a plagiarism detection tool and us to make sure your solution to this problem is unique and not like others.


Problem Description:

In this assignment you are going to help my dog find a path from where he is to where his favourite snack (i.e. peanut butter) is. I’ve made a maze for this purpose, which fits one of my rooms. There is no way that he can get to peanut butter unless he passes through the maze. The maze that I have designed has an entrance, exit and at least one path that gets my dog to the peanut butter. The idea is that each time I’m busy teaching you and I don’t want him to disturb me, I set a new form of maze for him to engage him. I’m going to give you the layout of the maze and you are going to give me a path from where my dog is to where the peanut butter is placed. I’m going to mark the path that you identify with another favourite of his (yogurt). He sniffs the path and follow the yogurts until he gets to the peanut butter.

 

To implement the maze, I used a two-dimensional array, where the element of the array shows which side of the maze is open. The element of the array is a string of length four and contains only zero and one.  Zero means the side is open and 1 means it is blocked. The first, second, third and fourth digits shows the state of the top, left, bottom and right side of one cell respectively. Please see the following example that shows how the maze is created. The left picture shows the maze, while the right shows the content of the array that represent the maze.

 


To solve this problem, you should assume that

•    the maze has been made such that there exists at least one path from the entrance to the exit.

•    the maze can be of any width or length >= 4, where width and length show the number of rows and columns.

•    the maze has either a square or rectangular shape.

Please note that no test case is given for this assignment. Instead, you need to write the junit test cases yourself.

Task 1:

The first task is to make the maze. A class is created called Maze, in which a 2D array for the maze is declared. Your job  is to  implement the constructor according to the given javaDoc.   When you completed this task, write a set of Junit test case to test your code.

As you probably noticed, the maze is defined as a private variable. The second job for you is to write an accessor(getter) method that returns the maze. Other information about what is expected for this method is given in the starter code.

Task 2:

Implement the toString() method for class maze such that the content of the maze is returned as it is seen in the array. For example, if the maze is defined as

String [] array = {{"1110", "1010", "1010", "1000"},

{"1010", "1000", "1001", "0101"},

{"1100", "0011", "0101", "0110"},

{"0101", "1101", "0110", "1001"},

{"0110", "0011", "1110", "0010"}};

then the toSting() should return

[1110 1010 1010 1000]

[1010 1000 1001 0101]

[1100 0011 0101 0110]

[0101 1101 0110 1001]

[0110 0011 1110 0010]

Hint: “\n” is used to create a new line.

Task 3:

Implement method setup in PE1 class. The description of what is wanted is given in the starter code.

Task 4:

The first  problem that you  solve  recursively  is to  implement  enoughGate() to  check  if the dogMaze has at least two gates (one for the entrance and one for the exit). This problem must be solved recursively, however there is no limitation on what type of recursion (i.e., direct or indirect recursion) you use .

As a reminder, a direct recursion refers to the function that calls itself to solve the given problem. However, by indirect recursion, more than one function involves in solving the problem. It is possible that a non-recursive function solves a small part of the problem and then calls the recursive function to finish the job.

 

Please note that any method that you write in addition to the given methods in the starter code, must have its javaDoc.

Task 5:

In this task, you are going to find a path from an entrance to the exit. Please note that for this task, we assume that the maze has only two gates.  However, it is possible that more than one path exists from the entrance to the exit.

The method that you implement is findPath() that gets two integers that refers to the index of

the entrance. For example, for the above maze, findPath(1, 0) is called. The output will be (1,0)(1,1)(1,2) (2,2)(3,2) (3,3)(4,3)(4,5) (3,5)

This task should be solved recursively, however there is no limitation on how you solve the problem. You are allowed to solve it via direct or indirect recursion.

Marking Scheme:

•    [15 points]: For the correctness of task 1.

•    [5 points]: For the correctness of task 2.

•    [5 points]: For the correctness of task 3.

•    [20 points]: For the correctness of task 4. If the method is correct but not recursive, no points will be awarded.

•    [30 points]: for the correctness of task 5. If the method is correct but not recursive, no points will be awarded.

•    [25  points]:  For javaDoc,  inner  documentations,  and  correct  code  style  (meaningful variable names, correct indentations). We assume that you get this 25% and then we start deducting marks for the following problems.

▪  -2 for every complex code that does not contain a comment. The maximum deduction is 4 points.

▪  -2 for every meaningless identifier name. The maximum deduction is 6 points.

▪  -5 points if there exist one method without javaDoc.

▪  -2 for every indentation flaw.  The maximum deduction is 6 points.

▪  -2 points for unnecessary codes. The maximum deduction is 4 points.

Checklist:

Before you submit, check this checklist to ensure that you have done all we asked you to do.

     I have finished tasks 1, 2, 3, 4, and 5.

     I have signed the statement on academic honesty.

     I have removed/commented out the main() method in case I have added it to the code.      I have tested my code with a set of JUnit test cases, which I have written myself.

What and how to Submit:

•    You only submit one file, which is the completed PE1.java file.

•    Submit your solution in eClass, where you have downloaded these instructions