COP2250 Assignment 5
Due Wednesday, 6/11 at 6 am.
If you did not do Assignment 3, then create a NetBeans project that will
contain all of your homework projects for the rest of the course:
Project for Assignments.
Create a package for chapter 7 and create one main class in it
Import each of your main class into the Menu
class. This is
the class that is in the username
package of your assignment
project.
Assignment Menu
Modify the menu in the main method of the Menu
class
(or create it if you did not do Assignments 3 and 4).
-
Display a menu to the user, using a
JOptionPane
dialog.
-
The choices from Assignments 3 and 4 should still be in the menu.
-
Add a new option for the program in this assignment.
-
The user will enter a number from 0 through 8. Depending on the number that
is entered, call the main method from one of the main classes that
you have created in the chapter 5 package and the chapter 6 package and the
new package.
-
The menu should work like it did in Assignment 4.
-
Modify the menu so that the user can enter either the number of the option
or a unique letter for each option. For instance, if the option in the menu
is named Email, then the user could enter 'E', 'e' or the number of the option.
-
In the option, put parenthesis aroung the special letter, like (E)mail.
-
Read the user's choice as a String, with a JOptionPane dialog.
-
Use the first character of the string to determine the option to run. Even
if the user enters a number, treat the first digit of the number as a single
character.
-
There will be three cases that will select each option; for instance, the
choices for email might be 'E', 'e' and '2'.
-
Do not exit the program when there is bad input: just display an appropriate
message and continue.
Circle Class
Write a class encapsulating the concept of a circle.
-
Place the class in the package for chapter 7.
-
A circle will have the following instance variables:
-
a Point, representing the center of the circle. Refer to the Java
API for information on the Point class.
-
a double, representing the radius of the circle
-
Create a default contstructor.
-
Create a constructor that has arguments of a Point and a double.
-
Create accessors and mutators for both instance variables.
-
Create a toString method.
-
Use the Point class's toString method to display the point.
-
Use a decimal format to display the radius to two decimal places.
-
Use English, too, so that I know what you have displayed.
-
Create an equals method.
-
Use the Point class's equals method to test if the points are
equal.
-
Use a threshold when comparing the radii.
-
Create a helper method that will calculate the area of the circle (PI * radius
* radius).
-
Create a helper method that will calculate the circumference of the circle
(2 * PI * radius).
Array Class
Write a class that will only have static class methods.
-
Place the class in the package for chapter 7.
-
Create a static method that has one argument and does not return anything.
-
The argument is an integer array.
-
Nothing is returned.
-
The method will print all the elements from the array.
-
Print all the elements on a single line.
-
Separate each number from the previous with a comma and a space. For instance:
12, -34, 75.
-
If the array is empty, then print a blank line.
-
If the array is null, then display an appropriate message.
-
Create a static method that has one argument and does not return anything.
-
The argument is a double array.
-
Nothing is returned.
-
The method will print all the elements from the array.
-
Print all the elements on a single line.
-
Separate each number from the previous with a comma and a space. For instance:
12.3, -34.5, 75.66.
-
If the array is empty, then print a blank line.
-
If the array is null, then display an appropriate message.
-
Create a static method that has one argument and does not return anything.
-
The argument is a character array.
-
Nothing is returned.
-
The method will print all the elements from the array.
-
Print all the characters on a single line.
-
Separate each character from the previous with a hyphen. For instance: H-e-l-l-o
-
If the array is empty, then print a blank line.
-
If the array is null, then display an appropriate message.
-
Create a static method that has one argument and returns a BigDecimal.
-
The argument is an integer array.
-
Return the product of all the elements of the array that have an odd index.
-
Use BigDecimal to calculate the product.
-
Return the product as a BigDecimal.
-
If the array is empty, null or only has one element, then return 0.
-
Create a static method that has one argument and returns a double.
-
The argument is a double array.
-
Return the difference between the largest and smallest elements in the array.
-
If the array is empty or null, then return 0.
-
Create a static method that has one argument and returns an array.
-
The argument is a string.
-
In the method, create a character array that has the same length as the string.
-
Place each character from the string into the corresponding position in the
character array.
-
Return the character array.
-
If the string is null, then return null.
-
If the string is empty, then return an array of length 0.
Class Client
Write a main method that will test each of the classes that you have created.
-
Test each method in each class.
-
Provide plenty of English in the output so that I can understand what is
being displayed.
-
When testing, if you make changes to a class, do a clean and build to be
sure that the class is recompiled.
-
Circle Class
-
Create an object using the default constructor.
-
Display the object.
-
Display the area of the object.
-
Create an object using the other constructor. Pass values to the constructor
that are not the same as the default values.
-
Display the object.
-
Display whether or not the two objects are equal (they should not be equal
now).
-
Set the radius of the first object to the radius of the second object.
-
Set the center of the first object to the center of the second object.
-
Display the first object.
-
Display the second object.
-
Display whether or not the two objects are equal (they should be equal now).
-
Display the area of one of the objects. Use a calculator to test if the answer
is correct.
-
Display the circumference of the object. Use a calculator to test if the
answer is correct.
-
Array Class
-
Create several arrays that will be used to test the methods.
-
An array of integers with at least 8 elements.
-
An array of integers with no elements.
-
A null array of integers.
-
An array of doubles with at least 8 elements.
-
An array of doubles with no elements.
-
A null array of doubles.
-
Test the method that prints the integer array.
-
Call the method with the integer array that has elements.
-
Call the method with the integer array that is empty.
-
Call the method with the integer array that is null.
-
Test the method that prints the double array.
-
Call the method with the double array that has elements.
-
Call the method with the double array that is empty.
-
Call the method with the double array that is null.
-
Test the method that calculates the product.
-
Call the method with the integer array that has elements. Display the result.
-
Call the method with the integer array that is empty. Display the result.
-
Call the method with the integer array that is null. Display the result.
-
Test the method that calculates the difference between the largest and smallest.
-
Call the method with the double array that has elements. Display the result.
-
Call the method with the double array that is empty. Display the result.
-
Call the method with the double array that is null. Display the result.
-
Test the method that converts a string into an array of characters.
-
Call the method with a string that has some letters in it. Display the returned
array of characters.
-
Call the method with a string that is empty. Display the returned array of
characters.
-
Call the method with a string that is null. Display the returned array of
characters.
Submit Homework
To hand in the assignment, upload the JAR file online:
Submitting
homework on-line via the Web.
-
Upload the file as binary.
-
Be sure that the JAR file contains the .java files. Check this page for more
information: Submitting JAR Files