77范文网 - 专业文章范例文档资料分享平台

上机实验指导书-面向对象程序设计(4)

来源:网络收集 时间:2019-03-09 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

//由字符输入流对象生成缓冲输入流(或串输入流)对象bin int i,w; /*w开关量 和 中间量*/ int a[]=new int[10]; boolean b;

for(i=0;i<10;i++)

{ System.out.println(\输入第\个整数\ do{/*判断是否是空串 如 是则重新输入*/ w=1;

try{ /*建立一个异常捕获*/

a[i] = Integer.parseInt(bin.readLine());

/*Integer.parseInt(str)- str 转成 int整形; bin.readLine() - 从系统输入缓冲区读入字符流给buf缓冲区 并返回字符串 */

}

__________________/*捕获“输入数据格式”异常*/ {

System.out.println(\数据输入错误请重新输入\处理异常*/ w = 0; }

}while(w==0); }

System.out.println(\您输入的数组是:\ for(i=0; i<10; i++)/*输出原数组*/ {

System.out.print(a[i]+\ }

for(i=0; i<5; i++)/*对换*/ {

w = a[i];

a[i] = a[9-i]; a[9-i] = w; }

System.out.println(\对换后的数组是:\ for(i=0; i<10; i++)/*输出对换后数组*/ {

System.out.print(a[i]+\ }

System.out.println(); } }

程序运行结果:

2,P153第8题 import java.io.*;

public class P153_8 {

public static void main(String[] args) throws IOException{ String name,xuehao,temp; int score;

float average=0,max=0,min=0,n=0; InputStreamReader iin=new InputStreamReader(System.in); BufferedReader bin= new BufferedReader(iin);

FileWriter fout=new FileWriter(new File(\ BufferedWriter bfout=new BufferedWriter(fout);

boolean endch=true;//输入是否结束开关:名字为空串时结束输入。 while(endch)

{ System.out.println(\ name=bin.readLine();

if(_______________) //名字为空串时结束输入。

{endch=false;continue;}

System.out.println(\ xuehao=bin.readLine();

System.out.println(\

score=Integer.parseInt(bin.readLine());

if(score<0||score>100) //抛出非法参数错误,提示“score data error” __________________________________

bfout.write(name); bfout.newLine(); bfout.write(xuehao); bfout.newLine();

bfout.write(String.valueOf(score)); bfout.newLine(); }

bfout.close();

FileReader fin=new FileReader(new File(\ BufferedReader bfin=new BufferedReader(fin); System.out.println(\ temp=bfin.readLine();

while(__________________) //读取字符串指针为空null时,结束文件读取 { System.out.print(\ temp=bfin.readLine();

System.out.print(\ temp=bfin.readLine();

System.out.println(\ average+=Integer.parseInt(temp); n++;

______________________ //读入下一行字符串 }

bfin.close();

average/=n;

System.out.println(\ } }

程序运行结果:

文本文件名称:

文本文件内容(用记事本打开,用图片粘贴):

参考答案:

import java.io.*; throws IOException

temp!=null

name.compareTo(\

new InputStreamReader(System.in); iin

catch (NumberFormatException e)

temp=bfin.readLine();

throw new IllegalArgumentException(\

第九次上次作业 图形用户界面

实验目的:

了解AWT的概念,掌握其初步使用

掌握三种布局管理的异同及使用条件(或场合)

掌握基于Windows编程的程序的运行机制:事件驱动。

掌握Java的事件驱动实现机制与实现流程 实验要求: 实验内容:

1,请设计一个如下图的GUI,不必实作事件接口。

import java.awt.*;

public class document extends Frame {

document() {

setLayout(new BorderLayout());/*窗口布局*/ Panel pan1 = new Panel();/*容器*/

pan1.setLayout(new GridLayout(3,1,0,5));/*容器布局*/ Panel pan2 = new Panel();/*容器*/

pan2.setLayout(new FlowLayout());/*容器布局*/ Panel pan3 = new Panel();/*容器*/

pan3.setLayout(new FlowLayout());/*容器布局*/ Button but1 = new Button(\检查\按钮*/ Button but2 = new Button(\搜索\ Button but3 = new Button(\选项\ Button but4 = new Button(\存档\ Button but5 = new Button(\取消\ Button but6 = new Button(\求助\

Label lab = new Label(\输入文字\标签*/ TextArea ta = new TextArea();/*文本框*/ pan1.add(but1);/*加载到容器1*/ pan1.add(but2); pan1.add(but3);

pan2.add(but4);/*加载到容器2*/ pan2.add(but5); pan2.add(but6);

pan3.add(lab);/*加载到容器3*/

add(pan1,\加载到窗口 布局位置*/ add(pan2,\ add(pan3,\ add(ta,\

setSize(300,150);/*窗口大小*/ setVisible(true);

}

public static void main(String[] args) { document doc=new document(); // TODO, add your application code //System.out.println(\ } } 或者:

import java.awt.*; public class document

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

Frame fr=new Frame();

fr.setLayout(new BorderLayout());/*窗口布局*/ Panel pan1 = new Panel();/*容器*/

pan1.setLayout(new GridLayout(3,1,0,5));/*容器布局*/ Panel pan2 = new Panel();/*容器*/

pan2.setLayout(new FlowLayout());/*容器布局*/ Panel pan3 = new Panel();/*容器*/

pan3.setLayout(new FlowLayout());/*容器布局*/ Button but1 = new Button(\检查\按钮*/ Button but2 = new Button(\搜索\ Button but3 = new Button(\选项\ Button but4 = new Button(\存档\ Button but5 = new Button(\取消\ Button but6 = new Button(\求助\

Label lab = new Label(\输入文字\标签*/ TextArea ta = new TextArea();/*文本框*/ pan1.add(but1);/*加载到容器1*/ pan1.add(but2); pan1.add(but3);

pan2.add(but4);/*加载到容器2*/ pan2.add(but5); pan2.add(but6);

pan3.add(lab);/*加载到容器3*/

fr.add(pan1,\加载到窗口 布局位置*/ fr.add(pan2,\

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库上机实验指导书-面向对象程序设计(4)在线全文阅读。

上机实验指导书-面向对象程序设计(4).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/505219.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: