All pastes #11475 Raw Edit

Eyeless

public text v1 · immutable
#11475 ·published 2005-05-11 11:42 UTC
rendered paste body
	/* Method: statistics
	 * Parameters: an ArrayList
	 * Return: a String
	 * Read info about personnummer and show age's statistics at 2005
	 * Declared as static because called in another class through "JuppgiftGUI.statistics(...)"
	 */
	public static String statistics( ArrayList statistics ) {

		int year;
		int ages[] = new int[10];
		
		for ( int i = 0; i < statistics.size(); i++ ) {
			if ( ((Personnummer)statistics.get(i)).errorMessage() == null ) {
				year = Integer.parseInt(((Personnummer)statistics.get(i)).personnummer().substring( 0, 2 ));

				if (year < 06) //om det är pa 2000-talet
					year += 2000; // slå om så det e det;
				else 
					year += 1900;
				
				ages[(2005 - year)/10] += 1; //öka rätt åldersperiod
			}
		}
		
		String retval = new String("");
		for(int x = 0; x < 10; x++)
			retval += ages[x] + " st " + (x * 10) + "-" + (x * 10 + 9) + " - ingar\n";
			
		return retval;

	}	// end method statistics