COP2250 Assignment 3
Due Thrusday, 5/29 at 6 am.
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 5 and create four different main classes
in it; one for each part of the assignment.
-
Batting average main class
-
Area of polygons main class
-
Email splitting main class
-
Password testing main class
After you create the four main classes, your project will look something
like this:
Import each of your main classes into the Menu
class. This is
the class that is in the username
package of your assignment
project.
Assignment Menu
Implement a menu in the main method of the Menu
class.
-
Display a menu to the user, using a
JOptionPane
dialog.
-
The user will enter a number from 1 through 4. Depending on the number that
is entered, call the main method from one of the main classes that
you created in the chapter 5 package.
-
Use a switch statement to decipher the user input and call the appropriate
main method.
-
For example, if the user selects 1, then call
Batting.main(args);
-
If the user enters a number that is not in the menu, then print an
appropriate message and use
System.exit(0)
to end the
program.
Batting Average
For the main method in the Batting
main class, do the
following.
-
Use
JOptionPane
dialogs to read two integers from the user.
-
One integer will be the number of times the player was at the plate.
-
If the number of times at the plate is less than 0, then print an
appropriate message and use
System.exit(0)
to end the program.
-
One integer will be the number of hits that a baseball player had.
-
If the number of hits is less than 0, then print an appropriate message
and use
System.exit(0)
to end the program.
-
If the number of hits is greater than the number of times at the plate, then
print an appropriate message and use
System.exit(0)
to end
the program.
-
Calculate the average for the player as (total hits)/(total times at plate).
-
Use a
JOptionPane
dialog to display the players average to three
decimal places.
-
Use a
DecimalFormat
to limit the average to three decimal places
and always show three deciamal places.
-
For example, if the user has 100 hits in 300 plate appearances, then the
average will be .333
-
If the player has 90 hits in 300 times at the plate, then the average will
be .300.
-
Use a complete sentence that includes the number of hits and the number of
plate appearances.
-
If the average is greater than .300, then add a statement that the player
is elligible for the all-star game.
Polygon Area
For the main method in the Area
main class, do the following.
-
Calculate the area of a square that has a side of 0.666666667.
-
Use a
JOptionPane
dialog to display the area. Use a complete
sentence that includes the length of the side of the square.
-
Calculate the area of a rectangle with sides of 4 and 1/9.
-
Use a
JOptionPane
dialog to display the area. Use a complete
sentence that includes the length and the width of the rectangle.
-
Use a
JOptionPane
dialog to display the difference between the
two calculations.
-
Declare a constant threshold that can be used to test if two doubles are
equal.
-
Use an
if
statement and the threshold to test if the two areas
are equal. Display an appropriate message in a dialog.
Email Address
For the main method in the Email
main class, do the following.
-
Use a
JOptionPane
dialog to read an email address from the user.
-
If any of the following tests fail, then display an appropriate message and
use S
ystem.exit(0)
to end the program.
-
The string must contain an @ sign.
-
The string must not contain more than one @ sign.
-
The @ sign cannot be the first or last character in the string.
-
Use a
JOptionPane
dialog to display the user name and the domain
of the email address as separate
strings.
Password Test
For the main method in the Password
main class, do the following.
-
Use a JOptionPane to read a password from the user.
-
Use a JOptionPane to read the password again from the user.
-
Use a JOptionPane to display one of the following messages, based on the
values that the user entered.
-
The two passwords point to the same location in memory.
-
The two passwords contain the same value.
-
The two passwords are not equal.
-
When displaying the message, use a complete sentence that includes the two
passwords that the user entered.
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