Results 1 to 2 of 2

Thread: Changing arrays.

  1. #1
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Changing arrays.

    Ok one last problem... i hope.
    When i run through my Undergrad loop and add the grades it works. but when i add two or more Undergrad students it uses the most recent scores added for all the Undergrad students. I realize i need to do some sort of loop so that i can add more arrays. I can have a maximum of 20 students. in my array. How would i make an array that has a different name every time 1 is added. here is my code.
    Code:
    class Undergrad extends College
       {
          int[] tempAct, tempExercise, tempProject;
        
       	int ap, ex1, ex2, fEx;
       	
          
       	public UnderGrad(String name, int age, String schoolName, int id, double gpa, int apCreds, String major, String minor, boolean time, int examOne, int examTwo, int[] activity, int[] exercise, int[] projects, int finalExam)
       	{
       		super(name, age, id, schoolName, gpa, major, minor, time);
       		tempAct = activity;
       		tempExercise = exercise;
       		tempProject = projects;
    			ap = apCreds;
    			ex1 = examOne;
    			ex2 = examTwo;
    			fEx = finalExam;
       	}
       	
       	public String toString()
       	{
    			String A, E, P;
    			A = "";
    			for(int i = 0; i < 14; i++)
    				A += tempAct[i] + " ";
    			E = "";
    			for(int j = 0; j < 14; j++)
    				E += tempExercise[j] + " ";
    			P = "";
    			for (int k = 0; k < 14; k++)
    				P += tempProject[k] + " ";
    			
       		String temp = super.toString();
       		return temp +"\nExam One Grade: "+ex1+ "\nExam Two Grade: "+ex2+"\nActivity Grades: "+A+"\nExercise Grades: "+E+"\nProject Grades: "+P;
       	}
       		
       }

  2. #2
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Got it fixed. It was because my arrays in the driver file were declared static. Not sure why it effected it but that is the reason.

Bookmarks

Posting Permissions

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