import java.util.*;

public class D2 extends DetailRecord
{
	private String school;
	private static final int TOKENS = 5;
	private static final int HOURS = 4;
	private static final int YEAR = 0;
	private static final int TERM = 1;

	
	public D2(int y, int t, String s, String c, int h)
	{
		super (y, t, c, h);
		school = s;
	}
	
	public int getGradedHours ()
	{
		return 0;
	}
	
	public Grade getGrade()
	{
		return Grade.TR ;
	}
	
	public int getEarnedHours()
	{
		return getCreditHours();
	}
	
	public String getDescription()
	{
		return getCourse() + " taken at " + school;
	}
	
	public double getQualityPoints()
	{
		return 0;
	}
	public static int checkD2(String line)
	{
		int result, hours;
		String fields [];
		StringTokenizer st;
		fields = new String [TOKENS];
		
		st = new StringTokenizer(line, ",");		
		hours = 0;
		result = 0;
		
		if (st.countTokens() != TOKENS)
			result = 7;
		// pull off tokens to prep for next section
		else
		{
			for (int ii = 0; ii < fields.length; ii++)
				fields[ii] = st.nextToken();
			
			try
			{
				Integer.parseInt(fields[YEAR]);
				Integer.parseInt(fields[TERM]);
				hours = Integer.parseInt(fields[HOURS]);
			}
			catch(NumberFormatException nfe)
			{
				result = 8;
			}		
			if(hours < 0 || hours > 12)
				result = 9;
		}
		
		return result;
	}
	
	public static D2 makeD2(String line)
	{
		D2 detail = null;
		StringTokenizer st;
		int year, term, hours;
		String course, school;
				
		// if no errors found
		if (checkD2(line) == 0)
		{
			// at this point we know that everything
			// is okay since we have checked.
			st = new StringTokenizer(line,",");
			year = Integer.parseInt(st.nextToken());
			term = Integer.parseInt(st.nextToken());
			school = st.nextToken();
			course = st.nextToken();
			hours = Integer.parseInt(st.nextToken());
			
			detail = new D2(year, term, school, course, hours);
		}	
		return detail;
	}

}