Java - Loop

I add this part to the code.
int i;
   for (i = 1; i <=10; i++)
but it is not doing what I need.  
I just repeats the answer 10 times.  

How do you determine the numeric grade for one single letter grade, it repeatedly calculates and displays numeric grades for a sequence of exactly 10 grades?

Any help would greatly be appreciated.

package charatmethod;
import java.util.Scanner;
 
public class CharAtMethod
{
 
public static void main(String[] args) 
{
Scanner in = new Scanner(System.in);
 
System.out.println("Enter a letter grade:");
String input = in.nextLine();
 
Grade g = new Grade(input);
 
double grade = g.getNumericGrade();
 
int i;
   for (i = 1; i <=10; i++)
System.out.println("Numeric value: " + grade);
}
 
}
************************************
package charatmethod;
public class Grade
{
    public Grade(String initGrade)
    {
        letterGrade = initGrade;
    }
public double getNumericGrade()
{
    double grade = 0;
switch(letterGrade.charAt(0)) 
{
case 'A': grade = 4.0;break;
case 'B': grade = 3.0; break;
case 'C': grade = 2.0; break;
case 'D': grade = 1.0; break;
default: grade = 0.0; break;
 
}
 
for (int i = 0; i < letterGrade.length(); i++)
{
   if (letterGrade.charAt(i) == '-')   
       grade = grade - 0.3;
     else if (letterGrade.charAt(i) == '+')
        grade = grade + 0.3;
}
    return grade;
            
}  
    private String letterGrade;
}

Open in new window

ca1358Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

marklorenzCommented:
I'm not totally sure what you're trying to do.  If you take out the for loop in your main method, you will ask for one letter grade and output the related numeric grade.  If you want a loop, it would have to encompass the part where you ask for a grade.  You'd probably want to go until nothing is entered, to indicate it's done (versus a for loop).
ca1358Author Commented:
I am not sure what it asking.

It states
Alter the main class of the project so that, instead of just determining the numeric grade for one single letter grade, it repeatedly calculates and displays numeric grades for a sequence of exactly 10 grades.  

You should add a loop to the main method that will ensure that the process of "retrieve letter grade, then calculate and display the numeric grade, will be repeated 10 times.

Of course it gives no explanation of how to do this.
quincydudeCommented:
do you actually want something like
public static void main(String[] args) 
{
Scanner in = new Scanner(System.in);
String input;
Grade g;
double grade;
 
 
int i;
   for (i = 1; i <=10; i++)
	{
	   System.out.println("Enter a letter grade:");
		input = in.nextLine();
		g = new Grade(input);
		grade = g.getNumericGrade();
		System.out.println("Numeric value: " + grade);
	}
}

Open in new window

Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Kevin CrossChief Technology OfficerCommented:
Think you want something more like this so that you keep prompting for letter grade and displaying for 10 times and then stops.
public class CharAtMethod {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
 
        Grade g;
        double grade;
        
        for (int i = 1; i <= 10; i++) {
            System.out.println("Enter a letter grade:");
            g = new Grade(in.nextLine());
            grade = g.getNumericGrade();
            System.out.println("Numeric value: " + grade);
        }
    }
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kevin CrossChief Technology OfficerCommented:
That is what I get for not refreshing, what quincydude is pretty much what I was trying to show you.  You just needed to move the code for input and conversion from letter grade to inside the for loop.

This is just hte basics of the solution and should get you started.  You will have to ensure that you get valid input each time if they want 10 good executions.  Other interpretation/implementation could be to allow entry of 10 grades in a row and then calculate and display all ten at once.  Again that is all based on the above code as a start so good luck.

Regards,
Kevin
ca1358Author Commented:
Thanks!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.