We are going to start our problem-solving education by writing a program that simulates a pair of dice.
This assignment will give you practice using Eclipse to create and test a Java program. Hopefully, you set up your Eclipse environment to make this assignment easier to complete.
You could use the New -> Class option to help you build the program.
You could set up Eclipse’s Java -> Code Templates -> Comments to automatically conform to the Checkstyle guidelines. This will make your programming lives much simpler.
You could set up Eclipse to use checkstyle to show you any style errors in your code.
Or you can do it all by yourself and spend much more time getting the homework done.
This project is where we will be doing all our homework assignments for ICS 111. Here’s a screen shot of my Eclipse with my cmoore
project.
This is where we will put all our classes for homework 01. To create a package right mouse click on the project, choose new, then choose package.
In the dialog box type in ‘edu.ics111.h01’. Packages are Java’s way of grouping things together. We are going to put all of our Java files for each homework in a different package.
Here’s a screen shot of my workspace with the package.
.
Write a program that simulates rolling a pair of dice. The program should output the value of each die and the sum of the two dice. Your output should look something like:
The first die comes up 3
The second die comes up 5
Your total roll is 8
To create a program in Eclipse right mouse click on the package, choose New -> Class then fill out the information in the dialog. Here’s a screen shot of my SixSidedDieSimulation dialog.
I decided to name my class ‘SixSidedDieSimulation’ since that is a descriptive name for what the program does. Also notice I chose ‘public staic void main(String[] args)’ and ‘Generate comments’. These choices will add a main method and comments. Here’s a screen shoot of the Java code generated.
Note: I’ve turned on Checkstyle, so I have 5 Warnings I need to fix if I want full credit for the homework.
Now we can start working on solving the problem of simulating two six-sided die. What are the steps we need to take? How do we get a random number? Hint
Create another program to simulate two 20 sided dice. Follow the same steps as above to create the Java program and solve the problem.
Create a third program that asks the user for the number of sides for the dice, then simulate rolling them. What do you do if they give a bad answer?
Criterion | Excellent (100%) | Satisfactory (75%) | Borderline (50%) | Unsatisfactory (25%) | Poor (0) |
---|---|---|---|---|---|
Adherence to standards - 2 points Does it conform to standards in every detail? |
No errors. | Minor details of the assignment are violated, or poor choices are made where the assignment is unclear. | Significant details of the assignment or the underlying program intent are violated, but the program still fulfills essential functions. | Significant details of the assignment or the underlying program intent are violated, but the program still fulfills some essential functions. | Misses the point of the assignment. |
Breakdown (modular design) - 1 point Does it demonstrate good modular design? |
No errors. | 1-3 minor errors. | > 3 minor errors OR 1 major error. | 2 major errors | > 2 major error. |
Correctness of code - 5 points Does it work? Does it pass JUnit? |
Passes all tests. | Works for typical input, may fail for minor special cases. | Fails for typical input, for a minor reason. | Fails for typical input, for a major reason. | No. |
Documentation, and style - 2 points Is it clear and maintainable? Does it pass CheckStyle? |
No errors. | 1-3 minor errors. | > 3 minor errors OR 1 major error. | 2 major errors | > 2 major error. |
The assignment is due on Friday, September 3rd at 11:55pm. You may turn it in early.
Conduct a personal review of your code before turning it in. Does your code follow the Java Coding Standard?
Test your code.
Export your ICS111-workspace project by choosing File -> Export.
Under General choose Archive File.
On the next dialog choose only the src files in your project. Uncheck any other files or directories
Name the zip file H01.
Sign into Laulima, then navigate to the ICS111 site. In the left hand side of the site, there is an Assignments tab/link. Click on it and view all of the posted assignments. Select the assignment that you want to turn in and attach your H01.zip file and accept the honor pledge to submit the assignment.