So this is my first time on these forums so if this is in the wrong spot, I apologize.
This is the input file I have:
f 3.40 f 4.00 m 3.56 m 3.80 f 2.30 f 3.95 m 3.90 m 4.00 m 2.00 f 4.00 f 2.80 m 3.70 m 2.98 f 3.89 m 4.00 f 3.90 m 1.90 m 2.90 f 1.50 f 2.67 m 3.80 m 2.35 f 2.90 f 3.70 f 4.00 m 3.78 m 4.00 f 3.98
And here's my relevant code:
public static void main(String[] args) throws FileNotFoundException { Scanner inFile = new Scanner (new FileReader("Ch5_Ex18Data.txt")); PrintWriter outFile = new PrintWriter("output.txt"); int mCounter = 0, fCounter = 0; double maleGPA, femaleGPA, mSum = 0, fSum = 0; while (inFile.hasNext()) { if (inFile.next() == "m") { mCounter++; mSum = mSum + inFile.nextDouble(); } else { fCounter++; fSum = fSum + inFile.nextDouble(); } } inFile.close();
What the program should do is store the values for the amount of males and females separately as well as the sum of their GPA's separately. Now with the way I have it everything is getting read in and stored as a female only. I've been trying to figure out what I have wrong for some time now and I can't get it, so I was hoping that someone here could point me in the right direction. If you need any more info or just need something cleared up just ask.
Thanks in advance for any help you can provide.