Colorado State University Logo | CS 163/4: Java Programming (CS 1) Colorado State University Logo | CS 163/4: Java Programming (CS 1)
CS 163/4: Java Programming (CS 1)
Computer Science

Practical One - Knight Fight Debug

Introduction

Welcome to your first practical. Practical assignments are longer assignments, and you have roughly two weeks to complete the assignment during a 16-week session (1 week for 8-week class sessions). It is important that you start early, as the most common feedback we get from students is that they wish they started earlier.

For this practical, you will practice two major concepts:

  • Reading Other People’s Code
  • Debugging Code (especially understanding zybooks feedback)

That is it. However, it isn’t as simple as it sounds. Why do we do this? One, it will help you understand debugging in zybooks, and two, debugging other peoples’ code is actually fairly common for your first job. Often, testers are given code and told to “figure it out”. Learning the skills needed to figure out other peoples’ code and correct errors is essential.

Knight Fight
Student, you have been hired by Round Table Games. They are a startup company that believes text-based games are going to make a comeback. However, the programmer they hired to prototype their latest game Knight Fight quit mid-development. You have been hired to pick up the slack. Once completed, you will have a very, very basic game to play.

Your Task For This Practical

Your goal for this practical is to simply get the code working! You may submit as many times as possible, but it is suggested you don’t submit for grading without first trying to figure out ways to debug!

Provided Code

You will find by clicking the drop-down arrow next to the name of the file in zyBooks that this program has a lot of files. Most programs have as much code divided out between files as is reasonable, and this is no exception. In all the files, you will find extensive comments to help guide you on what each method does or is supposed to do.

Where To Start?

Here are some suggestions on how to approach this problem:

  1. First figure out what the code is supposed to do.
    • This may involve writing an outline, documenting it visually on paper, and writing notes to yourself!
    • Feel free to talk with others about it and post any questions you have in MS Teams.
  2. Get the code compiling. The provided code does not compile. Your first step is to find the compiling errors. Make sure to submit to grading after that.
    • Try to run your code in Develop Mode when testing your changes.
  3. After the code compiles, you will have at least 7 (maybe more) logic errors to track down. For simplicity’s sake, we kept those errors to RtKnight, RtView, and RtTarotDeck.
  4. RtView.splash - while not part of the graded code, we would like you to implement the .splash() method. Have FUN with it! You will be asked to post your splash screen as part of Reflection 1, and we will “grade” it there (make sure you completed it).

Suggestions
You should test after every couple statements! While they won’t all work right away, it is much easier to trace errors like missing curly brackets if you are only looking at a couple lines of code.
System.out.println
Is a great tool to debug! We suggest putting “DEBUG” in the line as you debug. For example, System.out.println(“DEBUG: “ + value);

Remember to start early, ask questions, and more! In this case, help desk can’t help you track down the errors themselves, but asking in general channel will cause the TAs and Instructors to provide guides on where to find the errors.

List of Common Errors

Since you may not have encountered some of these errors before, below is a list of common errors you may encounter in the practical and your assignments this semester. There are many error messages out there - if you get one that is unfamiliar, google it. A simple search is a powerful tool that can help point you in the right direction.

Common Errors:

  • Missing semicolon
  • Misspelling variables or methods
  • Variable or method called that has not been declared
  • Missing “}”
  • Class name doesn’t match file name
  • Method has missing or incorrect return type
  • “S” in String not capitalized
  • Failing to use the “this” keyword in setters and constructors
  • Having a return type for a constructor
  • Incorrect spacing when using String format
  • Having unreachable code
  • Method doesn’t do what you expect it to (logic error - hardest to debug!)

Random Insights

No System.out.printlns?

You will notice that none of the classes have System.out.print/println except for RtTests and RtView. This is intentional and common practice. Methods rarely print directly! Instead, they pass messages of information to other methods while user interfacing (UI/UX) happens in a specific layer of your program. In this case, RtView. In the future, we could change RtView to interact with a webpage, making the game a web-based game. UI/UX design is an emphasis of Human-Centered Computing, where as full-stack development is more Software Engineering and focuses on establishing the entire design.

User Interface Design

The RtView class is the heart of your user interface, along with the RtController acting as an interface to the rest of the program. We will explore this MVC design more in the future (take CS 312!), but for now, go here to learn about user interfaces.

Some examples of splash screens:

======== WELCOME ======
=  Round Table Games  =
=     Introduces      =
=                     =
=     Knight Fight    =
= Quest for the Grail =
=                     =
=======================

or fancier

Knight Fight: Grail Quest
_,.
,` -.)
( _/-\\-._
/,|`--._,-^|            ,
\_| |`-._/||          ,'|
|  `-, / |         /  /
|     || |        /  /
`r-._||/   __   /  /
__,-<_     )`-/  `./  /
'  \   `---'   \   /  /
|           |./  /
/           //  /
\_/' \         |/  /
|    |   _,^-'/  /
\    , ``  (\/  /_
(  /   `-._/x/^`
`Y-.____(__}
|     {__)
()
by
Round Table Games          

ASCII art source.

Submitting

Make sure to click through canvas before your last ‘submit for grading’. This will ensure the code is linked and updates to Canvas. After submitting, you should complete Reflection 1.

Computer Science Department

279 Computer Science Building
1100 Centre Avenue
Fort Collins, CO 80523
Phone: (970) 491-5792
Fax: (970) 491-2466

CS 163/4: Java Programming (CS 1)

Computer Programming in Java: Topics include variables, assignment, expressions, operators, booleans, conditionals, characters and strings, control loops, arrays, objects and classes, file input/output, interfaces, recursion, inheritance, and sorting.