/* ======================================================================
   Parts Copyright 2006 University of Leeds, Oxford University, University of the Highlands and Islands.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

====================================================================== */

package org.bodington.assessment;

import java.sql.Timestamp;
import java.util.Enumeration;
import java.math.BigDecimal;

import org.bodington.sqldatabase.*;
import org.bodington.database.*;
import org.bodington.server.BuildingServerException;

public class McqResult extends org.bodington.sqldatabase.SqlPersistentObject
	{
	
	private PrimaryKey mcq_result_id;
	private PrimaryKey resource_id;
	private PrimaryKey user_id;
	private int available;
	private int deductions;
	private int wrong;
	private int right;
	private java.sql.Timestamp when_done;
	private java.sql.Timestamp when_marked;
	
	
	public static McqResult findMcqResult( PrimaryKey key )
	    throws BuildingServerException
	    {
	    return (McqResult)findPersistentObject( key, "org.bodington.assessment.McqResult" );
	    }
	
	public static McqResult findMcqResult( String where )
	    throws BuildingServerException
	    {
	    return (McqResult)findPersistentObject( where, "org.bodington.assessment.McqResult" );
	    }
	
	public static Enumeration findMcqResults( String where )
	    throws BuildingServerException
	    {
	    return findPersistentObjects( where, "org.bodington.assessment.McqResult" );
	    }
	
	public static Enumeration findMcqResults( String where, String order )
	    throws BuildingServerException
	    {
	    return findPersistentObjects( where, order, "org.bodington.assessment.McqResult" );
	    }
	

	
    public PrimaryKey getPrimaryKey()
    	{
        return getMcqResultId();
    	}

    public void setPrimaryKey(PrimaryKey key)
    	{
    	setMcqResultId( key );
    	}


	public PrimaryKey getMcqResultId()
		{
		return mcq_result_id;
		}
		
	public void setMcqResultId( PrimaryKey id )
		{
		mcq_result_id = id;
		}
		
	public PrimaryKey getResourceId()
		{
		return resource_id;
		}
		
	public void setResourceId( PrimaryKey id )
		{
		resource_id = id;
		setUnsaved();
		}


	public PrimaryKey getUserId()
		{
		return user_id;
		}
		
	public void setUserId( PrimaryKey id )
		{
		user_id = id;
		setUnsaved();
		}


	public int getAvailable()
		{
		return available;
		}
		
	public void setAvailable( int n )
		{
		if ( available == n )
			return;
		available = n;
		setUnsaved();
		}

	
	public int getDeductions()
		{
		return deductions;
		}
		
	public void setDeductions( int n )
		{
		if ( deductions == n )
			return;
		deductions = n;
		setUnsaved();
		}
		
		
	public int getRight()
		{
		return right;
		}
		
	public void setRight( int n )
		{
		if ( right == n )
			return;
		right = n;
		setUnsaved();
		}
		
				
	public int getWrong()
		{
		return wrong;
		}
		
	public void setWrong( int n )
		{
		if ( wrong == n )
			return;
		wrong = n;
		setUnsaved();
		}
		
		
	public Timestamp getWhenDone()
		{
		return when_done;
		}
		
	public void setWhenDone( Timestamp t )
		{
		when_done = t;
		setUnsaved();
		}
		
	public Timestamp getWhenMarked()
		{
		return when_marked;
		}
		
	public void setWhenMarked( Timestamp t )
		{
		when_marked = t;
		setUnsaved();
		}
		
		
	public BigDecimal mark()
		{
		double	mark=	((double)right - (double)deductions) / (double)available;
			
		BigDecimal bigmark = new BigDecimal( Long.toString( Math.round( mark *  1000.0 ) ) );
		return bigmark.movePointLeft( 1 );
		}
	
	}
