第一次编程的作业
博客班级 | https://edu.cnblogs.com/campus/fzzcxy/2018SE1 |
---|---|
作业要求 | https://edu.cnblogs.com/campus/fzzcxy/2018SE1/homework/11110 |
作业目标 | <学习使用Git,了解Git的上传以及更新文件,通过Jsoup查找云班课分值> |
作业源代码 | https://gitee.com/WZ1115A/dashboard/projects |
学号 | <211806424> |
代码行数: 110 | |
需求分析时间: 10h | |
编码时间: 15h | |
思路分解 | |
1.导入html到eclipse中,获得Document | |
2.找经验值的相同属性 | |
3.通过isNum()函数计算对应题型所获得的经验值 | |
4.读取配置文件 | |
5.依题意计算经验值 | |
建立git远程仓库: | |
![]() |
用java去让HTML解析的代码:
{
try {
File file = new File("src/small.html");
Document doc = Jsoup.parse(file, "UTF-8", "http://example.com/");
File file1 = new File("src/all.html");
Document doc1 = Jsoup.parse(file1, "UTF-8", "http://example.com/");
//System.out.println(doc);
int self_before=0;
int self_base=0;
int self_test=0;
int self_program=0;
int self_add=0;
int rowslength=doc.select("div[class=interaction-row]").size();//全部class的长度
for (int i=0;i<rowslength;i++) {
//目的:看出长度之在9,10,11,12,13之间转换换
int rowssize=doc.select("div[class=interaction-row]").get(i).select("span").size();
/* System.out.println(rowssize);
Elements rows=doc.select("div[class=interaction-row]").get(i).select("span");
System.out.println(rows.text());
System.out.println("-----------");*/
String rows=doc.select("div[class=interaction-row]").get(i).select("span").get(1).text();
int spansize=doc.select("div[class=interaction-row]").get(i).select("span").size();
if(rows.indexOf("自测")!=-1) {
/*System.out.println(rowssize);System.out.println(rows);*/
String selfget=doc.select("div[class=interaction-row]").get(i).select("span").get(spansize-1).text();
/*System.out.println(selfget); 以下相同*/
self_before+=isNum(selfget);
}
if(rows.indexOf("小测")!=-1) {
String testget=doc.select("div[class=interaction-row]").get(i).select("span").get(spansize-1).text();
self_test+=isNum(testget);
}
if(rows.indexOf("课堂完成")!=-1) {
String baseget=doc.select("div[class=interaction-row]").get(i).select("span").get(spansize-1).text();
self_base+=(isNum(baseget));
}
if(rows.indexOf("编程")!=-1) {
String proget=doc.select("div[class=interaction-row]").get(i).select("span").get(spansize-1).text();
self_program+=(isNum(proget));
}
if(rows.indexOf("附加")!=-1) {
String addget=doc.select("div[class=interaction-row]").get(i).select("span").get(spansize-1).text();
self_add+=(isNum(addget));
}
}
int rowslength1=doc1.select("div[class=interaction-row]").size();//查找html中全部class的个数
for (int i=0;i<rowslength1;i++) {
int rowssizea=doc1.select("div[class=interaction-row]").get(i).select("span").size();
String rowsa=doc1.select("div[class=interaction-row]").get(i).select("span").get(1).text();
int spansize=doc1.select("div[class=interaction-row]").get(i).select("span").size();
if(rowsa.indexOf("自测")!=-1) {
String selfget=doc1.select("div[class=interaction-row]").get(i).select("span").get(spansize-1).text();
self_before+=isNum(selfget);
}
}
double before=self_before/(double)all_before* 100;
double base=self_base/(float)all_base* 100*0.95;
double test=self_test/(double)all_test* 100;
double program=self_program/all_program* 100;
if(program>95.0)
program=95.0;
//附加题部分换算成百分制若超过 90 则为 90
double add=self_add/all_add* 100;
if(add>90.0)
add=90.0;
double last_score=before*0.25+base*0.3+test*0.2+program*0.1+add*0.05;
String result = String .format("%.2f",last_score);
System.out.println(result);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static int isNum(String str){
String str1="";
for(int i=0;i<str.length();i++){
char chr=str.charAt(i);
if(chr>=48 && chr<=57)
str1+=chr;
}
int a=Integer.parseInt(str1);
return a;
}
}
}
学习过程
1配置文件 :https://blog.csdn.net/qq_38006520/article/details/82951958?ops_request_misc={"request_id"%3A"159973873319725254046608"%2C"scm"%3A"20140713.130102334.."}&request_id=159973873319725254046608&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduend~default-3-82951958.first_rank_ecpm_v3_pc_rank_v2&utm_term=java怎么创建配置文件&spm=1018.2118.3001.4187
2.解析html文件:https://www.open-open.com/jsoup/load-document-from-file.htm
3.建立git仓库的方法:https://m.runoob.com/git/git-create-repository.html
想法:光是看懂题目题目都用了一上午(刚开始以为是让设计一个程序去算给定的经验值???),主要是这方面代码打的太少。|