www.pudn.com > students.rar > Crouse_score.java


package students; 
import java.sql.*; 
public class Crouse_score { 
	public static int[] fun(String str){ 
		Connection con=null; 
		Statement stmt=null; 
		ResultSet rs = null; 
		int score[]=new int [6]; 
		 
		try{ 
		 
			con = Database.connectToDb(); 
			String strSQL2="select S.degree from sel_crouses S where S.cro_id= "+str; 
			stmt = con.createStatement(); 
			rs = stmt.executeQuery(strSQL2); 
			while(rs.next()){ 
				if(Float.parseFloat(rs.getString("degree"))<60) 
					score[0]++; 
				else if(Float.parseFloat(rs.getString("degree"))>=60 && Float.parseFloat(rs.getString("degree"))<70) 
					score[1]++; 
				else if(Float.parseFloat(rs.getString("degree"))>=70 && Float.parseFloat(rs.getString("degree"))<80) 
					score[2]++; 
				else if(Float.parseFloat(rs.getString("degree"))>=80 && Float.parseFloat(rs.getString("degree"))<90) 
					score[3]++; 
				else if(Float.parseFloat(rs.getString("degree"))>=90 && Float.parseFloat(rs.getString("degree"))<100) 
					score[4]++; 
				else if(Float.parseFloat(rs.getString("degree"))==100) 
					score[5]++; 
			} 
		}catch (SQLException e) { 
			e.printStackTrace(); 
		} catch (Exception e) { 
			e.printStackTrace(); 
		} finally { 
			if (con != null) { 
				try { 
					con.close(); 
				} catch (SQLException e) { 
					e.printStackTrace(); 
				} 
				con = null; 
			} 
		} 
		return score; 
	} 
	public static float fun1(String str){ 
		Connection con=null; 
		Statement stmt=null; 
		ResultSet rs = null; 
		int i=0; 
		float result=0; 
		float res=0; 
		try{ 
		 
			con = Database.connectToDb(); 
			String strSQL2="select S.degree from sel_crouses S where S.cro_id= "+str; 
			stmt = con.createStatement(); 
			rs = stmt.executeQuery(strSQL2); 
			while(rs.next()){ 
				result+=Float.parseFloat(rs.getString("degree")); 
				i++; 
			} 
		}catch (SQLException e) { 
			e.printStackTrace(); 
		} catch (Exception e) { 
			e.printStackTrace(); 
		} finally { 
			if (con != null) { 
				try { 
					con.close(); 
				} catch (SQLException e) { 
					e.printStackTrace(); 
				} 
				con = null; 
			} 
		} 
		res=result/i; 
//		java.text.DecimalFormat df = new java.text.DecimalFormat("#.00");    
//		df.format(res); 
		return res; 
	} 
}