Hello everyone hope all is well. So I'm learning java and been at it all night and this is my last hope. I can't figure out why a certain part of my code is not being executed after the conditions of my if statement is true.
/**
* @(#)mathsoftware.java
*
*
* @author
* @version 1.00 2010/7/1
*/
import java.util.Scanner; //input stuff
public class mathsoftware {
/**
* Creates a new instance of <code>mathsoftware</code>.
*/
public mathsoftware() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner mygrade = new Scanner(System.in); //input
System.out.println("How many courses have you taken?");
int coursecount = mygrade.nextInt(); // number of courses taken
if (coursecount < 2) { // in number of courses less than 2
System.out.println("Cannot Compute need at least 2 classes");
} else if (coursecount == 2) { // if courses equal 2
System.out.println("What is the grade of your first class?");
String grade001 = mygrade.next();
double gradenum001;
if (grade001 == "A") {
gradenum001 = 4.00;
} else if (grade001 == "B"){
gradenum001 = 3.00;
} else if (grade001 == "C"){
gradenum001 = 2.00;
} else if (grade001 == "D"){
gradenum001 = 1.00;
} else {
gradenum001 = 0.00;
}
System.out.println("What is the grade of your next class?");
String grade002 = mygrade.next();
double gradenum002 = 0;
if (grade002 == "A") {
gradenum002 = 4.00;
} else if (grade002 == "B"){
gradenum002 = 3.00;
} else if (grade002 == "C") {
gradenum002 = 2.00;
} else if (grade002 == "D") {
gradenum002 = 1.00;
} else {
gradenum002 = 0.00;
}
double printedg;
printedg = gradenum001 + gradenum002 / 2;
System.out.println(printedg);
} else {
System.out.println("tested");
}
}
}
in the snippet
if (grade001 == "A") {
gradenum001 = 4.00;
} else if (grade001 == "B"){
gradenum001 = 3.00;
} else if (grade001 == "C"){
gradenum001 = 2.00;
} else if (grade001 == "D"){
gradenum001 = 1.00;
} else {
gradenum001 = 0.00;
}
the code is not running at all and I get the value of 0.0
Sorry I know my code is horrible but I am learning just stuck. Everything compiles without errors. I found out it was this section because I inserted a println and some text in the if statement that should have placed a 4.00 value to gradenum001 variable. Thank you for your help.