首页 \ 问答 \ 《Java程序设计一》 1,设计课程类及类中包含的属性和方法.

《Java程序设计一》 1,设计课程类及类中包含的属性和方法.

《Java程序设计一》 1、设计课程类及类中包含的属性和方法。 提示: 设计三个变量:课程号,课程名称,课程分数。   要求:课程类不能作为主类。 课程号随机生成。 2、设计学生类及类中包含的属性和方法。 提示:设计三个变量:学号,姓名,课程对象(如:Course  course[])。       设计的方法至少包括:选课,给成绩,求总分,打印输出成绩。 要求:学生类不能作为主类。        学生的学号随机生成。        学生的成绩为每人多门成绩。        学生选修的课程数及课程名称、成绩在程序运行时交互式生成。        求每位学生的总分。        按照下列格式打印学生的相关信息。         学号:172         姓名:张三    课程1:90        课程2:89                   总分:179 3、设计主类,包含main方法,对类中的方法进行调用,完成各功能。    要求:主方法中仅设计对象的定义及方法的调用。 《Java程序设计二》 修改实验一: 1、  增加教师类,根据上述实验要求,设计类中的方法和属性。 要求:每位学生的成绩由教师给出。适当修改学生和教师类中的方法 提示:教师负责给出成绩,课程负责对成绩进行赋值,学生负责对指定的课程赋值。 2、  在教师类和学生类之上设计person类,构建继承关系 3、  设计主类 《Java程序设计三》 修改实验二: 1、  将person类设计成抽象类,其中的setId方法设计为抽象方法,在教师类和学生类中分别实现不同的setId方法。 2、  设计接口Compare,包含方法CompareTo(Object o),实现对不同类的相等判断 3、  person类实现Compare接口,在子类中具体实现不同的判断方式 4、  重写equals方法,具体实现不同的判等方式。 5、  编写主类
更新时间:2022-01-09 11:01

最满意答案

import java.io.*;
import java.util.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import javax.swing.text.html.parser.*;
import javax.swing.text.html.HTMLEditorKit.ParserCallback;
public class Parser extends ParserCallback {    //继承ParserCallback,解析结果驱动这些回调方法
 protected String base;
 protected boolean isImg = false;
 protected boolean isParagraph = false;
 protected static Vector<String> element = new Vector<String>();
 protected static String paragraphText = new String();
 public Parser() {
 }
 public static String getParagraphText() {
  return paragraphText;
 }
 public void handleComment(char[] data, int pos) {
 }
 public void handleEndTag(HTML.Tag t, int pos) {
  if (t == HTML.Tag.P) {
   if (isParagraph) {
    isParagraph = false;
   }
  } else if (t == HTML.Tag.IMG) {
   if (isImg) {
    isImg = false;
   }
  }
 }
 public void handleError(String errorMsg, int pos) {
 }
 public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
  handleStartTag(t, a, pos);
 }
 public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {
  if (t == HTML.Tag.P) {
   isParagraph = true;
  } else if ((t == HTML.Tag.IMG)) {
   String src = (String) a.getAttribute(HTML.Attribute.SRC);
   if (src != null) {
    element.addElement(src);
    isImg = true;
   }
  }
 }
 public void handleText(char[] data, int pos) {
  if (isParagraph) {
   String tempParagraphText = new String(data);
   if (paragraphText != null) {
    element.addElement(tempParagraphText);
    ;
   }
  }
 }

 private static void startParse(String sHtml) {
  try {
   ParserDelegator ps = new ParserDelegator();//负责每次在调用其 parse 方法时启动一个新的 DocumentParser
   HTMLEditorKit.ParserCallback parser = new Parser();//解析结果驱动这些回调方法。
   ps.parse(new StringReader(sHtml), parser, true);//解析给定的流并通过解析的结果驱动给定的回调。
   //System.out.println(getParagraphText());
   Vector link = element;
   for (int i = 0; i < link.size(); i++) {
    System.out.println("----haha-----");
    System.out.println(link.get(i));
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
 public static void main(String args[]) {
  try {
   String filename = "D://blogbaby.htm";
   BufferedReader brd = new BufferedReader(new FileReader(filename));
   char[] str = new char[50000];
   brd.read(str);
   String sHtml = new String(str);
   startParse(sHtml);
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}

其他回答

用jsonp可以解析html文档

相关问答

更多
  • import java.io.*; import java.util.*; import javax.swing.text.*; import javax.swing.text.html.*; import javax.swing.text.html.parser.*; import javax.swing.text.html.HTMLEditorKit.ParserCallback; public class Parser extends ParserCallback { //继承ParserCallba ...
  • 在java环境下读取xml文件的方法主要有4种:DOM、SAX、JDOM、JAXB 1. DOM(Document Object Model) 此方法主要由W3C提供,它将xml文件全部读入内存中,然后将各个元素组成一棵数据树,以便快速的访问各个节点 。 因此非常消耗系统性能 ,对比较大的文档不适宜采用DOM方法来解析。 DOM API 直接沿袭了 XML 规范。每个结点都可以扩展的基于 Node 的接口,就多态性的观点来讲,它是优秀的,但是在 Java 语言中的应用不方便,并且可读性不强。 实例: imp ...
  • Java 如何解析XML[2022-02-14]

    package xml; import java.io.File; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamRe ...
  • 如果你想修改网页并返回修改后的内容,那么我最好的方法就是使用XSL转换。 http://en.wikipedia.org/wiki/XSLT if you want to modify web page and return modified content, I thnk the best way is to use XSL transformation. http://en.wikipedia.org/wiki/XSLT
  • 如果它真的只是从字符串中获取某些子字符串,那么我会在这里使用正则表达式。 使用捕获组(确保它不贪婪)来获取您感兴趣的字符串部分(在本例中为value属性和标记内容)。 val str = """""" val pattern = """
  • 您还应该选择选项。 尝试这个。 Document doc = Jsoup.parse(html); Elements options=doc.select("select[id=secondary_contact_type] > option"); for(Element data:options){ System.out.println(data.attr("value")); System.out.println(data.ownText()); ...
  • 问题解决了! 其中一个没有任何导致这个问题! problem solved! One of the does not have any which causes this problem!!
  • 将您的XML读取到StringReader中,将其包装在InputSource中,并将其传递给您的DocumentBuilder: DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new InputSource(new StringReader(xml))); Read your ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)