Create a command-line application named GradePointAverage that calculates the grade-point average of the letter grades represented by a string
that the user supplies as a command-line argument.
Probably the easiest way to begin this exercise is to start with your GradePoints program. Your solution to this exercise will use the static method
gradePoints()
that you created previously.
Additionally, you will need to create another static method
gradePointAverage()
that accepts a
String
reference as parameter. The characters contained in this
String
object will represent a collection of letter grades.
The
gradePointAverage()
method should return a
double
which represents the grade-point average (GPA) of the letter grades. For example, after the following code executes, the variable
result
contains 3.25:
double result = gradePointAverage("ABAC");
In your
gradePointAverage()
method you will need to loop through the characters contained in the
String
object. There are two methods provided by the
String
class that you will find useful. The method
length()
returns the number of characters contained in a
String
. The method
charAt(int)
returns the
char
at the specified index.
The indexes for the chars contained in a
String
object begin with 0. Here's an example of some code that uses both of these methods:
In the text box below, cut and paste the source code for the GradePointAverage application.
Click the Submit button to submit your code.