Outcomes
▪ Write programs that use object oriented programming concepts.
▪ Write programs that use objects.
Scoring
▪ If you do not submit a .zip file containing your source code, your score will be
zero.
▪ If you submit source code that does not compile, your score will be zero.
▪ If you submit source code without the correct class name(s) or the correct
method names (see below), your score will be decreased by 50 points.
▪ In addition, deductions will be made for not meeting the following
requirements:
o At the beginning of each java file, add a comment with the following information:
▪ Student’s name
▪ Course/section,
▪ Date
▪ Filename
▪ Description of the program/class o Indentation guidelines:
▪ The code inside of a class must be indented with respect to the class
definition.
▪ The code inside of a method must be indented with respect to the method
definition.
▪ The code inside of if / else / else if / while / for / do-while structures must be
indented with respect to its corresponding structure.
▪ Curly braces can be positioned at the end of the corresponding structure
definition, or in the following lines aligned with the corresponding structure. o
Comments:
▪ At least, one-line comment should be added per method or constructor.
▪ Comments must describe the functionality or objective of the method.
▪ Please add more comments about your code, if you think that will help the
grader.
Rubric
Full credit Partial credit
Implement and test class
Circle
(30 points)
You implements the class Circle and
your
code obtains the correct
output with the provided test class.
You implements the
class Circle and your
code obtains the correct
output with the
provided test class, but
with some errors.
Implement the class Bug
(15 points)
You implements the class Bug. You implements the
class Bug, but with some
errors.
Implement the class BugTest
(15 points)
You implements the class BugTest. You implements the
class BugTest, but with
some errors.
Implement the class
ComboLock
(15 points)
You implements the class
ComboLock.
You implements the
class ComboLock, but
with some errors.
Implement the class
ComboLockTest
(15 points)
You implements the class
ComboLockTest.
You implements the
class ComboLockTest,
but with some errors.
Make sure the user does not
enter bad values
(10 points)
You make sure the user only
enters a valid menu options and
values.
You check for bad user
entry, but with some
errors.
Description
For this assignment, you will build three applications: CircleSolution, BugSolution, and
ComboLockSolution.
CircleSolution
1. Create a folder named CircleSolution to store the classes for this application.
2. Create the class Circle.
Circle
radius: double
circumference: double area:
double
calculateCircumference():void
calculateArea():void
3. All the data fields are private.
4. calculateCircumference and calculateArea are private methods.
5. Create a no-argument constructor for the class.
public Circle() {
}
6. Add another constructor which receives a double value to initialize the radius of the object (if
the double value is a negative value, the value of zero will be assigned to this.radius) and calls
the methods calculateCircumference and calculateArea.
7. Create a setter and a getter for the data field radius.
8. The setter for radius will check if the received double value is greater than or equal to zero. If it
is, the radius will be updated, and circumference and area will be recalculated by calling the
corresponding methods. Otherwise, the value of radius will not be updated.
9. circumference and area will be read-only members. Therefore, only create a getter for
circumference and another for area.
10. Complete the method calculateCircumference.
11. Complete the method calculateArea.
12. Download the file CircleTest.java and add it to the folder CircleSolution.
13. Compile and execute it.
14. The class Circle have to interact with CircleTest to provide the expected output.
BugSolution
1. Create a folder named BugSolution to store the classes for this application.
2. Implement the class Bug described in the programming exercise P8.12 in your book.
3. All the data fields of the class Bug are private.
4. The methods described in the programming exercise are public.
5. In addition, create a getter to obtain the current direction of the bug.
6. Other private methods can be created, if needed.
7. Create an application named BugTest, which will have the following behavior.
a. It starts by showing the application name and asking the user for the initial position of
the bug. The text in red represents the user input.
== Bug Solution ==
Enter the initial position of the bug: 7
b. The application creates an object Bug with the user input as the initial position, and sets
the direction to the right.
c. Then, it
presents the
status of the
bug: current
position and
direction:
Position: 7 Direction: right d.
Also, it presents a menu with three options.
– Menu –
Name Radius Circumference Area
Circle 1 5.00
31.42 78.54
Circle 2 11.00 69.12 380.13
Circle 3 19.00 119.38 1134.11
1. Change
direction.
2. Move.
3. Exit.
Enter your choice: 1
e. If the user chooses option 1, the direction is changed.
f. If the user chooses option 2, the bug changes its position by one unit in the current
direction.
g. After option 1 or option 2 are chosen, the status of the bug and the menu is presented
again.
h. If the user chooses option 3, the program ends.
Sample run
== Bug Solution ==
Enter the initial position for the bug: 7
Position: 7 Direction: right
– Menu –
1. Change direction.
2. Move.
3. Exit.
Enter your choice: 2
Position: 8 Direction: right
– Menu –
1. Change direction.
2. Move.
3. Exit.
Enter your choice: 2
Position: 9 Direction: right
– Menu –
1. Change direction.
2. Move.
3. Exit.
Enter your choice: 4
*** Invalid option!
Position: 9 Direction: right
– Menu –
1. Change direction.
2. Move.
3. Exit.
Enter your choice: 1
Position: 9 Direction: left
– Menu –
1. Change direction.
2. Move.
3. Exit.
Enter your choice: 2
Position: 8 Direction: left
– Menu –
1. Change direction.
2. Move.
3. Exit.
Enter your choice: 3
ComboLockSolution
1. Create a folder named ComboLockSolution to store the classes for this application.
2. Implement the class ComboLock described in programming exercise P8.9 in your book.
3. All the data fields of the class ComboLock are private.
4. The methods described in the programming exercise are public.
5. Other private methods can be created, if needed.
6. Create an application named ComboLockTest, which will have the following behavior.
a. In the main method, create an object ComboLock with a hard-coded combination.
b. The program shows the application name and menu. The text in red represents the user
input.
== ComboLock Solution ==
– Menu –
1. Open Lock.
2. Exit.
Enter your choice: 1
c. If the user chooses option 1,
i. Ask the user for the first number, then call turnRight with the provided
number.
ii. Ask the user for the second number, then call turnLeft with the provided
number. iii. Ask the user for the third number, then call turnRight with the
provided number.
iv. Call the method open, and show whether the user could open the lock.
v. Finally, return to the menu.
d. If user chooses option 2, the program ends.
Sample run
== ComboLock Solution ==
– Menu –
1. Open Lock.
2. Exit.
Enter your choice: 1
Enter the first number: 10
Turning to the right.
Enter the second number:
50
*** Invalid value!
Enter the second number: 22
Turning to the left.
Enter the third number: 7
Turning to the right.
The combination is incorrect. The lock is closed.
– Menu –
1. Open Lock.
2. Exit.
Enter your choice: 1
Enter the first number: 11
Turning to the right.
Enter the second number: 9
Turning to the left.
Enter the third number: 7
Turning to the right.
The combination is correct. The lock is open.
– Menu –
1. Open Lock.
2. Exit.
Enter your choice: 3
*** Invalid option!
– Menu –
1. Open Lock.
2. Exit.
Enter your choice: 2
Other requirements
▪ For the ComboLock solution, the program needs to validate the option selection in the menu
and the values of each number of the combination.
▪ For the BugSolution, the program needs to validate the option selection in the menu.
▪ Compress the application folders into a zip file named Homework02.zip and submit it to the
corresponding assignment in Canvas.