信息工程学院1Java程序设计实验/实习报告学院:信息工程学院班级:软件工程123姓名:刘杰学号:2012013413成绩:多线程异常处理一、实验/实习过程实验题1修改实验二实验题4,声明一个局部变量Stringtext="";然后通过循环把数组中的成员(有序)添加到text中,修改方法JOptionPane.showMessageDialog();参数以显示text。实验过程:与上次实验中的实验四相同,只是添加一个局部变量Stringtext="",赋值到text中,通过JOptionPane.showMessageDialog();方法输出。实验代码:Store类:packagecn.edu.nwsuaf.jp.p4;importjava.util.Arrays;importjavax.swing.JOptionPane;importcn.edu.nwsuaf.jp.p4.data.MP3Player;importcn.edu.nwsuaf.jp.p4.data.Mobile;importcn.edu.nwsuaf.jp.p4.data.Product;publicclassStore{publicstaticvoidmain(String[]args){Mobilemobile1=newMobile("E365onChinaMobile",1780.0f);Mobilemobile2=newMobile("M330onChinaMobile",1450.0f);MP3Playerplayer1=newMP3Player("MeizoX3",256,399.0f);MP3Playerplayer2=newMP3Player("MeizoE5",512,580.0f);MP3Playerplayer3=newMP3Player("XliveXMMP3Player",256,930.0f);Product[]products={mobile1,mobile2,player1,player2,player3};Arrays.sort(products);Stringtext="";for(inta=0;a
{protectedStringname;protectedfloatprice;protectedstaticintcount;protectedProduct(Stringname,floatprice){this.name=name;this.price=price;++count;}publicStringgetName(){returnname;}publicfloatgetPrice(){returnprice;}publicstaticintgetCount(){returncount;}publicintcompareTo(Productproduct){returnnewFloat(product.getPrice()).compareTo(price);}}实验截图:实验题2用StringBuilertext="";替换Stringtext="";然后通过循环使用StringBuiler类的append方法向text中把数组中的成员(按价格有序)添加到text中,修改方法JOptionPane.showMessageDialog()的参数以显示text。运行结果如图3-1所示。图3-1思考问题:对比分析StringBuiler与String的区别。答:一个String对象的长度是固定的,不能改变它的内容,或者是附加新的字符至String对象中。您也许会使用+来串联字符串以达到附加新字符或字符串的目的,但+会产生一个新的String实例。而使用StringBuiler类中的append方法则是将新的字符串添加到已经开辟的内存中,不会增加新的内存来存放新增的字符串。使用StringBuiler类中的append方法效率比较高,并且使用StringBuiler类中的append方法可以完全替代String类。实验过程:在前面代码中使用了StringBuiler类中的append方法。实验代码:(只展示Store类)Store类:packagecn.edu.nwsuaf.jp.p4;importjava.util.Arrays;importjavax.swing.JOptionPane;importcn.edu.nwsuaf.jp.p4.data.MP3Player;importcn.edu.nwsuaf.jp.p4.data.Mobile;importcn.edu.nwsuaf.jp.p4.data.Product;publicclassStore{publicstaticvoidmain(String[]args){Mobilemobile1=newMobile("E365onChinaMobile",1780.0f);Mobilemobile2=newMobile...