Sapperm's Profile User Rating: -----

Reputation: 2 Apprentice
Group:
New Members
Active Posts:
15 (0.01 per day)
Joined:
31-October 12
Profile Views:
311
Last Active:
User is offline Sep 18 2013 08:36 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   Sapperm has not set their status

Posts I've Made

  1. In Topic: Reading data from an array into an object

    Posted 16 Sep 2013

    Well I worked more on it as soon as I posted the question. I think I found a valid solution by using array lists.
    *I made an array list
    *populated the list
    *converted the list to a int array via loop
    *sent in the array to the constructor
    *used .clear to clear the list and start over

    import java.util.*;
    import java.io.*;
    /**
     * 
     * @author 
     *
     */
    public class Lab2 {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		
    		Grades[] classArray;
    	     classArray = new Grades[4];
    	
    	     ArrayList<Integer> gradeList = new ArrayList<Integer>();
    		
    	     
    	  
    		int [] grades;
    		grades = new int[1];
    		
    		String name;
    		  
            int counter = 0;
    		
            
    		Scanner in = null;
    		try {
    		    in = new Scanner(new File("data.txt"));
    		} catch (FileNotFoundException exception) {
    		    System.err.println("failed to open data.txt");
    		    System.exit(1);
    		}
    		int j = 0;
    		while (in.hasNext()) {
    			name = in.next();
    			
    		
    		    while (in.hasNextInt()) {
    		    	int grade = in.nextInt();
    			  
    		    	gradeList.add(grade);
    				
    		//		if (counter == grades.length) {
    			//		
    			//		grades = Arrays.copyOf(grades, 2 * grades.length);
    		//		}
    				
    				
    				
    			//	grades[counter] = grade;
    				counter++;
    	
    		    }
    		 
    		   
    		    grades = new int[gradeList.size()];
    		    for (int index = 0; index < gradeList.size(); index++) {
    		        grades[index] = gradeList.get(index);
    		    }
    		   // System.out.println("gradelist.size = "+ gradeList.size());
    		   // grades = Arrays.copyOf(grades, counter);
    		   
    		    
    		    classArray[j] = new Grades(name,grades);
    		    gradeList.clear();
    		 
    		    j++;
    		 
    		}
    		//grades = Arrays.copyOf(grades, counter);
    //		Arrays.sort(grades);
    	/*
    		for(int i = 0; i < counter; i++){
    		    
    			System.out.printf("counter = %d\n",grades[i]);
    		
    		}
    		*/
    
    		testGrades(classArray[0]);
    		testGrades(classArray[1]);
    		testGrades(classArray[2]);
    		testGrades(classArray[3]);
    	}//end main
    	
    	public static void testGrades(Grades grades) {
    	    System.out.println(grades.toString()); 
    	    System.out.printf("\tName:    %s\n", grades.getName());
    	    System.out.printf("\tLength:  %d\n", grades.length());
    	    System.out.printf("\tAverage: %.2f\n", grades.average());
    	    System.out.printf("\tMedian:  %.1f\n", grades.median());
    	    System.out.printf("\tMaximum: %d\n", grades.maximum());
    	    System.out.printf("\tMininum: %d\n", grades.minimum());
    	}
    
    }//end class
    
    
    
  2. In Topic: Inserting strings to binary trees

    Posted 15 Aug 2013

    I was using all of the various printf() statements in the program to test where data was being read and stored properly. As it turns out it all was.

    I found the problem at line 69. I had a == instead of a =.
  3. In Topic: hi i really want to learn C++ but where do i go?

    Posted 14 Aug 2013

    Some questions you may want to ask your self.
    Why do I want to learn C++?
    What do I want to accomplish?
    How much time can I spend on learning?

    Based on these answers you will discover a variety of methods that will work best for you. If you are looking for a career path, and formal instruction, maybe a university would be best. On the other hand, you may be looking to learn on the side casually.

    There are many tutorials on this site. There are also vast amounts of tutorials on youtube for all experience levels. The best thing to do is expose your self to all of these mediums and see what helps you learn the most.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

Sapperm hasn't added any friends yet.

Comments

Sapperm has no profile comments yet. Why not say hello?