| Project #1 | CMSC 131 |
| Due: Monday February 18 at 11:00 pm | Object-Oriented Programming I |
| Type of project: Open | Spring 2008 |
Interactive Polygon Quiz
![]() |
![]() |
![]() |
![]() |
| triangle | square | pentagon | octagon |
Objective
This project will allow you to practice variables, strings, input/output facilities, conditional statements, logical operators, and the Eclipse IDE.
Overview
You will write a very simple application that can be used to quiz a child that is learning the names of the regular polygons. The child can choose which way the quiz goes - from the number of sides do they know the name of the regular polygon that has that number of sides or from the name do they know the number of sides it must have.
This project is considered "open". Please visit the course web page for information regarding the open/closed policy for projects of this course.
Specifications
Your program knows four things: The name of a 3 sided polygon is a triangle, a 4 sided regular polygon is a square, a 5 sided polygon is a pentagon and a 8 sided polygon is an octagon. It knows these words in their lowercase forms (no uppercase characters should be used for any input in this project).
The program begins by prompting the user with:
Type 1 to first enter the name of a regular polygon, 2 to enter a count of the sides:
The user should then enter either "1" or "2". If the user enters a different integer value at that time, the quiz terminates immediately with the message:
Invalid choice!
Processing an Entry of "1"
The program prompts the user with:
Type the name of a regular polygon:
The user should at this point enter triangle, square, pentagon, or octagon. [note: spelled correctly and without any capitalization] If any other sequence of characters is typed, the program will terminate immediately with the message:
Invalid choice!
Assuming that the user has entered one of the valid names, the program prompts the user with:
How many sides does a xxx have?
[In the prompt above, the "xxx" must actually be replaced by the polygon name that was typed by the user at the previous prompt.]
The user will then enter their guess for the number of sides. If the value entered represents the correct number of sides for this polygon, the program will output "Correct!" and terminate. But if the user has entered the wrong value, then the program will output "Incorrect!" and terminate.
Processing an Entry of "2"
The program prompts the user with:
Type a count of the number of sides:
The user should at this point enter a 3, 4, 5 or 8. If any other number is entered, the program will terminate immediately with the message:
Invalid choice!
Assuming that the user has entered one of the valid numbers, the program prompts the user with:
Which regular polygon has n sides?
[In the prompt above, the "n" must actually be replaced by the number that was typed by the user at the previous prompt.]
The user will then enter their guess for the name of the polygon with that number of sides. If the string entered represents the correct name for this polygon, the program will output "Correct!" and terminate. The name of the regular polygon with that number of sides must be spelled correctly and without any capitalization. But if the user has entered the wrong name, then the program will output "Incorrect!" and terminate.
Getting Started
In order to help you get started, we have defined an PolygonQuiz class with a main( ) method in a file named PolygonQuiz.java. This file can be retrieved by checking out the project called Spring08Proj1 from the CVS repository. Remember that you must have set up your repository in order to check out and submit projects. (Refer to Project #0 for more specific instructions.) After checking out the project, switch over to Java perspective to open the source-code file and begin working on it.
If you write the project from scratch, without checking out the "Spring08Proj1" files from your CVS repository, you will not be able to submit your work.
Requirements
The following examples show how your program should behave. Note that items in italics represent the things that are entered by the user. Keep in mind these are just examples and not the only scenarios that your program is expected to handle.
Example 1:
Type 1 to first enter the name of
a regular polygon, 2 to enter a count of the sides: 5
Invalid choice!
Example 2:
Type 1 to first enter the name of a regular polygon, 2 to enter a count of the sides: 1
Type the name of a regular polygon: Rectangle
Invalid choice!
Example 3:
Type 1 to first enter the name of
a regular polygon, 2 to enter a count of the sides: 1
Type the name of a regular polygon: octagon
How many sides does a octagon have? 7
Incorrect!
Example 4:
Type 1 to first enter the name of
a regular polygon, 2 to enter a count of the sides: 1
Type the name of a regular polygon: square
How many sides does a square have? 4
Correct!
Example 5:
Type 1 to first enter the name of
a regular polygon, 2 to enter a count of the sides: 2
Type a count of the number of sides: 4
Which regular polygon has 4 sides? triangle
Incorrect!
Example 6:
Type 1 to first enter the name of
a regular polygon, 2 to enter a count of the sides: 2
Type a count of the number of sides: 5
Which regular polygon has 5 sides? pentagon
Correct!
Submission
Submit your project from Eclipse by right-clicking the project folder and selecting "submit". You may submit as many times as you want -- we we only grade your most recent submission. After you have submitted your project, you should visit the submit server. There you can obtain limited feedback about how well your project is performing. The number of times you can run our tests on your project (before the due date) is limited. The earlier you begin working on the project, the more opportunities you will have to see how your project performs on our tests before the due date!
Grading
There are seven release tests which will be run on your project. Together, these tests will dictate 90% of the grade on the project. The remaining 10% will be based on your use of correct programming style.