王之泰《面向对象程序设计(java)》课程学习总结

第一部分:理论知识学习部分

总复习纲要

1. Java语言特点与开发环境配置(第1章、第2章)

2. Java基本程序结构(第3章)

3. Java面向对象程序结构(第4章、第5章、第6章)

4. 类、类间关系、类图

5. Java JDK预定义类/接口及其API(String-第3章、 Arrays-第3章、Files-第3章62页、LocalDate-第4章、 Object-第5章、对象包装器-第5章、Comparator-第6章、 异常类-第7章、ArrayList-第5+8章、第9章、第10-12章、 第14章)     

— Java异常处理编程模型   

—  Java GUI编程模型

6. Java并发程序设计(第14章)

7. Java应用程序部署(第13章) 

第二部分:实验部分——实验十八  总复习

实验时间 2018-12-30

1、实验目的与要求

(1) 综合掌握java基本程序结构;

(2) 综合掌握java面向对象程序设计特点;

(3) 综合掌握java GUI 程序设计结构;

(4) 综合掌握java多线程编程模型;

(5) 综合编程练习。

2、实验内容和步骤

任务1:填写课程课后调查问卷,网址:https://www.wjx.cn/jq/33108969.aspx。

任务2:综合编程练习

练习1:设计一个用户信息采集程序,要求如下:

(1)  用户信息输入界面如下图所示:

(1)用户点击提交按钮时,用户输入信息显示控制台界面;

(2)用户点击重置按钮后,清空用户已输入信息;

(3)点击窗口关闭,程序退出。

  1 package jiemian;
  2 
  3 import java.awt.EventQueue;
  4 import java.awt.event.ActionEvent;
  5 import java.awt.event.ActionListener;
  6 
  7 import javax.swing.ButtonGroup;
  8 import javax.swing.JButton;
  9 import javax.swing.JCheckBox;
 10 import javax.swing.JComboBox;
 11 import javax.swing.JFrame;
 12 import javax.swing.JLabel;
 13 import javax.swing.JPanel;
 14 import javax.swing.JRadioButton;
 15 import javax.swing.JTextArea;
 16 
 17 public class aaa {
 18 
 19     public static void main(String[] args) {
 20          EventQueue.invokeLater(() -> {
 21              JFrame frame = new FrameTest();
 22              frame.setTitle("WangZT");
 23              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 24              frame.setVisible(true);
 25           });
 26        }
 27     }
 28     class FrameTest extends JFrame {
 29          
 30          private JPanel panel;
 31          private JRadioButton JRadioButton1,JRadioButton2;
 32          private ButtonGroup ButtonGroup;
 33          private JLabel JLabel;
 34          private JTextArea fieldname,fieldadress;
 35          private JCheckBox Read,dance,sing;
 36          private JComboBox<String> JComboBox;
 37          private JButton Button1,Button2;
 38          public FrameTest() {
 39               setSize(700,500);
 40               panel=new JPanel();
 41               panel.setLayout(null);
 42               ButtonGroup=new ButtonGroup();
 43               JRadioButton1=new JRadioButton("男",false);   JRadioButton1.setBounds(130,330, 80, 50);
 44               JRadioButton2=new JRadioButton("女",false); JRadioButton2.setBounds(130,300, 80,50);
 45               ButtonGroup.add(JRadioButton1);
 46               ButtonGroup.add(JRadioButton2);
 47               addJLabel("性别:",100,300);
 48               addJLabel("姓名:",100,50);
 49               addJLabel("地址:",90,150);
 50               addJLabel("资格:",400,50);
 51               addJLabel("喜好:",400,150);
 52               
 53               fieldname=new JTextArea(1,1);fieldname.setBounds(150,70, 120, 30);fieldname.setLineWrap(true);
 54               fieldadress=new JTextArea(5,3);fieldadress.setBounds(150,160, 130, 100);fieldadress.setLineWrap(true);
 55               Read=new JCheckBox("读书");Read.setBounds(450,160,100,30);
 56               dance=new JCheckBox("跳舞");dance.setBounds(450,180,100,30);
 57               sing=new JCheckBox("唱歌");sing.setBounds(450,200,100,30);
 58               JComboBox=new JComboBox<>();
 59               JComboBox.addItem("研究生");
 60               JComboBox.addItem("本科生");
 61               JComboBox.addItem("专科生");
 62               JComboBox.setBounds(500,65, 100, 20);
 63               Button1 = new JButton("提交");Button1.setBounds(200, 400, 100, 35);
 64               Button2 = new JButton("重置");Button2.setBounds(400, 400, 100, 35);
 65               Button1.addActionListener(new Action1());
 66               Button2.addActionListener(new Action2());
 67               
 68               panel.add(Button2);
 69               panel.add(Button1);
 70               panel.add(JComboBox);
 71               panel.add(Read);
 72               panel.add(dance);
 73               panel.add(sing);
 74               panel.add(fieldname);
 75               panel.add(fieldadress);
 76               panel.add(JRadioButton1);
 77               panel.add(JRadioButton2);
 78               add(panel);
 79      }
 80      
 81  
 82      public void addJLabel(String n,int a,int b) {
 83          JLabel = new JLabel(n);
 84          JLabel.setBounds(a,b,100,50);
 85          panel.add(JLabel);
 86      }
 87  
 88      private class Action1 implements ActionListener {
 89          public void actionPerformed(ActionEvent event) {        
 90              System.out.println("name:"+fieldname.getText()+"\n"+"address:"+fieldadress.getText());
 91              System.out.println("Qualification:"+JComboBox.getSelectedItem());
 92              System.out.println("Hobby:");
 93              if(Read.isSelected()==true)System.out.print(Read.getText());
 94              if(dance.isSelected()==true)System.out.print(dance.getText());
 95              if(sing.isSelected()==true)System.out.print(sing.getText());
 96              System.out.println("\n"+"sex:");
 97              if(JRadioButton1.isSelected()==true)System.out.println(JRadioButton1.getText());
 98              if(JRadioButton2.isSelected()==true)System.out.println(JRadioButton2.getText());
 99              System.out.println("\n");
100          }
101      } 
102          private class Action2 implements ActionListener {
103              public void actionPerformed(ActionEvent event) {        
104                  fieldname.setText(null);
105                  fieldadress.setText(null);
106                  Read.setSelected(false);
107                  dance.setSelected(false);
108                  sing.setSelected(false);
109                  ButtonGroup.clearSelection();
110                  JComboBox.setSelectedIndex(0);
111              }
112          }   
113  
114 }
View Code

