欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    软件设计与体系结构实验指导书2014(共41页).doc

    • 资源ID:14495919       资源大小:230KB        全文页数:41页
    • 资源格式: DOC        下载积分:20金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要20金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    软件设计与体系结构实验指导书2014(共41页).doc

    精选优质文档-倾情为你奉上专心-专注-专业实验一 经典软件体系结构风格(一)实验目的(1)理解管道-过滤器软件体系结构、面向对象软件体系结构的原理(2)掌握管道-过滤器软件体系结构、面向对象软件体系结构的实例(3)管道-过滤器软件体系结构、面向对象软件体系结构的编程实现实验内容1管道-过滤器软件体系结构(1)在dos提示符下输入下面的命令:dir | more使得当前目录列表在屏幕上逐屏显示。dir的输出的是整个目录列表,它不出现在屏幕上而是由于符号“|”的规定,成为下一个命令more的输入,more命令则将其输入一屏一屏地显示,成为命令行的输出。(2)Java I/O流中的管道流类PipedInputStream和PipedOutputStream可以方便地实现管道-过滤器体系结构,这两个类的实例对象要通过connect方法连接。下面程序的功能是sender发送“Hello,receiver! Im sender”给receiver,然后receiver接受后显示出来并且在前面加上“the following is from sender”的信息。管道流内部在实现时还有大量的对同步数据的处理,管道输出流和管道输入流执行时不能互相阻塞,所以一般要开启独立线程分别执行,顺便复习了多线程操作。import java.io.*;import java.util.*;public class TestPipedpublic static void main(String args)sender s = new sender();receiver r = new receiver(); PipedOutputStream out = s.getOut(); PipedInputStream in = r.getIn(); try in.connect(out); s.start(); r.start(); catch(Exception e) e.printStackTrace(); class sender extends Thread PipedOutputStream out = new PipedOutputStream(); public PipedOutputStream getOut() return out; public void run() String str = "Hello,receiver ! Im sendern" try out.write(str.getBytes(); out.close(); catch(Exception e) e.printStackTrace(); class receiver extends Thread PipedInputStream in = new PipedInputStream(); public PipedInputStream getIn() return in; public void run() byte buf = new byte1024; try int len = in.read(buf); System.out.println("the following is from sender:n"+new String(buf,0,len); in.close(); catch(Exception e) e.printStackTrace(); 程序的执行结果: the following is from sender:Hello,receiver ! Im sender2数据抽象和面向对象软件体系结构有一个已知的二维坐标系,在坐标系中定义了若干种规则的图形:圆、正方形、矩形和椭圆。使用Java语言进行面向对象的程序设计:(1)首先考虑数据封装性,(2)考虑继承性,(3)考虑抽象类。abstract class Graphprotected double x,y;/ x,y是规则图形的中心点坐标 public Graph(double x,double y)/ 构造函数初始化中心点坐标 this.x=x; this.y=y; protected void changeX(double x)/ 修改横坐标 this.x=x; protected void changeY(double y)/ 修改纵坐标 this.y=y; public abstract double area();/ 计算面积的抽象方法class MySquare extends Graph private double length; public MySquare(double x,double y,double length) super(x,y); this.length=length; protected void changLength(double length) / 修改边长length this.length=length; public double area() return length*length; class MyCircle extends Graph private double radius; public MyCircle(double x,double y,double radius) super(x,y); this.radius=radius; protected void changRadius(double radius) / 修改半径radius this.radius=radius; public double area() return 3.1416*radius*radius; class MyRectangle extends Graph private double a,b; public MyRectangle(double x,double y,double a,double b) super(x,y); this.a=a; this.b=b; protected void changLength(double length) / 修改长length a=length; protected void changWidth(double width) / 修改宽width b=width; public double area() return a*b; class MyEllipse extends Graph private double a,b; public MyEllipse (double x,double y,double a,double b) super(x,y); this.a=a; this.b=b; protected void changA(double a) / 修改长轴a this.a=a; protected void changB(double b) / 修改短轴b this.b=b; public double area() return 3.1416*a*b; public class Area public static void main (String arg)MyCircle c=new MyCircle(1,1,3); MySquare s=new MySquare(2,2,4); MyRectangle r=new MyRectangle(12,9,1,2); MyEllipse e=new MyEllipse(2,-1,3,2); System.out.println("圆c的面积是"+c.area(); System.out.println("正方形s的面积是"+s.area(); System.out.println("矩形r的面积是"+r.area(); System.out.println("椭圆e的面积是"+e.area(); 该程序的运行结果为: 圆c的面积是28.2744正方形s的面积是16.0矩形r的面积是2.0椭圆e的面积是18.8496思考与提高1、管道-过滤器软件体系结构与批处理软件体系结构的区别和联系是什么?2、面向对象软件体系结构与主程序-子程序软件体系结构的区别和联系是什么?实验二 经典软件体系结构风格(二)实验目的(1)理解基于事件的隐式调用软件体系结构、层次软件体系结构的原理(2)掌握事件的隐式调用软件体系结构、层次软件体系结构的实例(3)事件的隐式调用软件体系结构、层次软件体系结构的编程实现实现内容1基于事件的隐式调用风格常用控制组件的事件按钮与动作事件(ActionEvent),参见下例。按钮与动作事件运行结果import java.awt.*;import java.awt.event.*; /引入java.awt.event包处理事件class BtnLabelAction extends Frame implements ActionListener/声明窗口类(BtnLabelAction)并实现动作事件接口(ActionListener)Label prompt;Button btn;void CreateWindow() /自定义方法setTitle("MyButton");prompt = new Label("你好");/创建标签对象btn = new Button("操作");/创建按钮对象setLayout(new FlowLayout();/布局设计,用于安排按钮、标签的位置add(prompt);/将标签放入容器add(btn);/将按钮放入容器btn.addActionListener(this);/将监听器(窗体对象本身)注册给按钮对象setSize(300,100);setVisible(true);public void actionPerformed(ActionEvent e)/接口ActionListener的事件处理方法if(e.getSource()=btn) /判断动作事件是否是由按钮btn引发的if(prompt.getText()="你好")prompt.setText("再见");elseprompt.setText("你好"); public class BtnTestpublic static void main (String args)BtnLabelAction bla=new BtnLabelAction();bla.CreateWindow(); 2层次软件体系结构基于层次软件体系结构的软件测试系统。第一层为用户图形界面层import java.awt.*;import java.util.*;import javax.swing.*;import java.awt.event.*;import com.sun.java.swing.plaf.windows.*;public class TestingGUI extends JPanel private JTextArea txtTestInfo, txtTestcase; private JLabel lblTestcases; private JPanel buttonPanel; private JComboBox cmbTestcases; private static final String CASE_BUBBLE= "TC1-Test Bubble Sort" private static final String CASE_HEAP= "TC2-Test Heap Sort" private static final String CASE_INSERTION= "TC3-Test Insertion Sort" private static final String EXECUTE = "Execute" private static final String EXIT = "Exit" public TestingGUI() txtTestInfo=new JTextArea("Test output from source shown heren", 6, 20); txtTestInfo.setLineWrap(true); txtTestcase = new JTextArea("Testcase info and test validation shown heren", 4, 15); txtTestcase.setLineWrap(true); buildUpScrollGUI(); private void buildUpScrollGUI() setUpButtonPanel(); JScrollPane btnPane = new JScrollPane(buttonPanel); JScrollPane textPane = new JScrollPane(txtTestcase); textPane.setMinimumSize(new Dimension(250, 150); JScrollPane testDataPane = new JScrollPane(txtTestInfo); JSplitPane upSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); upSplitPane.setLeftComponent(btnPane); upSplitPane.setRightComponent(testDataPane); JScrollPane downPane = new JScrollPane(textPane); Dimension minimumSize = new Dimension(130, 100); btnPane.setMinimumSize(minimumSize); textPane.setMinimumSize(new Dimension(100, 100); upSplitPane.setDividerLocation(270); upSplitPane.setPreferredSize(new Dimension(500, 300); JSplitPane bigSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, upSplitPane, downPane); bigSplitPane.setDividerLocation(190); add(bigSplitPane); setSize(new Dimension(500, 400); setVisible(true); private void setUpButtonPanel() lblTestcases = new JLabel("Test Cases:"); cmbTestcases = new JComboBox(); cmbTestcases.addItem(CASE_BUBBLE); cmbTestcases.addItem(CASE_HEAP); cmbTestcases.addItem(CASE_INSERTION); /Create the open button JButton executeBtn = new JButton(EXECUTE); executeBtn.setMnemonic(KeyEvent.VK_S); JButton exitButton = new JButton(EXIT); exitButton.setMnemonic(KeyEvent.VK_X); BtnListener objButtonHandler = new BtnListener(); / add action Listener executeBtn.addActionListener(objButtonHandler); exitButton.addActionListener(objButtonHandler); buttonPanel = new JPanel(); GridBagLayout gridbag = new GridBagLayout(); buttonPanel.setLayout(gridbag); GridBagConstraints gbc = new GridBagConstraints(); buttonPanel.add(lblTestcases); buttonPanel.add(cmbTestcases); buttonPanel.add(executeBtn); buttonPanel.add(exitButton); gbc.insets.top = 5; gbc.insets.bottom = 5; gbc.insets.left = 5; gbc.insets.right = 5; gbc.anchor = GridBagConstraints.EAST; gbc.gridx = 0; gbc.gridy = 0; gridbag.setConstraints(lblTestcases, gbc); gbc.anchor = GridBagConstraints.WEST; gbc.gridx = 1; gbc.gridy = 0; gridbag.setConstraints(cmbTestcases, gbc); gbc.anchor = GridBagConstraints.EAST; gbc.insets.left = 2; gbc.insets.right = 2; gbc.insets.top = 25; gbc.anchor = GridBagConstraints.EAST; gbc.gridx = 0; gbc.gridy = 7; gridbag.setConstraints(executeBtn, gbc); gbc.anchor = GridBagConstraints.WEST; gbc.gridx = 1; gbc.gridy = 7; gridbag.setConstraints(exitButton, gbc); public void showTestInfo(int str ) txtTestInfo.setText(""); for(int n=0; n< str.length; n+) txtTestInfo.append(""+strn+" "); public void showErrors(String err) txtTestcase.append(err+"n"); public String getSelectedTestcase() return (String) cmbTestcases.getSelectedItem(); class BtnListener implements ActionListener private Testcase test; private String selectedTestcase; public void actionPerformed(ActionEvent e) String searchResult = null; int output=null; if (e.getActionCommand().equals(EXIT) System.exit(1); if (e.getActionCommand().equals(EXECUTE) selectedTestcase = getSelectedTestcase(); if(selectedTestcase.equals(CASE_BUBBLE) test = new TestcaseBubble(); else if(selectedTestcase.equals(CASE_HEAP) test = new TestcaseHeap(); else if(selectedTestcase.equals(CASE_INSERTION) test = new TestcaseInsertion(); output = test.execute(3000); showTestInfo(output); showErrors(selectedTestcase); boolean result = ResultVerification.isResultCorrect(output ); showErrors("No Error found = " +result); long timeTaken = test.getTimeTaken(); showErrors("Testing Time takes = " + timeTaken+"n"); / End of class BtnListener private static void createAndShowGUI() JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("Layered Architecture- Software Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); TestingGUI newContentPane = new TestingGUI(); newContentPane.setOpaque(true); frame.setContentPane(newContentPane); frame.pack(); frame.setVisible(true); static public void main(String argv) javax.swing.SwingUtilities.invokeLater(new Runnable() public void run() createAndShowGUI(); ); public class ResultVerification static boolean flag = true; public static boolean isResultCorrect(int arr) for(int k=0; k<arr.length-1; k+) if(arrk > arrk+1) flag=false; System.out.println("error "+ k); /break; return flag; 第二层为测试案例层,包括软件测试工程师所编写的测试案例public interface Testcase public abstract int execute(int len); public abstract long getTimeTaken();class Context SortAlgorithm alg; / Constructor public Context(SortAlgorithm alg) this.alg = alg; public int sortIntArray(int a) return this.alg.sort(a); import java.util.Random;public class IntegerArrGenerator public static int generateInput(int len) int input= new intlen; Random r = new Random(); for(int m=0; m< len; m+) inputm = r.nextInt(len); return input; import java.util.*;public class TestcaseBubble implements Testcase private long startTime; private long timeTaken=0; public int execute(int len) startTime = System.currentTimeMillis(); int input = IntegerArrGenerator.generateInput(len); SortAlgorithm sa = new BubbleSort(); Context context = new Context(sa); int intArray = context.sortIntArray(input); timeTaken = System.currentTimeMillis() - startTime; return intArray; public long getTimeTaken() return timeTaken;import java.util.*;public class TestcaseHeap implements Testcase /static long time; private long startTime; private long timeTaken=0; public int execute(int len)startTime = System.currentTimeMillis();int input = IntegerArrGenerator.generateInput(len);SortAlgorithm sa = new HeapSort();Context context = new Context(sa);int intArray = context.sortIntArray(input);timeTaken = System.currentTimeMillis()-startTime; return intArray; public long getTimeTaken() return timeTaken;import java.util.*;public class TestcaseInsertion implements Testcase private long startTime; private long timeTaken=0; public int execute(int len) startTime = System.currentTimeMillis(); int input = IntegerArrGenerator.generateInput(len); SortAlgorithm sa = new InsertSort(); Context context = new Context(sa); int intArray = context.sortIntArray(input); timeTaken = System.currentTimeMillis()-startTime; return intArray; public long getTimeTaken() return timeTaken;第三层为被测试软件层(排序算法)public interface SortAlgorithm int sort(int nums);public class BubbleSort implements SortAlgorithm public int sort(int nums) for(int i = nums.length; -i >= 0;) for(int j = 0; j < i; j+) if(numsj > numsj + 1) /exchange numsj+1 with numsj int T = numsj; numsj = numsj + 1; numsj + 1 = T; return nums; public class HeapSort implements SortAlgorithm public int sort(int nums ) for(int i=nums.length; i>1; i-) buildBinaryHeapTree(nums, i - 1); swapLeadingNodeWithLastNode(nums, i - 1); return nu

    注意事项

    本文(软件设计与体系结构实验指导书2014(共41页).doc)为本站会员(飞****2)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开