第一次编程作业

博客班级 https://edu.cnblogs.com/campus/fzzcxy/2018SE2
作业要求 https://www.cnblogs.com/yifelix/p/13647905.html
作业目标 eclipse 怎么配置jsoup,完成成绩计算和复习
作业源代码 https://gitee.com/chen-shiyu/personal
学号 211806307

时间记录

需求分析3个时
代码行数126行
编码时间6小时

思路

获得帮助:CSDN(百度),其中一例:https://blog.csdn.net/sunrainamazing/article/details/55253532;同学的思路梳理。

首先读取配置文件,解析网页,然后用try防止报错,开始定义。

	public static void main(String[] args) throws IOException{	
		// 读取配置文件
		Properties prop = new Properties();
		prop.load(new FileInputStream("src/total.properties"));
		Enumeration fileName = prop.propertyNames();
		// 总分赋值
		int all_before = Integer.parseInt(prop.getProperty("before"));
		int all_base = Integer.parseInt(prop.getProperty("base"));
		int all_test = Integer.parseInt(prop.getProperty("test"));
		int all_program = Integer.parseInt(prop.getProperty("program"));
		int all_add = Integer.parseInt(prop.getProperty("add"));
		
		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/");

开始看云班课网页代码寻找规律,然后发现span和各个分数之间的关系。定义循环,从第一个项目的分数开始叠加,直到最后一个,然后得出各个项目的总分。
其中一个例子:

int rowslength=doc.select("div[class=interaction-row]").size();//全部class的长度
			for (int i=0;i<rowslength;i++) {
				int rowssize=doc.select("div[class=interaction-row]").get(i).select("span").size();				
				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);
				}

最后进行计算。得出自己的分数(文本,后面将经验去除)。

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();
		}
		}
	
	//取出span标签中内容(数字+成绩)中的数字
    public void getNumber_charAt(){
        Stringstr1 = new Stringstr1();
        for (int i = 0; i < str.length(); i++) {
            char chr = str.charAt(i);
            if(48<=ch&&ch<=57){
                sBuffer.append(ch);
            }
/*	        System.out.println((char)9);
	        System.out.println(Stringstr1.toString());

posted on 2020-09-14 16:06  木丶木  阅读(124)  评论(1编辑  收藏  举报

导航