CSC 120 Programming Assignment 4
Note: You should not work on this assignment during lecture or lab class-time unless:
- You have completed all of the in-class assigned work for the day, and
- You have permission from the instructor.
This assignment must be handed in to the PA4 dropbox in D2L before
the due date/time.
Overview:
Using the class definition you developed for Programming Assignment # 2, create a Java
application that provides a Graphical User Interface that allows the user to enter
data values in TextFields for each property of the class, uses those values to instantiate
an object from your class, and displays the results of the toString()
method of your class in a TextArea as described
in these instructions.
Instructions:
- Initial Set-up.
- Create a NetBeans Java Application named PA4 in your network space.
It should contain the class named MUFrame from the starter template we've used
previously. Start with the files named MUFrame.form and MUFrame.java stored
in the MUFrameWithGUIDesigner.zip file
that is available in the "Starter Templates" section of the CSC 120 Student Resources page of the
course web site. You won't need to use the
MUPanel.java file for this assignment.
- Copy the .java file for the class you wrote for PA # 2 into the src folder of the PA4 project.
- Open the MUFrame.java file in the NetBeans editor, switch to "Source" view, and delete the three lines that refer
to an object named
muPanel
. After doing this, you should be able to
run the MUFrame.java without errors an obtain a blank output screen.
- Ensure that your class from PA2 has all required parts.
- Your class must have at least 4 properties, at least 2 of which are a numeric type (either Integer or Double).
The class must have a constructor method that stores initial values in the properties of
the object. The class must have a "getter" method for each property, and the class must have
a
toString
method that returns a String that shows all the property values.
- If your class doesn't satisfy all these requirements, fix it so that it does satisfy the requirements.
Failing to do this will result in point deductions for PA4.
- Create your User Interface.
- Switch to "Design" view for the MUFrame.java file in NetBeans, and create a User
Interface for your program that
has a TextField for each of the properties in the class you wrote for PA # 2. Each
of the fields should be preceded by a Label that describes what the user should enter
into each field.
- Add two Buttons to the interface that will allow the user to click and display results
as described later in these instructions.
- Add a TextArea to the interface. This will be used for program output display.
- Be sure to "Edit Text" for each of the TextFields so that they are blank to start with,
and "Edit Text" for each of the Labels so that they display
appropriate messages to the user indicating what should be entered into each of
the TextFields. Also, "Edit Text" on the Buttons so that one of them displays a message
saying "Process Form Data" or something like that, and the other Button's message should
be something like "Display Numeric Statistics".
- Also be sure to "Change Variable Name" for all of the TextFields, the Buttons and the
TextArea so that they use names that are meaningful to your program topic.
As an example, if your class has properties
named
albumName
and tracksOnCD
, then your should name
your TextFields albumNameField
and tracksOnCDField
.
- Code the actionPerformed method for the "Process Form Data" Button.
- Double-click on the Button that will process the form data in your User Interface
to make NetBeans insert an
actionPerformed method into the MUFrame class.
- When the user clicks on this Button, your application should do the following in this order:
- retrieve all data from the TextFields into String objects
- for each of the data items that represents a numeric value, you will need to convert the input String into an Integer or a Double data type for use in the next step
- declare an object from your class
- instantiate the object from your class that you just declared, using the values from the first two steps
-
append
the results of the toString
method called for the new object in the TextArea of the User Interface
- call the "getter" method of the new object for one of the numeric properties in your class, and add the value retrieved
to a "total" variable of the proper data type.
- compare the value retrieved in the previous step with a maximum and a minimum
variable of the proper type. If the value retrieved from the "getter" method is
larger than the maximum variable, it should be stored as the new value of the maximum
variable. If the value retrieved from the "getter" is smaller than the minimum variable,
it should be stored as the new minimum.
- add one to a "count" variable that will keep track of how many times the "Process Form Data" button has been
clicked. This will be needed to calculate the average value described below.
- The messages appended to the TextArea should be displayed on separate lines, with a blank line
between the output generated by successive button clicks.
- Of course your program will have to use
Integer.parseInt
and/or
Double.parseDouble
to convert the String
data from the TextFields for
the numeric properties of your object into the proper numeric type before instantiating your
object.
- Code the actionPerformed method for the "Display Numeric Statistics" Button.
- Double-click on the other Button in your Interface
to make NetBeans insert another
actionPerformed method into the MUFrame class.
- When the user clicks on this Button, your application should calculate the average value of the numeric field
you've chosen to use, and then display the total, average,
minimum and maximum values that the user has entered for the numeric field.
- The average must be displayed with decimal places, even if the field you are averaging is an Integer field. The average
must be computed as a Double value, and show the exact average, not truncated to an Integer value.
- Display a blank line
between the output generated by successive button clicks.
- Optional: Keep track of statistics for two or more properties of your class, if you would like.
- If it makes sense for your topic, you can separately keep track of the "total", "minimum" and
"maximum" for each
of your class' numeric properties. Just be sure not to mix them up.
- When the user clicks on the Button that displays the statistics, be sure to clearly
indicate in the output which property's statistics are being displayed on each line.
Example of Program Behavior:
Turning in your Program for Grading:
Convert your
CSC120\Java\PA4 folder into a .zip file named PA4.zip
and submit it to the PA4 dropbox
in D2L.
Note: It is expected that each student will complete this
assignment INDIVIDUALLY.
Grading Rubric:
PA4 Grading Rubric