




免费预览已结束,剩余22页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Java作业4(第九章-第十三章)第九章3.1.1程序代码import java.awt.*;import javax.swing.event.*;import javax.swing.*;import java.awt.event.*;public class kehou31 public static void main(String args) Computer fr=new Computer(); class Computer extends JFrame implements DocumentListener JTextArea text1,text2; int count=1; double sum=0,aver=0; Computer() setLayout(new FlowLayout(); text1=new JTextArea(6,20); text2=new JTextArea(6,20); add(new JScrollPane(text1); add(new JScrollPane(text2); text2.setEditable(false); (text1.getDocument().addDocumentListener(this); setSize(300,320); setVisible(true); validate(); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); public void changedUpdate(DocumentEvent e) String s=text1.getText(); String a =s.split(0123456789.+); sum=0; aver=0; for(int i=0;i=0) m=m-1; random.seek(m); int c=random.readByte(); if(c=0) System.out.print(char)c); else m=m-1; random.seek(m); byte cc=new byte2; random.readFully(cc); System.out.print(new String(cc); catch(Exception exp) 4.1.2运行界面4.2.1程序代码 import java.io.*;public class E public static void main(String args ) File file=new File(E.java); File tempFile=new File(temp.txt); try FileReader inOne=new FileReader(file); BufferedReader inTwo= new BufferedReader(inOne); FileWriter tofile=new FileWriter(tempFile); BufferedWriter out= new BufferedWriter(tofile); String s=null; int i=0; s=inTwo.readLine(); while(s!=null) i+; out.write(i+ +s); out.newLine(); s=inTwo.readLine(); inOne.close(); inTwo.close(); out.flush(); out.close(); tofile.close(); catch(IOException e) 4.3.1程序代码import java.io.*;import java.util.*;public class kehou1043 public static void main(String args) File file = new File(a.txt); Scanner sc = null; double sum=0; int count = 0; try sc = new Scanner(file); sc.useDelimiter(0123456789.+); while(sc.hasNext() try double price = sc.nextDouble(); count+; sum = sum+price; System.out.println(price); catch(InputMismatchException exp) String t = sc.next(); System.out.println(平均价格:+sum/count); catch(Exception exp) System.out.println(exp); 4.3.2运行界面第十一章2.1.1程序代码import java.sql.*;import java.util.*;public class kehou1121 public static void main(String args) Query query=new Query(); String dataSource=myData; String tableName=goods; Scanner read=new Scanner(System.in); System.out.print(输入数据源名:); dataSource = read.nextLine(); System.out.print(输入表名:); tableName = read.nextLine(); query.setDatasourceName(dataSource); query.setTableName(tableName); query.setSQL(SELECT * FROM +tableName); query.inputQueryResult(); class Query String datasourceName=; /数据源名 String tableName=; /表名 String SQL; /SQL语句 public Query() try Class.forName(sun.jdbc.odbc.JdbcOdbcDriver); catch(ClassNotFoundException e) System.out.print(e); public void setDatasourceName(String s) datasourceName = s.trim(); public void setTableName(String s) tableName = s.trim(); public void setSQL(String SQL) this.SQL = SQL.trim(); public void inputQueryResult() Connection con; Statement sql; ResultSet rs; try String uri = jdbc:odbc:+datasourceName; String id = ; String password = ; con = DriverManager.getConnection(uri,id,password); DatabaseMetaData metadata = con.getMetaData(); ResultSet rs1 = metadata.getColumns(null,null,tableName,null); int 字段个数 = 0; while(rs1.next() 字段个数+; sql = con.createStatement();/创建SQL语句 rs = sql.executeQuery(SQL);/执行SQL语句 while(rs.next() for(int k=1;k=字段个数;k+) System.out.print( +rs.getString(k)+ ); System.out.println(); con.close(); catch(SQLException e) System.out.println(请输入正确的表名+e); 2.1.2运行界面2.2.1程序代码import java.sql.*;import java.util.*;public class kehou1122 public static void main(String args) Q query = new Q(); String dataSource = myData; String tableName = goods; query.setDatasourceName(dataSource); query.setTableName(tableName); String name = ; Scanner read=new Scanner(System.in); System.out.print(商品名:); name = read.nextLine(); String str=%+name+%; String SQL = SELECT * FROM +tableName+ WHERE name LIKE +str; query.setSQL(SQL); System.out.println(tableName+表中商品名是+name+的记录); query.inputQueryResult(); class Q String datasourceName=; /数据源名 String tableName=; /表名 String SQL; /SQL语句 public Q() try Class.forName(sun.jdbc.odbc.JdbcOdbcDriver); catch(ClassNotFoundException e) System.out.print(e); public void setDatasourceName(String s) datasourceName = s.trim(); public void setTableName(String s) tableName = s.trim(); public void setSQL(String SQL) this.SQL = SQL.trim(); public void inputQueryResult() Connection con; Statement sql; ResultSet rs; try String uri = jdbc:odbc:+datasourceName; String id = ; String password = ; con = DriverManager.getConnection(uri,id,password); DatabaseMetaData metadata = con.getMetaData(); ResultSet rs1 = metadata.getColumns(null,null,tableName,null); int 字段个数 = 0; while(rs1.next() 字段个数+; sql = con.createStatement(); rs = sql.executeQuery(SQL); while(rs.next() for(int k=1;k=字段个数;k+) System.out.print( +rs.getString(k)+ ); System.out.println(); con.close(); catch(SQLException e) System.out.println(请输入正确的表名+e); 2.2.2运行界面2.3.1程序代码import java.sql.*;import java.util.*;public class kehou1123 public static void main(String args) Q1 query = new Q1(); String dataSource = myData; String tableName = goods; query.setDatasourceName(dataSource); query.setTableName(tableName); String SQL = SELECT * FROM +tableName+ ORDER BY madeTime; query.setSQL(SQL); System.out.println(tableName+表记录按商品生产日期前后排序是: ); query.inputQueryResult(); class Q1 String datasourceName=; /数据源名 String tableName=; /表名 String SQL; /SQL语句 public Q1() try Class.forName(sun.jdbc.odbc.JdbcOdbcDriver); catch(ClassNotFoundException e) System.out.print(e); public void setDatasourceName(String s) datasourceName = s.trim(); public void setTableName(String s) tableName = s.trim(); public void setSQL(String SQL) this.SQL = SQL.trim(); public void inputQueryResult() Connection con; Statement sql; ResultSet rs; try String uri = jdbc:odbc:+datasourceName; String id = ; String password = ; con = DriverManager.getConnection(uri,id,password); DatabaseMetaData metadata = con.getMetaData(); ResultSet rs1 = metadata.getColumns(null,null,tableName,null); int 字段个数 = 0; while(rs1.next() 字段个数+; sql = con.createStatement(); rs = sql.executeQuery(SQL); while(rs.next() for(int k=1;k=字段个数;k+) System.out.print( +rs.getString(k)+ ); System.out.println(); con.close(); catch(SQLException e) System.out.println(请输入正确的表名+e); 2.3.2运行界面第十二章4.1.1程序代码public class kehou1241 public static void main(String args) Cinema a=new Cinema(); a.zhang.start(); a.sun.start(); a.zhao.start(); class TicketSeller /负责卖票的类。 int fiveNumber=3,tenNumber=0,twentyNumber=0; public synchronized void sellTicket(int receiveMoney) if(receiveMoney=5) fiveNumber=fiveNumber+1; System.out.println(Thread.currentThread().getName()+给我5元钱,这是您的1张入场卷); else if(receiveMoney=10) while(fiveNumber1) try System.out.println(Thread.currentThread().getName()+靠边等); wait(); System.out.println(Thread.currentThread().getName()+结束等待); catch(InterruptedException e) fiveNumber=fiveNumber-1; tenNumber=tenNumber+1; System.out.println(Thread.currentThread().getName()+给我10元钱,找您5元,这是您的1张入场卷); else if(receiveMoney=20) while(fiveNumber1|tenNumber1) try System.out.println(Thread.currentThread().getName()+靠边等); wait(); System.out.println(Thread.currentThread().getName()+结束等待); catch(InterruptedException e) fiveNumber=fiveNumber-1; tenNumber=tenNumber-1; twentyNumber=twentyNumber+1; System.out.println(Thread.currentThread().getName()+给20元钱,找您一张5元和一张10元,这是您的1张入场卷); notifyAll(); class Cinema implements Runnable Thread zhang,sun,zhao; TicketSeller seller; Cinema() zhang=new Thread(this); sun=new Thread(this); zhao=new Thread(this); zhang.setName(张小有); sun.setName(孙大名); zhao.setName(赵中堂); seller=new TicketSeller(); public void run() if(Thread.currentThread()=zhang) seller.sellTicket(20); else if(Thread.currentThread()=sun) seller.sellTicket(10); else if(Thread.currentThread()=zhao) seller.sellTicket(5); 4.1.2运行界面4.2.1程序代码public class Example12_6 public static void main(String args) ClassRoom room6501=new ClassRoom();room6501.student1.start();room6501.teacher.start();room6501.student2.start(); class ClassRoom implements RunnableThread student1,teacher,student2;ClassRoom()teacher=new Thread(this);student1=new Thread(this);student2=new Thread(this);teacher.setName(王教授);student1.setName(张三);student2.setName(赵四);public void run()if(Thread.currentThread()=student1)trySystem.out.println(student1.getName()+正在睡觉,不听课);Thread.sleep(1000*60*60);catch(InterruptedException e)System.out.println(student1.getName()+被老师叫醒了);System.out.println(student1.getName()+开始听课);errupt();else if(Thread.currentThread()=teacher)for(int i=1;i=3;i+)System.out.println(上课!);tryThread.sleep(500);catch(InterruptedException e)errupt();else if(Thread.currentThread()=student2)trySystem.out.println(s
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年大学工会学专业题库- 工会在企业发展中的作用评估
- 2025年大学科学教育专业题库- 科学教育专业的学习成果展示
- 2024年高职单招过关检测试卷【名师系列】附答案详解
- 人防工程防爆地漏安装验收流程
- 物流运输安全控制与风险预防
- 部编版九年级语文课文深度解析
- 智能制造车间工艺改进方案
- 2025年老年医学护理技术应用模拟考试卷答案及解析
- 2025年放射诊断影像学解读技能考察答案及解析
- 光明区2025年4月广东深圳光明区政务服务数据管理局招聘一般类岗位专干2人笔试历年参考题库附带答案详解
- 物流园区规章制度模版(2篇)
- 《多能源耦合供热系统》
- 《搞定:无压工作的艺术》完整课件
- 京东方岗位胜任力测评题库
- 印刷包装公司安全生产管理方案
- 高中数学64数列求和省公开课获奖课件市赛课比赛一等奖课件
- 二手车国庆节活动方案
- 人教版八年级上册地理教学计划及进度表
- 2025高考物理步步高同步练习必修3练透答案
- DZ∕T 0215-2020 矿产地质勘查规范 煤(正式版)
- 2024年初中升学考试九年级数学专题复习新课标要求-中考33讲
评论
0/150
提交评论