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

          具體程序為:

          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端調用服務器端的方法,從而得到一些信息。

          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)  編輯  收藏

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


          網站導航:
           
          <2010年10月>
          262728293012
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          常用鏈接

          留言簿(13)

          隨筆檔案

          文章檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 玉门市| 芜湖市| 洛隆县| 乌兰浩特市| 宣威市| 巴塘县| 丰县| 仁寿县| 奉贤区| 龙门县| 河西区| 乐平市| 苍梧县| 瑞安市| 南召县| 黄梅县| 孝感市| 江门市| 苍梧县| 甘洛县| 资源县| 公安县| 怀远县| 海兴县| 康乐县| 三原县| 文昌市| 淮阳县| 鄂伦春自治旗| 垣曲县| 蛟河市| 尚义县| 安仁县| 沙湾县| 夏津县| 剑川县| 西盟| 虎林市| 祁东县| 蒲江县| 洱源县|