练习2:采用GUI界面设计以下程序:

1.编制一个程序,将身份证号.txt 中的信息读入到内存中;

2.按姓名字典序输出人员信息;

3.查询最大年龄的人员信息;

4.查询最小年龄人员信息;

5.输入你的年龄,查询身份证号.txt中年龄与你最近人的姓名、身份证号、年龄、性别和出生地;

6.查询人员中是否有你的同乡。

7.输入身份证信息,查询所提供身份证号的人员信息,要求输入一个身份证数字时,查询界面就显示满足查询条件的查询结果,且随着输入的数字的增多,查询匹配的范围逐渐缩小。

 1 package shiwuzhou;
 2 
 3 import java.awt.Dimension;
 4 import java.awt.EventQueue;
 5 import java.awt.Toolkit;
 6 
 7 import javax.swing.JFrame;
 8 
 9 public class Out {
10 
11      public static void main (String args[])
12         {
13              Toolkit t=Toolkit.getDefaultToolkit();
14             Dimension s=t.getScreenSize(); 
15             EventQueue.invokeLater(() -> {
16                 JFrame frame = new Main1();
17                 frame.setBounds(0, 0,(int)s.getWidth(),(int)s.getHeight());
18                 frame.setTitle("第四组");
19                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
20                 frame.setVisible(true);
21              });        
22         }
23  
24 }
Out
  1 import java.awt.BorderLayout;
  2 import java.awt.event.ActionEvent;
  3 import java.awt.event.ActionListener;
  4 import java.io.BufferedReader;
  5 import java.io.File;
  6 import java.io.FileInputStream;
  7 import java.io.FileNotFoundException;
  8 import java.io.IOException;
  9 import java.io.InputStreamReader;
 10 import java.util.*;
 11 import java.util.Timer;
 12 import javax.swing.*;
 13 
 14 public class Main1 extends JFrame
 15 {
 16     private static ArrayList<Person> Personlist;
 17     
 18     
 19     Scanner scanner = new Scanner(System.in);
 20     File file = new File("D:\\身份证号.txt");
 21     
 22     private JPanel Panel;
 23     private JLabel JLabel1;
 24     private JButton Button,Button2,Button3;
 25     private JTextArea text,text1,text2,text3;
 26     boolean tru=true;
 27     
 28     
 29     
 30     public  Main1() {
 31 
 32         
 33         Panel = new JPanel();Panel.setLayout(null);
 34         Button = new JButton("1:按姓名字典序输出人员信息");
 35         Button2 = new JButton("2:查询最大年龄与最小年龄人员信息");
 36         Button3 = new JButton("查询相近年龄");
 37         JLabel1 = new JLabel("输入身份证号或者地址查询");
 38         JLabel1.setBounds(900, 50, 400, 30);
 39         
 40         text=new JTextArea(30,80);text.setBounds(50, 180, 700, 700);
 41         text1=new JTextArea(1,30);text1.setBounds(900, 80, 400, 30);
 42         text2=new JTextArea(30,80);text2.setBounds(900,180,700, 700);
 43         text3=new JTextArea(30,80);text3.setBounds(420,100,200,40);
 44        
 45         Button.addActionListener(new Action());Button.setBounds(50,50,300,40);
 46         Button2.addActionListener(new Action1());Button2.setBounds(50,100,300,40);
 47         Button3.addActionListener(new Action2());Button3.setBounds(650,100,120,40);
 48         Panel.add(JLabel1);
 49         Panel.add(Button);
 50         Panel.add(Button2);
 51         Panel.add(Button3);
 52         Panel.add(text);
 53         Panel.add(text2);
 54         Panel.add(text1);
 55         Panel.add(text3);
 56         add(Panel);
 57         
 58         
 59         Timer timer = new Timer();      
 60         TimerTask timeTask=new TimerTask() {
 61             
 62              @Override
 63             public void run()
 64              {             
 65                      // TODO Auto-generated method stub
 66                      text2.setText(null);
 67                      String place=text1.getText().toString().trim();
 68                      for (int i = 0; i <Personlist.size(); i++) 
 69                      {
 70                          
 71                          String Str=(String)Personlist.get(i).getbirthplace();
 72                          if(Str.contains(place)&&!place.equals("")) 
 73                              {
 74                              text2.append(Personlist.get(i).toString());
 75                              }  
 76                     }      
 77                      for (int i = 0; i <Personlist.size(); i++) 
 78                      {
 79                          
 80                          String Str=(String)Personlist.get(i).getID();
 81                          if(Str.contains(place)&&!place.equals("")) 
 82                              {
 83                              text2.append(Personlist.get(i).toString());
 84                              }  
 85                     }    
 86                      
 87             }
 88             
 89         };timer.schedule(timeTask, 0,100);
 90      
 91         Personlist = new ArrayList<>();       
 92         try {
 93             FileInputStream fis = new FileInputStream(file);
 94             BufferedReader in = new BufferedReader(new InputStreamReader(fis));
 95             String temp = null;
 96             while ((temp = in.readLine()) != null) {            
 97                 Scanner linescanner = new Scanner(temp);               
 98                 linescanner.useDelimiter(" ");    
 99                 String name = linescanner.next();
100                 String ID = linescanner.next();
101                 String sex = linescanner.next();
102                 String age = linescanner.next();
103                 String place =linescanner.nextLine();
104                 Person Person = new Person();
105                 Person.setname(name);
106                 Person.setID(ID);
107                 Person.setsex(sex);
108                 int a = Integer.parseInt(age);
109                 Person.setage(a);
110                 Person.setbirthplace(place);
111                 Personlist.add(Person);
112 
113             }
114         } catch (FileNotFoundException e) {
115             System.out.println("查找不到信息");
116             e.printStackTrace();
117         } catch (IOException e) {
118             System.out.println("信息读取有误");
119             e.printStackTrace();
120         }
121  
122         
123     }
124     
125     
126 
127 
128     private class Action implements ActionListener
129     {
130     public void actionPerformed(ActionEvent event)
131         {        
132          text.setText(null);
133          Collections.sort(Personlist);
134          text.append(Personlist.toString());
135         }
136 
137     }         
138 
139     private class Action1 implements ActionListener
140         {
141         public void actionPerformed(ActionEvent event)
142             {        
143             text.setText(null);
144             int max=0,min=100;int j,k1 = 0,k2=0;
145             for(int i=1;i<Personlist.size();i++)
146             {
147                 j=Personlist.get(i).getage();
148                if(j>max)
149                {
150                    max=j; 
151                    k1=i;
152                }
153                if(j<min)
154                {
155                    min=j; 
156                    k2=i;
157                }
158             }  
159             text.append("年龄最大:   "+Personlist.get(k1)+"\n"+"年龄最小:  "+Personlist.get(k2));     
160             }
161    
162         }          
163 
164     private class Action2 implements ActionListener
165     {
166     public void actionPerformed(ActionEvent event)
167         {        
168          text.setText(null);
169          int a = Integer.parseInt(text3.getText().toString().trim());         
170          int d_value=a-Personlist.get(agenear(a)).getage();
171          
172          for (int i = 0; i < Personlist.size(); i++)
173          {
174              int p=Personlist.get(i).getage()-a;
175             
176              if(p==d_value||-p==d_value) text.append(Personlist.get(i).toString());
177          } 
178         }
179 
180     } 
181     
182     
183     public static int agenear(int age) {
184         
185         int j=0,min=53,d_value=0,k=0;
186          for (int i = 0; i < Personlist.size(); i++)
187          {
188              d_value=Personlist.get(i).getage()-age;
189              if(d_value<0) d_value=-d_value; 
190              if (d_value<min) 
191              {
192                 min=d_value;
193                 k=i;
194              }
195 
196           }    return k;
197          
198       }
199 
200 }
Main1
 1 public class Person implements Comparable<Person> {
 2 private String name;
 3 private String ID;
 4 private int age;
 5 private String sex;
 6 private String birthplace;
 7 
 8 public String getname() 
 9 {
10     return name;
11 }
12 public void setname(String name) 
13 {
14     this.name = name;
15 }
16 public String getID() 
17 {
18     return ID;
19 }
20 public void setID(String ID) 
21 {
22     this.ID= ID;
23 }
24 public int getage()
25 {
26     return age;
27 }
28 public void setage(int age) 
29 {
30     this.age= age;
31 }
32 public String getsex()
33 {
34     return sex;
35 }
36 public void setsex(String sex)
37 {
38     this.sex= sex;
39 }
40 public String getbirthplace() 
41 {
42     return birthplace;
43 }
44 public void setbirthplace(String birthplace)
45 {
46     this.birthplace= birthplace;
47 }
48 
49 public int compareTo(Person o) 
50 {
51    return this.name.compareTo(o.getname());
52 }
53 
54 public String toString() 
55 {
56     return  name+"\t"+sex+"\t"+age+"\t"+ID+"\t"+birthplace+"\n";
57 
58 }
59 
60 
61 
62 }
Person

