记一次学分绩点的算法
又到了算绩点的痛苦时刻,作为日常搬砖的小蚂蚁怎么会去一个个算呢,话不多说直接上代码(这是直接访问本地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++)
{
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;
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;
}
}