ok im having difficulty making this method work correctly. this is just a test to determine why its not doing my calculation right. in this class i have an incomeing string and int from another class called smester. its supposed to chekc wheather the string is "A" or not. and to return a calculation if it is true. but all i get is 1.0 cause of my else statment. so the method is not reading my incoming string right i think, not sure.
does anyone in this forum know?
thnks
keke
(both classes are listed below
public class Courses
{
private int numCredits;
private String grade;
public void setGrade(String g)
{
grade = g;
}
public void setCredits(int c)
{
numCredits = c;
}
public double calcQualityPoints()
{
double points;
double qualPoints;
if(grade=="A")
{
points = 4.0;
qualPoints = numCredits * points;
return qualPoints;
}
else
{
return 1;
}
}
}
////////////////////////////////////////////////////////////////////
semester class
///////////////////////////////////////////////////////////////////
import javax.swing.JOptionPane;
public class Semester{
public static void main(String[] args){
int count = 1;
int courses = Integer.parseInt(JOptionPane.showInputDialog("How many courses did you take htis semester"));
while(count<=courses)
{
Courses school = new Courses();
String grad = JOptionPane.showInputDialog("Whats was the letter grade for " + count + "class");
school.setGrade(grad);
int creds = Integer.parseInt(JOptionPane.showInputDialog("How Many Credits was your " + count + "class"));
school.setCredits(creds);
ok so that should work right, but i noticed u stored 4.0 in a variable, that means that i would have to write 6 different variables, correct? 1 for a, b ,b+,c,c+,d,d+,f,w. and the i would have to write all those into a nested if statment, so thats why i did it the wya i did. is therr another way of tackling this problem?
Bookmarks