COVID 19 SCENARIO
July 6, 2020
intro to java assignment
July 6, 2020
Show all

12.10 Code Refactor 2: Tic Tac Toe

Please note that there was an error with the original code template that was corrected at 7:50 on 4/22/2020. The arrays in the conditional statements for the fw and sp methods are supposed to all be the same.
This code works but there are some problems that need to be corrected. Your task is to complete it to course style and documentation standards CS 200 Style Guide. This project will be human graded with the Grading Rubric below.

During the process of writing code, the programmer is deeply immersed in the problem, the algorithms and code to solve it and has that context when naming methods, variables and writing comments. Looking at someone else’s code, or even your own code 6 months later can be challenging since the names and comments weren’t necessarily written to guide someone new to the problem and code. This assignment’s code works, but some methods have poorly chosen names, formatting, and comments. The objective is to format it, reduce redundant code, improve the naming and commenting to help guide someone like yourself, that is new to the code and problem, through it.

Play the game, add additional print statements to learn about the contents of the variables and use the debugger to systematically step through the code.

Getting Started
Set up a Code Refactor 2 project in Eclipse
Download CodeRefactor2.java and make sure it runs in Eclipse.
Note: The provided code works. The goal is to refactor, improving the code while keeping it working.
Add a file header comment.
Turn in the code to zyBooks to make sure all the tests pass.
Style and Format each of the methods
Format the method code to follow course standards.
In Eclipse it may be helpful to select code to format, go to Source menu, and select Format (Alternative: Ctrl + Shift + F).
Verify your program is still working.
Turn into zyBooks to verify your program is still working.
Turning in also saves snapshots of your code to return to at a later time if necessary.
If at any time your program is not working then back up to a point it was working and try again.
Refactor the identifiers (names)
Some methods have been named and commented to help give you more context in understanding the code. You do not need to update these method names or the local variable names in these methods
Refactor the magic numbers declared at the top of the class, and update any uncommented methods with new methods names, parameters, and local variables that are meaningful and follow course standards.
Meaningful names easily guide someone that is not familiar with the code to understand what the method does or what the variable contains. Variables are typically nouns or noun phrases while method names are typically verbs or verb phrases. Avoid abbreviations unless very commonly used.
In Eclipse, select the variable, right-click on the name, select Refactor, then Rename. Type the new name and Enter and the name will be changed everywhere. (Alternative: Alt + Shift + R)
It is acceptable for array indexes to have single-character names such as i, j, k, etc.
Trace the code through the provided examples and any additional examples to figure out what is happening.
Trace by hand, use print statements or use the debugger.
If you add print statements to help you debug, remember to remove them later.
Verify your program is still working.
Turn into zyBooks periodically to verify your program is still working and also provide snapshots of your code to return to at a later time if necessary.
Create a new method to reduce redundant code
There is a complicated set of if/else statements with a very similar structure in three different methods
Review this code to understand what it does
Create a method to perform the same task and replace the repeated code with your method
Add Class and Method Header Comments
Write a JavaDoc comment for the class and every method following the course standards. Method comments should include at least a summary description and @param and @return tags (if there is a return value) with a description. We expect you to use your own words.
Verify your program is still working.
Turn into zyBooks periodically to verify your program is still working and also provide snapshots of your code to return to at a later time if necessary.
Final Submission
Make sure your code follows all the standards in the Grading Rubric and expectations described in CS 200 Style Guide. Turn in your final version to zyBooks. The latest version that compiles and runs prior to the deadline Thursday, April 23th at 11:59 pm (no 10% penalty after 6 pm) will be the version that is human graded.
Grading Rubric
Commenting and Documentation
File and JavaDoc Class Header
JavaDoc Method Headers include a summary description and @param and possibly @return tags with descriptions.
Style and Structure
Appropriate use of spacing, both vertical and horizontal
No lines exceed 100 columns
Consistent placement of parentheses and braces
Helpful identifier naming that follows course conventions (e.g., methods, variables, constants)
Doesn’t use Java features past Chapter 12. Any fields should be constants (static final).
4/18/20 jimw – modifed to not use Java features past Chapter 12.

4/22/20 apk – updated test method to avoid infinite loop when structural changes are made to the code. Fix: The arrays in the conditional statements for the fw and sp methods are supposed to all be the same.

Leave a Reply

Your email address will not be published. Required fields are marked *