练习3:采用GUI界面设计以下程序

8.编写一个计算器类,可以完成加、减、乘、除的操作

9.利用计算机类,设计一个小学生100以内数的四则运算练习程序,由计算机随机产生10道加减乘除练习题,学生输入答案,由程序检查答案是否正确,每道题正确计10分,错误不计分,10道题测试结束后给出测试总分;

10.将程序中测试练习题及学生答题结果输出到文件,文件名为test.txt。

 1 import java.awt.Dimension;
 2 import java.awt.EventQueue;
 3 import java.awt.Toolkit;
 4 
 5 import javax.swing.JFrame;
 6 
 7 public class New {
 8 
 9      public static void main (String args[])
10         {
11              Toolkit t=Toolkit.getDefaultToolkit();
12             Dimension s=t.getScreenSize(); 
13             EventQueue.invokeLater(() -> {
14                 JFrame frame = new Demo();
15                 frame.setBounds(0, 0,(int)s.getWidth()/2,(int)s.getHeight()/2);
16                 frame.setTitle("第四组");
17                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
18                 frame.setVisible(true);
19              });        
20         }
21  
22 }
New
  1 import java.awt.Font;
  2 import java.awt.event.ActionEvent;
  3 import java.awt.event.ActionListener;
  4 import java.io.FileNotFoundException;
  5 import java.io.PrintWriter;
  6 import java.util.Collections;
  7 import java.util.Scanner;
  8 
  9 import javax.swing.*;
 10 
 11 import java.math.*;
 12 
 13 
 14 public class Demo extends JFrame {
 15     
 16     private String[] c=new String[10];
 17     private String[] c1=new String[10];
 18     private int[] list=new int[10];
 19     int i=0,i1=0,sum = 0;
 20     private PrintWriter out = null;
 21     private JTextArea text,text1;
 22     private int counter;
 23     
 24     public Demo()  {
 25         JPanel Panel = new JPanel();
 26         Panel.setLayout(null);
 27         JLabel JLabel1=new JLabel("");
 28         JLabel1.setBounds(500, 800, 400, 30);
 29         JLabel1.setFont(new Font("Courier",Font.PLAIN,35));
 30         JButton Button = new JButton("生成题目");
 31         Button.setBounds(50,150,150,50);
 32         Button.setFont(new Font("Courier",Font.PLAIN,20)); 
 33         Button.addActionListener(new Action());
 34         JButton Button2 = new JButton("确定答案");
 35         Button2.setBounds(300,150,150,50);
 36         Button2.setFont(new Font("Courier",Font.PLAIN,20));
 37         Button2.addActionListener(new Action1());
 38         JButton Button3 = new JButton("读出文件");
 39         Button3.setBounds(500,150,150,50);
 40         Button3.setFont(new Font("Courier",Font.PLAIN,20));
 41         Button3.addActionListener(new Action2());
 42          text=new JTextArea(30,80);text.setBounds(30, 50, 200, 50);
 43          text.setFont(new Font("Courier",Font.PLAIN,35));
 44          text1=new JTextArea(30,80);
 45          text1.setBounds(270, 50, 200, 50);
 46          text1.setFont(new Font("Courier",Font.PLAIN,35));
 47 
 48          Panel.add(text);
 49          Panel.add(text1);
 50 
 51          Panel.add(Button);
 52          Panel.add(Button2);
 53          Panel.add(Button3);
 54          Panel.add(JLabel1);
 55          add(Panel);
 56          
 57          
 58          
 59 
 60 
 61            
 62                   
 63     }
 64     
 65     private class Action implements ActionListener
 66     {
 67     public void actionPerformed(ActionEvent event)
 68         {        
 69         text1.setText("0");
 70         if(i<10) {
 71         
 72         int a = 1+(int)(Math.random() * 99);
 73         int b = 1+(int)(Math.random() * 99);
 74         int m= (int) Math.round(Math.random() * 3);
 75       switch(m)
 76       {
 77       case 0:
 78           while(a<b){  
 79               b = (int) Math.round(Math.random() * 100);
 80               a = (int) Math.round(Math.random() * 100); 
 81           }  
 82           c[i]=(i+":"+a+"/"+b+"=");
 83           list[i]=Math.floorDiv(a, b);
 84           text.setText(i+":"+a+"/"+b+"=");
 85           i++;   
 86           break; 
 87       case 1:
 88           c[i]=(i+":"+a+"*"+b+"=");
 89                 list[i]=Math.multiplyExact(a, b);
 90                 text.setText(i+":"+a+"*"+b+"=");        
 91            i++;
 92           break;
 93        case 2:
 94           c[i]=(i+":"+a+"+"+b+"=");
 95                 list[i]=Math.addExact(a, b);
 96           text.setText(i+":"+a+"+"+b+"=");
 97           i++;
 98           break ;
 99       case 3:
100           while(a<=b){  
101               b = (int) Math.round(Math.random() * 100);
102               a = (int) Math.round(Math.random() * 100); 
103           }    
104           c[i]=(i+":"+a+"-"+b+"=");
105           text.setText(i+":"+a+"-"+b+"=");
106           list[i]=Math.subtractExact(a, b);
107           i++;
108           break ;
109           }
110         }
111       }
112     }      
113     private class Action1 implements ActionListener
114     {
115         public void actionPerformed(ActionEvent event)
116         {    
117             if(i<10) {
118                 text.setText(null);        
119                 String daan=text1.getText().toString().trim();
120                 int a = Integer.parseInt(daan);
121                 if(text1.getText()!="") {
122                     if(list[i1]==a) sum+=10;
123                 }        
124                 c1[i1]=daan;
125                 i1++; 
126             }
127         }
128     }      
129     
130 
131     private class Action2 implements ActionListener
132     {
133         public void actionPerformed(ActionEvent event)
134             {
135          
136             try {
137                 out = new PrintWriter("text.txt");
138             } catch (FileNotFoundException e) {
139             // TODO Auto-generated catch block
140                 e.printStackTrace();
141             }
142             for(int counter=0;counter<10;counter++)
143             {
144                 out.println(c[counter]+c1[counter]);
145             }
146             out.println("成绩"+sum);
147             out.close();
148 
149             }
150 
151     }   
152 }
Demo

  

