import java.util.*;

public class D1 extends DetailRecord
{
	private String testType;
	private double score;
	private static final int TOKENS = 6;
	private static final int HOURS = 5;
	private static final int YEAR = 0;
	private static final int TERM = 1;
	private static final int TYPE = 4;

	
	public D1(int y, int t, String c, String tt, double s, int h)
	{
		super (y, t, c, h);
		testType = tt;
		score = s;
	}
	
	public int getGradedHours ()
	{
		return 0;
	}
	
	public Grade getGrade()
	{
		return Grade.CR ;
	}
	
	public int getEarnedHours()
	{
		return getCreditHours();
	}
	
	public String getDescription()
	{
		return getCourse() + " Test " + testType + ": " + score;
	}
	
	public double getQualityPoints()
	{
		return 0;
	}
	public static int checkD1(String line)
	{
		int result, hours;
		double tScore;
		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]);
				tScore = Double.parseDouble(fields[TYPE]);
			}
			catch(NumberFormatException nfe)
			{
				result = 8;
			}		
			if(hours < 0 || hours > 12)
				result = 9;
		}
		
		return result;
	}
	
	public static D1 makeD1(String line)
	{
		D1 detail = null;
		StringTokenizer st;
		int year, term, hours;
		double tScore;
		String course, testType;
						
		// if no errors found
		if (checkD1(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());
			course = st.nextToken();
			testType = st.nextToken();
			tScore = Double.parseDouble(st.nextToken());
			hours = Integer.parseInt(st.nextToken());
			
			detail = new D1(year, term, course, testType, tScore, hours);
		}	
		return detail;
	}

}