Hi there guys. I am soon halfway through AP computer science, where we learn Java. Right, now, I'm doing some extra credit programs, both for fun, and to learn this stuff better. However, I got stuck on a few of them, and I really need some advise. I have already put a lot of effort into my programs.
Here is the first assignment:ยจ
http://www.howard.k12.md.us/rhhs/helloworld/LessonA12/Lab-A12-4.html
The logic here seems to be pretty simple, and my program is far on the way, and it does not return any errors. However, it just keep taking values, and it doesn't stop when it is supposed to.
import java.util.Scanner;
public class Grades {
Scanner in;
String grade;
String average;
int count = 0;
int total = 0;
Grades(){
in = new Scanner(System.in);
input();
}
public void input(){
String grade;
System.out.println("Enter grades, seperated by ENTER");
for(grade = in.next(); !(grade.equals("A" + "B" + "C" + "D" + "F")); count++){
if(grade.equals("A")){
total += 4.0;
}
else if (grade.equals("B")){
total += 3.0;
}
else if (grade.equals("C")){
total += 3.0;
}
else if (grade.equals("D")){
total += 3.0;
}
else if (grade.equals("F")){
total += 3.0;
boolean hasF = true;
}
else if (grade.equals("Q")){
break;
}
}
System.out.println("Total: " + total + " count: " + count);
}
}
Main:
public class GradesTester {
public static void main(String[] args) {
Grades app = new Grades();
}
}
I appreciate all help. Right now I would like to know how I can change this so that it stops taking values.
EDIT: Just realizing that this should have been in Computer science section. Sorry about that. Mods feel free to move thread.