posts - 14,  comments - 7,  trackbacks - 0
          要求:寫一個有關(guān)股票的java小程序,寫出相關(guān)屬性,實現(xiàn)簡單的幾個方法,作為java初學(xué)者,簡單明了的感受一下項目--

          具體程序為:

          package com.dr.stock;

          public class Stock {
           private String name;
           private int price;
           private int id;
           private int flag;
           /**
            * @return the name
            */
           public String getName() {
            return name;
           }
           /**
            * @param name the name to set
            */
           public void setName(String name) {
            this.name = name;
           }
           /**
            * @return the price
            */
           public int getPrice() {
            return price;
           }
           /**
            * @param price the price to set
            */
           public void setPrice(int price) {
            this.price = price;
           }
           /**
            * @return the id
            */
           public int getId() {
            return id;
           }
           /**
            * @param id the id to set
            */
           public void setId(int id) {
            this.id = id;
           }
           /**
            * @return the flag
            */
           public int getFlag() {
            return flag;
           }
           /**
            * @param flag the flag to set
            */
           public void setFlag(int flag) {
            this.flag = flag;
           }

          }         
          這個類列出了股票的幾個屬性,下面是股票server和client端的類代碼,在client端調(diào)用服務(wù)器端的方法,從而得到一些信息。

          package com.dr.stock;

          import java.util.Random;

          public class StockServer {
           public static Stock[] getStock(){
            Stock[] stock = new Stock[3];
            Random rd = new Random();  
            //##############################
            Stock sk1 = new Stock();
            sk1.setName("ibm");
            sk1.setPrice(rd.nextInt(100));
            sk1.setId(1);
            sk1.setFlag(1);
             stock[0] = sk1;
            //###############################
            Stock sk2 = new Stock();
            sk2.setName("sun");
            sk2.setPrice(rd.nextInt(200));
            sk2.setId(2);
            sk2.setFlag(2);
            
             stock[1] = sk2;
            //##################################
            Stock sk3 = new Stock();
            sk3.setName("sico");
            sk3.setPrice(rd.nextInt(300));
            sk3.setId(3);
            sk3.setFlag(3);
             stock[2] = sk3;
            return stock;
            
           }
             }

          package com.dr.stock;

          import java.util.Random;

          public class StockClient {

           
           public static void main(String[] args) {
            
            while(true){
             Stock[] sk = StockServer.getStock();
             
             for(int i = 0;i<sk.length;i++){
              if(sk[i] != null)
                System.out.println("股票名字:"+sk[i].getName()+"    股票價格:"+sk[i].getPrice()+"    股票ID:"+sk[i].getId()+"    股票類型"+sk[i].getFlag());
             }
             try{
              Thread.sleep(2000);
             }catch(InterruptedException e){
              e.printStackTrace();
              break;
             }
            }
           }
              }
           

           


           


           

          posted on 2010-10-08 21:51 迷人笑笑 閱讀(416) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          <2010年10月>
          262728293012
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          常用鏈接

          留言簿(13)

          隨筆檔案

          文章檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 三河市| 浦县| 乌海市| 鹰潭市| 贵德县| 靖宇县| 阿尔山市| 曲麻莱县| 金华市| 湖南省| 右玉县| 长春市| 天长市| 炉霍县| 杭锦旗| 建德市| 静安区| 常熟市| 黔南| 华宁县| 丰顺县| 铁岭县| 施甸县| 尤溪县| 奇台县| 汪清县| 沾益县| 临城县| 新密市| 安徽省| 常宁市| 景泰县| 鹤壁市| 师宗县| 岳普湖县| 广元市| 平利县| 都匀市| 潮安县| 禹城市| 九江县|