CS 149 Intro to Programming

Fall 2020

Practice Coding Exam 1

This is a "closed book" examination and you must work entirely on your own. However, you may use the reference card provided to you.

The source code you submit must be entirely your work and must be written entirely during the class period. The use of any pre-existing code (other than that provided as part of the exam) is prohibited and will be considerd an honor code violation.

You may only use a terminal/shell window, the course IDE (jGrasp) and a WWW browser; the only page you may load in the WWW browser is the course submission site on Autolab.

Your code need not comply with the course style guidelines and need not include comments.

You must submit your code using the course submission system Autolab; your code for each question must be submitted separately in a single .java file (appropriately named). If the code you submit for a particular question does not compile against the official tests you will receive a grade of 0 on that question. Hence, you should stub-out your classes before you do anything else (i.e., make sure that your classes have all of the required methods, and that each method has the correct signature and returns an appropriately-typed value if necessary).

Your last submission is the one that will be graded. No limit will be placed on the number of submissions but, obviously, you must complete the exam during the class period and submissions waste time. The submission system will not provide hints.(50 points)

Your grade may differ from the grade Autolab gives you. I will deduct points for poor coding. Likewise, if your solution is close, I may offer some partial credit. However, you should strive to have Autolab award you all the points.

Problem Description

Complete the following Game class which must contain a method named playerTurn() and a method named movePieceBy().

(30 points) movePieceBy() is passed an int board position (there are 32 such positions and they are 0-based) and an int representing the number on one die. It must return the board position that corresponds to advancing the current board position by the number of positions on the die. So, for example, if the current position is 18 and the number on the die is 22, it must return 8.

(20 points) playerTurn() is passed two int values representing the number of moves made in the game and the number of players(0 to n-1). playerTurn() must return an int for represeting the number for the player whose turn it is to go(player 0, player 1 for 2 player game). So, for example, it must return 3 if it is passed 8 and 4 and must return 0 if it is passed 5 and 2.

Your solution must not print to the console/display and must not read from the console/keyboard. You may write a main class (with a main() method) for testing purposes, but you should not submit it.

Note: The elegance of your solution matters. That is, there are more and less elegant solutions to this problem. The more elegant your solution, the more points you will receive.  Your solution should not contain item not covered in Chp1-4 of Think Java(if-then-else, loops, etc...).

public class Game {

    public static int movePieceBy(int position, int number) {






    }




    public static int playerTurn(int moves, int players) {





    }
}

Test Submission Area on Autolab

You can submit your test submission to Autolab for grading, however, as mentioned previously, Autolab is specifically configured to only provide your grade (and no hints on what is wrong/missing).

It is recommended that you give yourself at most 35 minutes to complete this program, since that is the amount of time you will to complete it on the day of the exam (assuming you split your time 50/50 with the written portion of the exam).