Results 1 to 4 of 4
  1. #1
    mattvgt is offline Member
    Join Date
    Jul 2007
    Posts
    2
    Rep Power
    0

    Default help with java program

    I'm getting errors while compiling this. Can someone point me in the right direction?

    Java Code:
    import java.util.Scanner;
    
    public class MaleFemaleGPA
    
    {
    
    	static Scanner inFile = new Scanner(new FileReader(GPAdata.dat));
    
    	public static void main(String[] args)
    
    	{
    
    		char maleTotal, femaleTotal;
    		int maleCount, femaleCount;
    		double maleAverage, femaleAverage;
    
    		if (inFile.next.charAt(0) = m)
    
    			{
    
    			maleTotal += inFile.nextDouble();
    			maleCount++;
    
    			}
    
    		else
    
    			{
    
    			femaleTotal += inFile.nextDouble();
    			femaleCount++;
    
    			}
    
    		maleAverage = maleTotal / maleCount;
    		femaleAverage = femaleTotal / femaleCount;
    
    		System.out.println("Average GPA for male students is " + maleAverage);
    		System.out.println("Average GPA for female students is " + femaleAverage);
    
    		inFile.close();
    
    	}
    
    }

  2. #2
    simon is offline Member
    Join Date
    Jul 2007
    Posts
    44
    Rep Power
    0

    Default

    can you explain what do you do with the code? and what is the problem exactly?
    so I can test it and help you

  3. #3
    mattvgt is offline Member
    Join Date
    Jul 2007
    Posts
    2
    Rep Power
    0

    Default

    I have a file that is in the format:

    m 2.92
    f 2.60
    f 2.62
    m 4.0
    etc...

    The program is supposed to get the average of all the m's and f's. The m is for Male the f is for Female. The number beside of each m or f is the GPA. So it needs to get the average GPA for all male students and all female students.

  4. #4
    boy22 is offline Member
    Join Date
    Jul 2007
    Posts
    36
    Rep Power
    0

    Default

    You have to define maleTotal, femaleTotal as real or double; maleCount, femaleCount as integer and then initialized them

Similar Threads

  1. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  2. New to Java Program
    By jvasilj1 in forum New To Java
    Replies: 1
    Last Post: 02-05-2008, 08:22 AM
  3. Replies: 0
    Last Post: 10-04-2007, 10:33 PM
  4. help with simple java program
    By leonard in forum New To Java
    Replies: 3
    Last Post: 07-30-2007, 10:40 AM
  5. java program
    By nehasahu in forum New To Java
    Replies: 5
    Last Post: 07-12-2007, 12:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •