zoukankan      html  css  js  c++  java
  • 赵栋 201771010137 第三周学习总结

    自主学习任务

    1、 复习课程第1-3章学习内容

    2、 回顾实验三中实验题1《2018秋季西北师范大学面向对象程序设计(Java)(ch1-ch3)测试题1》,对照测试题参考答案,反思修改本人答卷的错误内容;

    3、完成实验2与实验3;

    4、修改置顶博文《面向对象程序设计课程学习进度条》,记录第三周个人编程水平提升参数

    第一部分:复习第一到三章

    1、第一章

               复习了Java语言的优点,发展简史,以及Java语言的关键术语和“白皮书”的特性,对Java的了解更加深刻了一点

    2、第二章

              复习了如何安装java开发工具包(JDK)以及如何编译和运行不同类型的程序以及如何构建并运行applet

    3、第三章

             复习了Java的数据类型,运算符,字符串等,重新学习了文件的输入输出,以及控制流程

    第二部分:实验部分

    1、实验目的与要求

      (1)进一步掌握Eclipse集成开发环境下java程序开发基本步骤;

      (2)熟悉PTA平台线上测试环境;

      (3)掌握Java语言构造基本程序语法知识(ch1-ch3);

      (4)利用已掌握Java语言基本程序设计知识,学习设计开发含有一个主类、类内可有多个方法的应用程序。

    2、实验内容和步骤

      实验2:公民身份证号码按照GB11643—1999《公民身份证号码》国家标准编制,由18位数字组成:前6位为行政区划分代码,第7位至14位为出生日期码,第15位至17位为顺序码,第18位为校验码。从键盘输入1个身份证号,将身份证号的年月日抽取出来,按年-月-日格式输出。注意:输入使用Scanner类的nextLine()方法,以免出错。

    输入样例:

    34080019810819327X

    输出样例:

    1981-08-19

    实验3:studentfile.txt文件内容是本班同学的学号与姓名,利用此文件编制一个程序,将studentfile.txt文件的信息读入到内存,并提供两类查询功能:(1)输入姓名查询学号;(2)输入学号查询姓名。要求程序具有友好人机交互界面

     3代码及结果

    1>实验二

     代码如下

    1 package jjj;
    2 import java.util.Scanner;

    3

    4 public class hhh {

    5

    6    public static void main(String[] args) {

    8         Scanner sc = new Scanner(System.in);

    10        System.out.println("请输入身份证号码:");

    11        String str = sc.nextLine();

    12        String regex = "^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$";

    13        boolean flag = str.matches(regex);

    14        if(flag == false) {

    15          System.out.println("身份证号码格式错误,请重新运行程序");

    16              }

    17

    18              String s1 = str.substring(6,10);
    19              String s2 = str.substring(10,12);
    20              String s3 = str.substring(12,14);
    21              System.out.println("出生年月"+ "-"+ s1+ "-"+s2+ "-"+s3);
    22    }

    23

    24 }

    结果验证如下:

     

    2>实验三

    (1)从文件中读入学生信息,可以编写如下函数:

    public static void StudentsFromFile(String fileName))

    (2)输入姓名查找学生学号,可以编写如下函数:

    public static String findStudent(String name)

    (3)输入学号查找学生姓名,可以编写如下函数:

    public static String findStudent(String ID)

     代码如下

    1 package mmm;
    2
    3  import java.io.BufferedReader;
    4 import java.io.File;
    5 import java.io.FileReader;
    6 import java.io.IOException;
    7 import java.util.ArrayList;
    8 import java.util.Scanner;
    9
    10
    11 public class Test {
    12
    13    
    14
    15    private static ArrayList<Student> studentList = null;
    16
    17    
    18    
    19     public static void StudentsFromFile(String fileName){
    20         File file = new File(fileName);
    21         BufferedReader reader = null;
    22         try {
    23             reader = new BufferedReader(new FileReader(file));
    24             String tempString = null;
    25             while ((tempString = reader.readLine()) != null) {
    26                 String str[] = tempString.split(" ");
    27                 if(studentList != null && str.length > 1) {
    28                     Student student = new Student();
    29                     student.setStudentId(str[0]);
    30                     student.setName(str[1]);
    31 studentList.add(student);
    32 }
    33 }
    34 reader.close();
    35         } catch (IOException e) {
    36 e.printStackTrace();
    37         } finally {
    38             if (reader != null) {
    39                 try {
    40 reader.close();
    41                 } catch (IOException e1) {
    42 }
    43 }
    44 }
    45 }
    46     public static String findStudentIdByName(String name) {
    47         String studentId = null;
    48         for(Student student : studentList) {
    49             if(student.getName().equals(name)) {
    50                 studentId = student.getStudentId();
    51                 break;
    52 }
    53 }
    54         return studentId;
    55 }
    56     public static String findStudentNameById(String ID) {
    57         String studentName = null;
    58         for(Student student : studentList) {
    59             if(student.getStudentId().equals(ID)) {
    60                 studentName = student.getName();
    61                 break;
    62 }
    63 }
    64         return studentName;
    65 }
    66     public static void main(String args[]) {
    67         String path = "D:/studentfile.txt";
    68         studentList = new ArrayList<Student>();
    69 StudentsFromFile(path);
    70         int statu = 1;
    71         System.out.println();
    72         while(statu != 0) {
    73             System.out.println("******************");
    74             System.out.println("1:通过姓名查询学生学号");
    75             System.out.println("2:通过学号查询学生姓名");
    76             System.out.println("0:退出");
    77             System.out.println("******************");
    78             Scanner scanner = new Scanner(System.in);
    79             statu = scanner.nextInt();
    80             switch(statu) {
    81             case 1:{
    82                 System.out.println("请输入学生姓名:");
    83                 Scanner scanner1 = new Scanner(System.in);
    84                 String name = scanner1.nextLine();
    85                 String Id = findStudentIdByName(name);
    86                 if(Id != null) {
    87                     System.out.println("姓名: "+name+" 学号: "+Id);
    88                 }else {
    89                     System.out.println("不存在该学生!请重新查找");
    90 }
    91
    92             }break;
    93             case 2:{
    94                 System.out.println("请输入学生学号:");
    95                 Scanner scanner2 = new Scanner(System.in);
    96                 String Id = scanner2.nextLine();
    97                 String name = findStudentNameById(Id);
    98                 if(name != null) {
    99                     System.out.println("姓名: "+name+" 学号: "+Id);
    100                 }else {
    101                     System.out.println("不存在该学生!请重新查找");
    102 }
    103             }break;
    104             case 0:
    105                 statu = 0; break;
    106             default:
    107                 System.out.println("输入错误");
    108 }
    109         }
    110 }
    111 }
     

    结果验证如下:

     

    实验总结:
        对前三章的理论知识内容复习了一遍,对一些没有掌握的的知识再次进行了学习,而实验三确实让我费尽了脑筋也没有弄会,最后还是经过舍友的帮忙才勉强完成了虽然是他的思路,但是通过他的帮忙也学到了很多,第一次感觉到了Java学习起来真不容易,好难啊。
  • 相关阅读:
    在浏览器地址栏按回车、F5、Ctrl+F5刷新网页的区别
    RESTful 的总结
    Mvc项目部署IIS报错:没有为请求的URL配置默认文档,并且没有在服务器设置目录浏览
    Ajax的请求方式几传参的区别
    响应式布局中的CSS相对量
    理解 ES6 语法中 yield* 关键字的作用
    理解 ES6 语法中 yield 关键字的返回值
    配置IIS Express以便通过IP地址访问调试的网站
    在IntelliJ IDEA 13中配置OpenCV的Java开发环境
    iOS UITableView获取cell的indexPath及cell内部按钮点击事件处理
  • 原文地址:https://www.cnblogs.com/zd0421/p/9657781.html
Copyright © 2011-2022 走看看