On This Page
Overview
The main points of this assignment are to:
- Design classes for a program
- Create an object-oriented design for a program
- Use more than one Java class in a application
^ top
Lab Exercises
In these exercises you explore classes and objects.
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 1 on page 174 of your textbook.
- Complete self-test exercises 3 on page 180 of your textbook.
- Complete self-test exercises 5 and 6 on page 190 of your textbook.
- Complete self-test exercises 10 and 11 on page 193 of your textbook.
- Complete self-test exercises 13 on page 200 of your textbook.
- Complete self-test exercises 20, 21, and 22 on page 219 of your textbook.<
- Complete self-test exercises 24 and 26 on pages 230 and 231 of your textbook.
- When finished, do not forget to upload your file to Blackboard as part of this assignment
^ top
Project Specifications
Write an object-oriented 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:
- Define two
public shape classes, one for a rectangle and one for a triangle.
- Each class must be in its own separate file.
- For each shape class, code at least one constructor.
- Also, for each shape class, code the following methods using the exact header shown:
public void draw(): draws the shape on the console
public String toString(): returns a string describing the shape
- In addition, define another class named
ShapeTester with a main() method that runs the application.
- 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),
ShapeTester must prompt for the width and the height (in that order), instantiate a rectangle object and then call its toString() and draw() methods to display a labeled rectangle like the one shown in the Example Operation.
- If the user enters a T (for triangle),
ShapeTester must prompt for the width only, instantiate a triangle object and then call its toString() and draw() methods to display a labeled 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 and the Scanner must be declared only in the ShapeTester class.
- 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 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: 7 x 3
* * * * * * *
* *
* * * * * * *
Choose a figure to draw:
R: rectangle
T: triangle
Q: quit
Choice: t
Triangle width: 4
Triangle: 4
*
* *
* *
* * * *
Choose a figure to draw:
R: rectangle
T: triangle
Q: quit
Choice: q
Goodbye
Also, you can download and run the asn04demo.jar file. Note that you cannot double-click the JAR file and must run the demo from the command line:
java -jar asn04demo.jar
Also note that the JAR file may contain some extra credit features.
^ top
Extra Credit
Completing the following are worth extra credit points:
- Add another class to draw a diamond and change the program to allow a user to enter a D (for diamond) in addition to R, T or Q. If the user does, 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 asn04.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
Program Style
- 4: Code is well-documented
- 3: Code has minor documentation errors
- Has 1 documentation error
- 2: Code has some documentation errors
- Has 2-3 documentation errors
- 1: Code has many documentation errors
- Has more than 3 documentation errors
- 0: No apparent attempt to document code
REAME.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 the same 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:24
|