Java Programming help
This program focuses on some basic elements of interactive programming as well as basic programming practices. Among the utilities learned in this assignment are the use of a Dialog Input and a Dialog Message box. This assignment also includes the use of efficient coding techniques for conditional statements, including single testing and a cascading structure. There is also information on avoiding redundant coding.
Before attempting this assignment, be sure you have completed all of the Module Readings, Java Trail Tutorials, and Videos listed for this week. There is always the resource of the DISCUSSION: Homework 2 thread that is available for you to ask questions, make comments, and read your fellow students’ issues and views.
Homework 2 (5 percent):
1. Create a Java Application Project named HW2[Last Name][First Initial] in the CMIS141 folder. As an example, if your name was Xavier Smith, then the project would be named HW2SmithX .
2. Review the requirements for the program (3 a. – 3 i.) then generate a test plan in a document named HW2SmithXTestPlan using the Test Plan Example document listed in Week 1 Activities as a guide.
3. Once you are in the IDE with the tabbed HW2SmithX.java in the Source window, begin developing the following program:
a. Declare identifiers for grade point and letter grade. The grade point can be either an integer or a double.
b. Display a table that relates the grade point set to a letter grade.
c. The following is the table of points to letters [Use the underline and the vertical line (|) – the uppercase symbol above the \ key – called a pipe to add the graphics. The output can all be left justified.]:
|
Letter Grade |
Points |
|
A |
100 - 94 |
|
A- |
93 - 88 |
|
B |
87 - 82 |
|
B- |
81 - 76 |
|
C |
75 - 70 |
|
C- |
69 – 64 |
|
D |
63 - 58 |
|
D- |
57 – 52 |
|
F |
51 - 0 |
Note : You can use a looping structure and arrays if you wish to generate the above table, but it is not necessary for this assignment since looping and arrays are not yet covered.
d. Using Dialog Input Box, prompt the user for a grade number. [It is assumed for this assignment that the user will not enter a zero, any negative numbers, or a number over 100; therefore do not create tests for these conditions.]
e. Using the value entered by the user, use a cascading conditional structure (See example on Page 4) with a single test (See example on Page 5) in each conditional statement to determine the appropriate letter grade. Review the information at the end of this assignment beginning with Example of Cascading Conditional Structure.
A single test means that within the condition, there is only one test, that is, there would be only
aNumber < 500
not the following that is three tests
aNumber > 0 && aNumber < 500
1 3 2
f. Display in a sentence (1) the grade point inputted and (2) the appropriate letter grade using a Message Dialog box. Be sure there is no redundant code .
g. When a user is reviewing the output of the program the order will be the table of grade points related to letter grades (Item 3. c.), then the input window, and finally the output window with the complete sentence.
h. End the program with a message indicating the end of the program and the purpose of the program.
i. Add the appropriate documentation to the program as suggested in the Documentation for Programs document listed in Week 1 Activities as a guide.
NOTE: Even though the table of letters and numbers is displayed first in the finished program, it is a good practice to first get the actual conditional element of the program to work correctly before working on the table that is only a graphic presentation.
4. When the assignment works correctly for all parts, capture images of the results – screen shots – for each of the test plan sets of data – the program will have to run for each of the sets – and paste each of them after the test plan prepared in Item 2. above into HW2SmithXTestPlan . The document contains the following: your test plan matrix followed by each of the screen shot sets of output. Each of the screen shot sets is tagged as Test Output 1, etc. or whatever term you prefer to use.
5. Once you complete the Homework 2 program attach the HW2SmithX.java and HW2SmithXTestPlan files to the appropriate location in LEO.
Design Rubric for Homework 2 (20 percent):
· The appropriate libraries are imported
· Declared all necessary identifier with an appropriate data type
· Used Input Dialog Boxes
· Used Message Dialog Boxes
· Displays required grade-point table
· Displays an appropriate prompt to accept a value that is either an integer or a double
· Displays the appropriate message for the grade that includes the points
· Displays the required final message
· The information in the message windows are graphically pleasing
Functionality Rubric for Homework 2 (40 percent):
· The declaration property use the correct data types
· Efficiently coded the grade table
· Grade table is graphically pleasing
· Coding to accept data appropriate
· The coding to display the output was appropriate
· Conditionals use single test
· The entire conditional structure is cascading
· There is no redundant coding
· The correct letters corresponded to the various grade points
· All requested elements of the program were implemented
Documentation Considerations for Homework 2 (20 percent):
[Refer to Documentation for Programs document in Week 1 Activities. Highlighted element is only required rubric implementation.]
· Each identifier uses word framing that clarifies the purpose in the program: documentable and user-friendly [interimBalance, beginningBalance, firstName]
· Uses inline documentation appropriately including explaining identifier declarations
· To help organize the segments of the programming code, there is tag after each of the closing } that ties in with the { that opens the segment [ } //ends the if count == 0]. These tags are especially important with conditionals, looping, methods, and functions
· Uses block documentation appropriately
· When using documentation for a segment of coding, there is an explanation of why that coding is used to achieve a specific goal. It is not just a description of the code, i.e., this is a conditional statement
· The appropriate data type is used with the identifiers
· The coding has spacing between lines of code that make it easier to identify various segments within the program
· The coding uses indentation to separate the various segments of the program in a vertical way
Test Plan Considerations for Homework 2 (20 percent):
[Refer to Test Plan Example document in Week 1 Activities.]
· There is a matrix holding various actions of the program, the input, the output, and normal and error messages
· There is at least one instance for each of the possible inputs into the program especially outside the acceptable input values
· There are examples of all the messages that can result from executing the program
· The selected data is comprehensive
Example of Cascading Conditional Structure:
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String aEvaluation = "Unacceptable";
System.out.println("Please enter an integer number:");
int aNumber = input.nextInt();
if (aNumber > 4)
aEvaluation = "Excellent ";
else if (aNumber > 3)
aEvaluation = "Above Average ";
else if (aNumber > 2)
aEvaluation = "Average ";
else if (aNumber > 1)
aEvaluation = "Below Average ";
System.out.println("Your evaluation is " + aEvaluation + "\n");
} //end main
Examples of redundant code:
Normally, programmers will do the following [Yellow highlight is redundant code.]:
if (aNumber > 4)
aEvaluation = "Excellent ";
System.out.println("Your evaluation is " + aEvaluation + "\n");
else if (aNumber > 3)
aEvaluation = "Above Average ";
System.out.println("Your evaluation is " + aEvaluation + "\n");
else if (aNumber > 2)
aEvaluation = "Average ";
System.out.println("Your evaluation is " + aEvaluation + "\n");
else if (aNumber > 1)
aEvaluation = "Below Average ";
System.out.println("Your evaluation is " + aEvaluation + "\n");
else
aEvaluation = "Unacceptable ";
or
if (aNumber > 4)
System.out.println("Your evaluation is Excellent\n");
else if (aNumber > 3)
System.out.println("Your evaluation is Above Average\n");
else if (aNumber > 2)
System.out.println("Your evaluation is Average\n");
else if (aNumber > 1)
System.out.println("Your evaluation is Below Average\n");
else
System.out.println("Your evaluation is Unacceptable\n");
In the example for cascading conditional structure above, note that the final alternative is used to initialize the identifier/variable. The cascading conditional structure above is the coding that is good coding.
Example of unnecessary tests of a conditional and redundant coding:
if (aNumber > 0 && aNumber < 2)
System.out.println("Your evaluation is Unacceptable\n");
if (aNumber > 1 && aNumber < 3)
System.out.println("Your evaluation is Below Average\n");
if (aNumber > 2 && aNumber < 4)
System.out.println("Your evaluation is Average\n");
if (aNumber > 3 && aNumber < 5)
System.out.println("Your evaluation is About Average\n");
if (aNumber > 4 && < aNumber < 6)
System.out.println("Your evaluation is Excellent\n");
Single conditional test accomplishes same result. See the cascading structure above.