Results 1 to 5 of 5
  1. #1
    blueduiker is offline Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    55
    Rep Power
    0

    Talking Problems With Array/Methods

    Hey guys,

    I am having some problems with the code below:

    The Student Class:
    Java Code:
    public class findValedictorian {
    	public static void main (String[] args) {
    		
    		//Declaration Block
    		//Scanner scan = new Scanner(System.in);
    		Student[] students = {
    				new Student("Justin", "Ku"), new Student("Christopher", "O'Brien", 4.892), new Student("JC", "Mo", 2.6), 
    				new Student("Albert", "Einstein", 1.93), new Student("Peter", "Chao", 4.1), new Student("Pedro", "Gonzalez", 3.5)
    		};
    		
    		for (int i = 0; i < students.length; i++){
    			System.out.println (students.toString() + students.getGPA());
    		}   
      }
    }
    The Student Class:

    Java Code:
    public class Student {
    	
    	//Declaration Block
    		Scanner scan = new Scanner(System.in);
      
      
    	//Instance Variables
    		private double gpa;
    		private String firstName, lastName;
      
     
    	// a) accepts first and last name, assigns gpa 0.0
    		public Student(String fName, String sirName){
    			firstName = fName;
    			lastName = sirName;
    			gpa = 0.0;
    			}
    
      
    	// b) accepts first name, last name, gpa		
    		public Student(String fName, String sirName, double gradepointaverage){
    			firstName = fName;
    			lastName = sirName;
    			gpa = gradepointaverage;
    		}
    		
    		
    	//returns the names of the students
    		public String toString(){
    			return firstName + " " + lastName + "'s GPA: ";
    		}
    		
    			
        //returns the gpa of the students
    		public double getGPA(){
    			return gpa;
    		}
    }
    Ok so basically the Student.java class compiles; however the client class, find Valedictorian.java does not. The error resides in this portion of the output line: students.getGPA()
    Eclipse is telling me that I Cannot invoke getGPA() on the array type Student[]

    all i want to do is output the gpa? what is wrong

    ALL HELP IS GREATLY APPRECIATED, thanks

  2. #2
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    extensions are in bold. (hard to see em, sorry :s)
    Java Code:
    ....
    		for (int i = 0; i < students.length; i++){
    			System.out.println (students[B][i][/B].toString() + students[B][i][/B].getGPA());
    		}  
    ....
    Last edited by Lil_Aziz1; 01-19-2010 at 01:23 AM.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  3. #3
    blueduiker is offline Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    55
    Rep Power
    0

    Default

    Thank you so much +1 rep

  4. #4
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    hellzzzz yea! ;) thanks
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  5. #5
    blueduiker is offline Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    55
    Rep Power
    0

Similar Threads

  1. do static methods cause synchronization problems
    By rajakumar.tu in forum Advanced Java
    Replies: 2
    Last Post: 12-24-2009, 07:39 AM
  2. Array problems!
    By Addez in forum New To Java
    Replies: 4
    Last Post: 08-29-2009, 06:56 PM
  3. Problems implementing Java string methods
    By everlast88az in forum New To Java
    Replies: 8
    Last Post: 11-06-2008, 04:17 AM
  4. Replies: 1
    Last Post: 07-20-2008, 04:42 PM
  5. Problems with readLine() and calling methods
    By peachyco in forum New To Java
    Replies: 2
    Last Post: 11-24-2007, 07:44 AM

Tags for this Thread

Posting Permissions

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