Description of Project 3 Purpose:
In Project 3, we are going to learn how to useMethodsto make our code more effective and handle "separation of concerns". Think ofmethods like functions - each method handlesone specificproblem or task, but is able to be called/reused as many times as needed. The purpose of this project is to prompt the user for category weights (of his/her grade) and then asks the user to input his/her grades for each category. It will then it find the grade average of each category and use them to calculate the user's final grade average and letter grade.
We will break our code down into several methods that each haveone
specificpurpose. One to give an introduction, one to handle the homework grades, one to handle the test grades, one to handle the midterm grade, one to handle the final exam grade, one to calculate the final grade average, and one to find the letter grade associated with the given numerical grade. We will learn how to call a method andstoreitsreturn valueas well aspassthese return values to methods asparameters.Don't get too bogged down in the terminology. Think of methods as you would math functions - you put a value in and you get a value out. We store these values invariablesin math just as in Java.
For example:
f(x) = 3x + 2
x = 4
y = f(4) = 3(4) + 2 = 14
Think of 'x' like our parameter value. We "sent" it to f(x) andstoredthe result in 'y'. In Java,
String letter = getLetterGrade(gradeAverage);
In this case,gradeAverageis like 'x' - aparameterwe are sending to the methodgetLetterGrade. The method willreturna value will be store it in ourlettervariable, which is like 'y'.
Methods
The following are sample runs of the program to help you write your code and format your output:
Sample Output 1:
Welcome to the Grade Calculator!This program will input your homework, quizzes, tests,and final exam and calculate your average.How many homework grades to be entered?:4Grade 1:85.6Grade 2:92Grade 3:84.7Grade 4:94.3How many tests grades to be entered?:3Grade 1:88Grade 2:89.9Grade 3:97Please enter your midterm exam grade:88.6Please enter your final exam grade:92.1Your final grade is: 90.79Great job - You earned an A
----jGRASP: operation complete.
Sample Output 2:
Welcome to the Grade Calculator!This program will input your homework, quizzes, tests,and final exam and calculate your average.How many homework grades to be entered?:3Grade 1:78Grade 2:76.4Grade 3:73.8How many tests grades to be entered?:2Grade 1:86.2Grade 2:75Please enter your midterm exam grade:71.3Please enter your final exam grade:79Your final grade is: 77.58OK job - You earned a C
----jGRASP: operation complete.
Instructions Project 3:
- We will now be usingmethodsandforloops(no while here) to make our program more efficient and to learn how methods work in practice.
- Go to the following URL to complete the project:Project 3
- If using and IDE (jGrasp or Eclipse), create a new class file namedGradeCalculatorUsingMethods.java(optional)
- You will be filling in code everywhere you see the ellipses (. . .) in the Code Check code. Please follow the instructions and use the Sample Outputs to guide you.
- Write the Classcommentand@authorand@versiontags
- NOTE: When writing a Java Class with methods, it is usually best to write the methods first and then go back and complete the main method. We will be doing this for this project, so in Step 5 you will start writing the first method and continue from there.
- In thegiveIntro()method, add statements to output the welcome message (see Sample Output for formatting and message)
- In thegetHomeworkAvg()method:
- Complete the method comment and @tag
- Read in the number of homework grades and store in a variable (already completed).
- Create a variable to hold the sum of homework grades (already completed).
- Construct afor loopwith conditions that will read in the given number of homework grades.
- Inside the for loop, prompt the user to enter the grade (pay special attention to the Sample Output of "Grade1", "Grade2", etc.)
- Add the grade entry to the homework sum
- Outside the for loop, calculate the homework average.
- Return the average (already completed)
- In thegetTestAvg()method:
- Complete the method comment and @tag
- Read in the number of homework grades and store in a variable (already completed).
- Create a variable to hold the sum of test grades (done).
- Construct afor loopwith conditions that will read in the given number of test grades
- Inside the for loop, prompt the user to enter the grade (pay special attention to the Sample Output of "Grade1", "Grade2", etc.)
- Add the grade entry to the test sum
- Outside the for loop, calculate the test average.
- Returnthe test average.
- In thegetMidtermExamGrade()method:
- Complete the method comment and @tag
- Prompt the user to enter the midterm exam grade and store in an appropriate variable. *No loop needed.
- Returnthe midterm exam grade.
- In thegetFinalExamGrade()method:
- Complete the method comment and @tag
- Prompt the user to enter the final exam grade and store in an appropriate variable. *No loop needed.
- Returnthe final exam grade from the method.
- In thecalculateGradeAverage()method:
- Complete the method comment and all @tags (must use 1 @param foreachparameter - no grouping - and 1 @return tag)
- Create a variable and calculate the grade average using only parameter variables and constants (no magic numbers!)
- Returnthe grade average.
- In thegetLetterGrade()method:
- Use a series of if/else if/else statements to determine which String message should beassignedto theletterGradevariable (NOTE: We are not using print(ln) statements here! You will assign the entire String to the variable and then it will be returned as the last statement of the method).
- An 'A' should returnGreat job - You earned an A, a 'B' should returnGood job - You earned a B, a 'C' should returnOK job - You earned a C, a 'D' should returnOh no - You earned a D, and an 'F' should returnSorry - You earned an F.
- TheletterGradeis returned from the method.
- Now - go back to themain method:
- Call the method to introduce the application to the user.
- Call the 4 methods to obtain the averages and grades for homework, tests, midterm, and final exam andstorethe returned values in 4 appropriate variables.*I have completed the call to the homework method for you.
- Call thecalculateGradeAverage()method andpassthe 4 variables you created in Step 12.2 (above) as parameters for homework, tests, midterm, and final exam to the method. Make sure andstorethe returned value in an appropriate variable.
- Use aprintfstatement to output the grade average to 2 decimal places.
- Call thegetLetterGrade()method andpassthe grade average to the method (NOTE: we are going to "nest" this method call inside ourprintlnstatement to understand the different ways we can call a method and get the return value. Basically, if we only want to output the return value and not "store" it, we can "nest" the method call inside a print(ln) statement).
- Submit your code and check the tests and correct any error messages or output formatting issues.
- Once you have everything correct, download thezipped fileand then upload to this Assignment folder.
Testing and Submitting
Once you have thoroughly tested your program, pleaseuploadthezipped fileonlyto thisProgramming Project 3folder.
You will be graded on:
- Neatness of code and use of proper indentation of 4 spaces, 8 spaces, etc. This is theCheckstylepart of yourReport.
- Commenting of code - including class comment, @author, @version, and code comments.This is theCheckstylepart of yourReport.
- Good use of constant and variablenames- they should bedescriptivenames and not individual characters or abbreviations. Ex. FINAL_COST or firstName.This is theCheckstylepart of yourReport.
- Output is correct and matches the Sample Output forall teststhat executed on your code in Code Check.This is theTest 1, Test 2, etc.part of yourReport.They must say "Pass".
- Correct calculations using variables and constants (i.e. the math is correct). This is theTest 1, Test 2, etc.part of yourReport.
- My visual inspection of your code. I will be checking for good variable and constant names and well as good indenting of code. Instructor reserves the right to make adjustments to the Code Check score based on inspection.
ALL DONE!! Great job!