Most solutions will be posted on Piazza, under the Resources page:
Deadline: Fri 9/12, 5pm.
In a plain text file called largestOfFive.txt, write an algorithm to find the largest of 5 numbers that are in a container. The values of the numbers are unknown when you start. Also, you must take the numbers out of the container one at a time. Use the CS-175/501a ecampus dropbox to turn in largestOfFive.txt. See http://en.wikipedia.org/wiki/List_of_text_editors to see a list of plain text file editors.
Modify the default robocode robot you started in lab to run in a figure eight pattern.
Turn in your robot's java code file, e.g. RobotName.java, using the CS-175/501a ecampus dropbox.
Deadline: Tue, 9/23, noon.
In Robocode create ChaseBot1
.
ChaseBot1
scans an enemy robot and follows that enemy robot by moving toward it.
Test your ChaseBot1
against the Crazy
sample robot.
Customize your ChaseBot1's
colors.
Dropbox ChaseBot1.java
.
Start a new Robocode robot named SpiralBot
.
Define the SpiralBot
robot's movement as follows:
For each turn, move forward a total of N pixels per turn, then turn right 90 degrees. Before the robot starts any movements, the variable N must be initialized to 15, and increase by 15 pixels per turn. N must be an instance variable of SpiralBot
.
Customize your SpiralBot's
colors.
Dropbox SpiralBot.java
.
Deadline: Thurs, 10/2, noon.
Do programming project “Business P4.5” on p. 172 of the book. Dropbox the program as BookOrder.java.
Do programming project “Business P4.7” on p. 173 of the book. Dropbox the program as DollarsCents.java.
In NearestWallBot1.txt (plain text file), write an algorithm to move a robocode robot to the nearest wall.
Deadline: Wed, 10/15, 5pm
Start a new Robocode robot named AdjustFireBot2. Change the AdjustFireBot2 robot's onScannedRobot method to fire the cannon with a power level that is inversely proportional to the distance between your robot and the scanned enemy robot. The idea is similar to what we did earlier to adjust the cannon fire power. But instead of using discrete fire power levels like 1.0, 2.0, and 3.0, we will compute the cannon power level based on distance.
The minimum fire power level is 0.1, and the maximum fire power level is 3.0 (See Robocode API). At maximum distance apart, your robot should fire with power=0.1. At minimum distance apart, your robot should fire with power=3.0.
Dropbox AdjustFireBot2.java.
P * (maximum distance) = ((maximum distance) - D ) * 3.0 (Re-arrange and solve for P; assumes you passed algebra.)
See the AdjustFireBot2 template.
Create CenterBot1. CenterBot1 moves to the center of the arena, spins around in a circle, and stops.
Dropbox CenterBot1.java.
See the CenterBot template for Approach #1.
Deadline: Thurs, 11/6, noon
Download the Assignment 5 file.
Deadline: Tues, 11/18, noon
We worked on a convenient randbetween method before. Improve the randbetween method in the following way:
// Simulate rolling a 6-sided die (1-6): System.out.println( randbetween(1, 6) ); System.out.println( randbetween(6, 1) ); // also works // Simulate a coin toss (0-1): int randnum = randbetween(0, 1); System.out.println(randnum); randnum = randbetween(1, 0); // also works System.out.println(randnum);
Test the improved randbetween method in a program called TryRandom4.java. Dropbox TryRandom4.java.
We worked on a program to compute the body mass index (BMI). Complete the following method to compute and return the BMI value for a given mass in lbs., and height in feet & inches:
public static double getBMI( double mass, int feet, int inches ) { double bmi; // compute from mass, feet and inches // // Your code goes here. // Use no System.out.println statements. // Do no Scanner input. // return bmi; }
Dropbox getBMI.java. Make sure getBMI.java contains only the getBMI method code.
Write and dropbox a program ValidTriangles.java that reads three edges for a triangle and determines whether the input is valid. The input is valid if the sum of any two edges is greater than the third edge. Here are two sample user dialogs from running this program:
Enter the three integer edges of a triangle: 1 2 1 Can edges 1, 2, and 1 form a triangle? NO Enter the three integer edges of a triangle: 2 2 1 Can edges 2, 2, and 1 form a triangle? YES
Use a while(true) loop in the program to read triangle edges and determine valid triangles continuously.
Deadline: Wed, 11/26, 7pm
This is related to the ValidTriangles program from Assignment 6. (See the Resources page, Resources tab on Piazza for all assignment solutions.) Complete the following method to return true if a triangle with given side1, side2 and side3 is a valid triangle.
public static boolean validTriangle( int side1, int side2, int side3 ) { boolean valid = false; // assume false // // Your code goes here. // Use no System.out.println statements. // Do no Scanner input. // return valid; }
Put the validTriangle method in the ValidTriangles2.java program, along with the main method. In the main method of ValidTriangles2.java read three edges for a triangle via Scanner, call the validTriangle method with the three edges as input parameters, and print whether the input is valid. Here are some sample user dialogs from running ValidTriangles2.java:
Enter the three integer edges of a triangle (-1 to quit): 1 2 1 Can edges 1, 2, and 1 form a triangle? NO Enter the three integer edges of a triangle (-1 to quit): 2 2 1 Can edges 2, 2, and 1 form a triangle? YES Enter the three integer edges of a triangle (-1 to quit): -1
Use a while(true) loop in the main method to read triangle edges and determine valid triangles continuously. Allow the user to enter -1 to quit.
Dropbox ValidTriangles2.java.
Complete the GuessNumber.java program. Your program must include the 3 possible improvements.
Dropbox GuessNumber.java.
From the book, do review exercises R6.2 (a only), R6.15, R6.19 (a, b, d), R6.27. Write your answers in assign7revex.txt (plain text) and dropbox it.
Deadline: Tues, 12/9, noon
(CS-175/501a-50 only)
Complete problem #11 of Quiz 2. Dropbox FactorialProg1.java.
Rewrite the following program using a 'for' loop instead of a 'while' loop. The rewritten program must function in the same way as the original program below. Dropbox the rewritten program as EquivalentFor.java.
public class EquivalentFor { public static void main( String[] args ) { int i = 0; int j = 0; while ( i <= 20 ) { j = i * i * i; i = i + 1; } System.out.println( "final values: i = " + i + ", j = " + j ); } }
See assign8sample2.txt. Dropbox Prog1.java, Prog2.java and Prog3.java.