On This Page
Overview
The main points of this assignment are to:
- Use variables and arithmetic statements
- Use if statements and loops with strings
- Compare
String equality
- Make use of Java's libraries for console I/O
^ top
Lab Exercises
In these exercises you explore Java control-flow statements.
Specifications
- Prepare a single text file named:
exercises.txt. Record answers to all the exercises in this file, labeling each answer with the exercise number.
- Complete self-test exercises 5 on page 102 of your textbook.
- Complete self-test exercises 13, 14, 15 and 16 on page 113 of your textbook.<
- Complete self-test exercises 17 and 18 on page 116 of your textbook.
- Complete self-test exercises 19 and 20 on page 127 and 128 of your textbook.
- Complete self-test exercises 22 and 23 on page 133 of your textbook.
- When finished, do not forget to upload your file to Blackboard as part of this assignment
^ top
Project Specifications
Write a program that draws either a rectangle or a triangle as shown in the sample operation below. Note that the size depends upon user input. The specifications include:
- The program first must display a menu that allows the user to enter either an upper or lower case R for rectangle, a T for triangle or Q to quit.
- Any other entry, besides an R, T or Q, displays an error message and allows the user to try again (with exceptions for the extra credit).
- If the user enters an R (for rectangle), the program must prompt for the width and the height (in that order) and then display a rectangle like the one shown in the Example Operation.
- If the user enters a T (for triangle), the program prompts for the width only and then displays a triangle like the one shown in the Example Operation.
- Also, the program must redisplay the menu and repeat until the user chooses to quit by entering a Q.
- You must use a
Scanner object to read input from the keyboard.
- Your program must operate in the order shown in the Example Operation and demonstration file shown below. In other words, I must be able to enter the same sequence of inputs to produce the exact same shapes.
- Do not use any package statements.
- Submit your files to Blackboard as explained in the section of this document: What to Turn In.
Example Operation
Choose a figure to draw:
R: rectangle
T: triangle
Q: quit
Choice: r
Rectangle width: 7
Rectangle height: 3
Rectangle:
* * * * * * *
* *
* * * * * * *
Choose a figure to draw:
R: rectangle
T: triangle
Q: quit
Choice: t
Triangle width: 4
Triangle:
*
* *
* *
* * * *
Choose a figure to draw:
R: rectangle
T: triangle
Q: quit
Choice: q
Goodbye
Also, you can download and run the asn03demo.jar file. Note that you cannot double-click the JAR file and must run the demo from the command line:
java -jar asn03demo.jar
Also note that the JAR file may contain some extra credit features.
Hints
- Review the example on Drawing Squares in lesson 3.2.4: Nested Loops.
- Picture the shape you want to draw on a grid of rows and columns.
- When you do not print a "*" you need to print a space, which you can control with an
if statement.
^ top
Extra Credit
Adding the following are worth extra credit points:
- Change the program to allow a user to enter a D (for diamond) in addition to R, T or Q. If they do, then the program asks for the width and displays a diamond like that shown below: (2 points)
Choose a figure to draw:
D: diamond
R: rectangle
T: triangle
Q: quit
Choice: d
Diamond width: 4
Diamond:
*
* *
* *
* *
*
Choose a figure to draw:
D: diamond
R: rectangle
T: triangle
Q: quit
Choice: d
Diamond width: 5
Diamond:
*
* *
* *
* *
*
Note that if the user enters an even number that you round up to an odd number to produce the diamond shape. Thus entering either a 4 or a 5 for the width produces the same width of diamond.
- Package your program as an executable JAR file following the instructions for Archive Your Files in How To Submit Homework Assignments. (1 point)
Note that you cannot double-click to run this JAR file because it is a console program. Instead, you can run it from the command line:
java -jar asn03.jar
Make certain that your README.txt file describes any extra credit attempted.
^ top
Grading Criteria
The instructor will evaluate your assignment using the following criteria. Each criteria represents a specific achievement of your assignment and has a scoring guide. The scoring guide explains the possible scores you can receive.
Some scoring guides have a list of indicators. These indicators are a sign of meeting, or a symptom of not meeting, the specific criterion. Note that a single indicator may not always be reliable or appropriate in a given context. However, as a group, they show the condition of meeting the criterion.
For information on grading policies, including interpretation of scores, see the Syllabus page.
Lab Exercises
- 2: All exercises attempted and turned in
- 1: Some exercises completed and turned in
- 0: No exercises completed or turned in
Program Compilation
- 4: Source code compiles with no errors or warnings
- 2: Source code compiles with warnings
- 0: Does not compile
Functionality
- 10: Demonstrates mastery of the assignment
- Has extra features or demonstrates techniques beyond the assignment
- Applies concepts from the lesson(s) appropriately
- Meets all specifications (see above) with particularly elegant solutions
- No errors encountered during operation
- 8: Has all the functionality expected of the assignment
- Demonstrates many techniques from the lesson
- Meets all specifications (see above)
- Implementation seems more complicated than necessary.
- May have one minor error
- 6: Has most of the functionality expected of the assignment
- Demonstrates some techniques from the lesson
- Meets all but one of the specifications (see above)
- Implementation seems excessively complicated.
- May have 2-3 minor errors
- 4: Has some of the functionality expected of the assignment
- Demonstrates some techniques from the lesson
- Meets at least 1/2 of the specifications (see above)
- Implementation seems excessively complicated.
- May have more than 3 minor errors
- 2: Serious functional problems but shows some effort and understanding
- Meets less than 1/2 of the of the specifications (see above)
- Has a major error or many minor errors
- Implementation seems very convoluted
- Demonstrates few techniques from the lesson
- 0: Does not execute or no specifications met
Programming Style
- 4: Code is well-documented
- Has your name, date, and program description in opening comment block
- Uses the specified class name
- Meets all requirements in How To Document and Organize Your Java Code covered to date
- Passes CheckStyle configured with the grade_checks.xml with no errors or warnings for those items covered to date
- 3: Code has a minor documentation error
- 2: Code has some documentation errors
- 1: Code has many documentation errors
- 0: No apparent attempt to document code
README.txt File
- 2: README.txt file submitted with specified information included
- 1: README.txt submitted but some information was not included
- 0: No README.txt submitted
Maximum Score: 22, plus extra credit
^ top
What to Turn In
Submit your assignment following the instructions for homework. Include the following items for grading:
README.txt file
exercises.txt
- Java source code file (possibly in a JAR file)
- Optionally, all the class files in addition to the source files in a single JAR file
You must submit all the files needed for your assignment to compile and work correctly. Do not assume that the instructors has any files. Also, do not turn in files that are not part of your assignment, especially ones that do not compile. Your assignment must compile after removing all the .class files and running: javac *.java. In addition, your code must work as submitted.
^ top
Home
| Blackboard
| Schedule
| Room Policies
| Syllabus
Help
| FAQ's
| HowTo's
| Links
Last Updated: March 21 2010 @13:16:23
|