任务3:本学期课程已结束,请汇总《面向对象程序设计课程学习进度条》的数据,统计个人专业能力提升的数据。并从学习内容、学习方法、学习心得几个方面进行课程学习总结,也希望你对课程的不足提出建议和意见。

 第三部分:总结

   通过这一学期对Java程序设计这门课程的学习,不管是在知识层面还是能力提升方面,都对我有很大的帮助。尤其是在老师的积极关心和助教学长认真负责的帮助下,学到的东西不止课本上的那些知识,虽然课本的有些知识也还没吃透,但我觉得无论是老师上课为我们开拓的就业层面和未来发展层面的相关知识,还是助教学长给我们教授的编程技能。其重要性都高于课本所学的内容。所以,能通过这门课程认识两位良师益学长也可以说是非常Lucky了。

  统计这学期的个人专业能力提升数据,代码量也有个一万多行了,但是自己的能力还是很差,反思之后。首先,投入的学习时间还是太少,自主练习程度还不够。其次,没有认真进行课后反思,对自己的要求偏低。最后,指定的学习计划并没有很好的完成。  

  学习内容方面,在老师的划分梳理总结下,很厚的一本书我们有条理的循序渐进学习,成功学完大部分基础性知识。而且老师也为我们的以后发展做出了指导和引荐,让我们对自己有个大致定位和目标方向。而且,在老师新加入的学习模式当中,结对编程,助教演示,课上检测,课后答疑等都从不同方面提升我们的学习能力和专业能力。我个人觉得以后可以继续下去。

  学习方法和对大家的建议在以前的一篇博客当中总结的很完善,之后的之一段时间里也没有做太多变化,所以这里就不多废话了。

  学习心得,在我看来,学习是一个不断求知、不断探索、不断完善自己的过程,而兴趣则是最好的老师。而授课老师只是为你指引一个前进的方向,和在你走偏的时候帮你回归正道。自主学习才是王道,而老师对我们的培养也是抓住自主学习能力这一核心开展的。所谓“知之者不如好之者,好之者不如乐之者”,有了学习的兴趣,就有了学习的动力,就有信心学好一切。其次对学习要有一个正确的态度和认识。学习是成长的一部分,我们在学习中成长,同时也在成长中学习,因此我们不仅要学习新的知识,跟要学习如何做人,因为人的道德品行高于一切,人的高贵在于灵魂。只有态度端正了,目标明确了,才有前进的方向。

  我对老师不断跟进教学模式这一做法很是赞同,希望老师能将“不断革新课程模式,加入新的学习模式”,这一做法坚持下去。因为时代在变化,我们对知识的获取,学习,理解都会有着不同的变化。

  最后,祝老师学长和同窗们在新的一年继续努力,再创辉煌!

猜你喜欢

转载自www.cnblogs.com/hackerZT-7/p/10198891.html