记一次学分绩点的算法

记一次学分绩点的算法

又到了算绩点的痛苦时刻,作为日常搬砖的小蚂蚁怎么会去一个个算呢,话不多说直接上代码(这是直接访问本地Excel表算结果,有些对应的行数不同得自己改代码(先横后竖))
package jidian;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class jidian {
	 public static void main(String[] args) throws BiffException, IOException
	   {
	      File xlsFile = new File("D:\\1test/1.xls");
	      // 获得工作簿对象
	      Workbook workbook = Workbook.getWorkbook(xlsFile);
	      // 获得所有工作表
	      List<String> cj =new ArrayList<>();
	      List<String> xf =new ArrayList<>();
	      Sheet[] sheets = workbook.getSheets();
	      // 遍历工作表
	      if (sheets != null)
	      {
	         for (Sheet sheet : sheets)
	         {
	            // 获得行数
	            int rows = sheet.getRows();
	            // 获得列数
	            int cols = sheet.getColumns();
	            // 读取数据
	            for (int row = 0; row < rows; row++)
	            {
	               for (int col = 0; col < cols; col++)
	               {
	                  /*System.out.printf("%10s", sheet.getCell(col, row)
	                        .getContents());*/
	            	   //以下是你想获取的数值,我这里是获取学分和成绩相对应的行数和列数并且存到对应的list中
	            	   if(col==5) {
	            		   if(row>=5&&row<=12) {
	            			   cj.add(sheet.getCell(col, row)
	                        .getContents());
	            		   }else if(row>=21&&row<=34) {
	            			   cj.add(sheet.getCell(col, row)
	       	                        .getContents());
	            		   }
	            	   }else if(col==6){
	            		   if(row>=5&&row<=12) {
	            			   xf.add(sheet.getCell(col, row)
	                        .getContents());
	            		   }else if(row>=21&&row<=34) {
	            			   xf.add(sheet.getCell(col, row)
		       	                        .getContents());
		            		   }
	            	   }else if(col==10) {
	            		   if(row>=5&&row<=18) {
	            			   cj.add(sheet.getCell(col, row)
	                        .getContents());
	            		   }else if(row>=21&&row<=33) {
	            			   cj.add(sheet.getCell(col, row)
	       	                        .getContents());
	            		   }
	            	   }else if(col==11) {
	            		   if(row>=5&&row<=18) {
	            			   xf.add(sheet.getCell(col, row)
	                        .getContents());
	            		   }else if(row>=21&&row<=33) {
	            			   xf.add(sheet.getCell(col, row)
		       	                        .getContents());
		            		   }
	            	   }else if(col==14) {
	            		   if(row>=5&&row<=14) {
	            			   cj.add(sheet.getCell(col, row)
	                        .getContents());
	            		   }
	            	   }else if(col==15) {
	            		   if(row>=5&&row<=14) {
	            			   xf.add(sheet.getCell(col, row)
	                        .getContents());
	            		   }
	            	   }
	               }
	            }
	         }
	      }
	      workbook.close();
	      float a=0,b=0,t=0;
	      //循环遍历已经存在两个list里面的数值
	      for (int i = 0; i < cj.size(); i++) {
	    	  //以下是获取学分和绩点之和的总和
	    	t=jisuan(Float.parseFloat(cj.get(i)));
	    	System.out.println(Float.parseFloat(cj.get(i)));
	    	System.out.println(t);
			t=t*Float.parseFloat(xf.get(i));
			System.out.println(Float.parseFloat(xf.get(i)));
			a+=t;
	      }
	      System.out.println(a);
	      for(String temp:xf) {
	    	  //以下是获取总学分
	    	  b+=Float.parseFloat(temp);
	      }
	      System.out.println(b);
	      //得出结果
	      System.out.println("绩点为:"+a/b);
	   }
	 /*这个函数是判断返回相对应的绩点*/
	 public static float jisuan(float x) {
		float temp=0;
		if(x>=90 && x<=100)
			temp = (float)4.0;
		else if(x>=85 && x<=89)
		    temp = (float)3.7;
		else if(x>=82 && x<=84)
		    temp = (float)3.3;
		else if(x>=78 && x<=81)
		    temp = (float)3.0;
		else if(x>=75 && x<=77)
		    temp = (float)2.7;
		else if(x>=71 && x<=74)
		    temp = (float)2.3;
		else if(x>=66 && x<=70)
		    temp = (float)2.0;
		else if(x>=62 && x<=65)
		    temp = (float)1.7;
		else if(x>=60 && x<=61)
		    temp = (float)1.3;
		else if(x==60)
		    temp = (float)1.0;
		else
			temp = 0;
		return temp;
	 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值