LAB EXERCISE 8: Test Score Average
In this exercise, you will learn how to:
1. Insert the Main Method (Main Entry Point to the Java Program)
2 Import a Java Class Library
3. Declare Variables
4. Create a Constructor (Special Method)
5. Create a Method and accept arguments
6. Create an Object from the Class
7. Use an If-Then-Else statement
8. User Relational operators to test a condition and execute code.
8. Call a Method and pass arguments
Create an application that allows the user to enter 3 test scores of a student. The application should be able to calculate and display the average test score. Then display the message “Student Passed” if the student’s average test score is greater than or equal to 70. If the student’s average test score is less than 70, then display the message “Student Failed”.
1. Create a folder on your desktop Exercise-8
2. Launch Java EE- Eclipse
Note: You will need to use the Java Perspective Workbench for this exercise
3. Setup your Eclipse Workspace to point to the Exercise-8
a. Select File-> Switch Workspace
b. Browse and select your Exercie-8 folder as your Workspace.
1. Create a Java Project and name it as TestAverage
2. Create the first Class that will have the Main Method
a. Name the Class as MainApp
b. Choose the main method to insert into the class
3. Create the second Class that will have the Constructor and Methods
a. Name the Class as Test
b. Do not select the main method stub
C. Requirements for the TestAverage Class:
1. Insert the import java.util.Scanner class which will allow data to be inputted from the console.
Declare the variables- test1, test2, test3 and testAverage using the double
b. Declare the variable message using the String data type
3. Create the Constructor called Test that will prompt the user to input the data
a. Declare the scanner input class objects
b. Prompt the user to input the data.
c. Assign the inputted data to the variable
the scanner input class object
Below is the code you can copy and paste
declare the scanner object used to input the student's test score 1 from the
declare the scanner object used to input the student's test score 2 from the
declare the scanner object used to input the student's test score 3 from the
close scanner input objects
4. Create the Method called calcTestAverage with a return data type of double
a. This method should accept the argument parameters (double t1, double t2, double t3)
b. Insert the formula testAverage = (t1 + t2 + t3)/3; ;
c. Insert return testAverage
5. Create a Method called displayMessage with a return data type of String.
a. This method should accept the argument parameters (double testAverage)
b. Use an if-then-else statement
to test the condition, execute the code and return the result
NOTE: if testAverage >= 70 then display “Student Passed” else “Student Failed”
D. Requirements for the MainApp Class:
comments (documentation)– Program Description, Author and Date
the instance of object called student from the Test class
Declare score1 variable
as double and assign the value from the student.test1 object’s
b. Declare score2 variable as double and assign the value from the student.test2 object’s variable
c. Declare score3 variable as double and assign the value from the student.test3 object’s variable
the avgTest variable
as double and assign the return value from the called method- student.calcTestAverage(score1,
Pass the score values as arguments.
5. Call the object's method - student.displayMessage(avgTest). Pass the avgTest value as an argument
6. Display the returned results. Below is the code you can copy and paste.
display the returned results on the console
1. Save your Java code
2. Compile and run your Java program.
3. Verify there is no syntax, logical or run-time errors.
4. Use the following set of test data to determine if the application is calculating properly:
Score 1 Score 2 Score 3 Avg Score Displayed Message
95 89 66 83.33 Student Passed
79 60 55 64.67 Student Failed
F. Submit your exercise in the Canvas Lab Exercise #8 Drop Box.
1. Submit the screen shot of the Eclipse
Workbench window showing the Console output screen.
You can use Paint (save as JPG) or Word to paste the screenshot.
2. Zip up and submit the compressed TestAverage subfolder that is in the Exercise-08
NOTE: Right click on the subfolder and select Send to “Compress Folder”. The file will have a file extension of .zip.