JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
作者 請問大大 關於封裝的問題
heyipomoea





發文: 40
積分: 0
於 2013-05-01 22:00 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我的Code如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package Practice;
 
  class CCircle{
    private int intArea1;
    private double doubleArea1;
    private int intArea2;
    private double doubleArea2;
    
    private int radius;
    private int Longaxis;
    private int Shortaxis;
    private int PI = (int)3.14;
    
    
    private void CalArea(int r){
        radius = r = 10;
        intArea1 = radius * radius * PI;
    }
    
    private void CalArea(double r){
      double radius =  r = 5.5;
      doubleArea1 = radius * radius * PI;
    }
    
    private void CalArea(int a, int b){
      Longaxis = a = 12;
      Shortaxis = b = 8;
      intArea2 = a * b * PI;
    }
    
    private void CalArea(double a, double b){
      double Longaxis = a = 10.5;
      double Shortaxis = b = 7.2;
      doubleArea2 = a * b * PI;
    }
    
    public int GetintArea1(){
      return intArea1;
    }
    
    public double GetdoubleArea1(){
      return doubleArea1;
    }
    
    public int GetintArea2(){
      return intArea2;
    }
    
    public double GetdoubleArea2(){
      return doubleArea2;
    }
  }
  
public class P6_32Six {
  public static void main(String[] args){
    CCircle cir = new CCircle();
    System.out.println("半徑 = 10");
    System.out.println(cir.GetintArea1());
    System.out.println("長軸 = 12, 短軸 = 8");
    System.out.println(cir.GetintArea2());
    System.out.println("半徑 = 5.5");
    System.out.println(cir.GetdoubleArea1());
    System.out.println("長軸 = 10.5, 短軸 = 7.2");
    System.out.println(cir.GetdoubleArea2());
  }
}


輸出如下:
半徑 = 10
0
長軸 = 12, 短軸 = 8
0
半徑 = 5.5
0.0
長軸 = 10.5, 短軸 = 7.2
0.0


為什麼沒有輸出正確計算後的值....都只輸出0值...?

我return的值也在local內阿...

有大大可以幫我給我Hit嘛??

感謝萬分


reply to postreply to post
作者 Re:請問大大 關於封裝的問題 [Re:heyipomoea]
okuimegumi





發文: 27
積分: 0
於 2013-05-02 10:36 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你的 intArea1, doubleArea1, intArea2, doubleArea2
都沒有給值當然是0
CalArea不是放好看的...


reply to postreply to post
真正的高手,是懂得分享自己所知,並樂於教導和提攜後進,而不是一昧的落井下石。
有心向學的,應該是了解問題核心,並能夠查詢和描述問題,而不是一昧的要求解答。
作者 Re:請問大大 關於封裝的問題 [Re:heyipomoea]
yahoo1234tw





發文: 668
積分: 0
於 2013-05-02 14:24 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
heyipomoea wrote:
有大大可以幫我給我Hit嘛??

既然要hit就用力hit吧


reply to postreply to post
專業的職業演員不會站在路邊演白戲,但是這裡有很多以寫程式為業的人很喜歡作賤自己跟別人,沒事就免費幫一些懶學生寫作業。
作者 Re:請問大大 關於封裝的問題 [Re:okuimegumi]
heyipomoea





發文: 40
積分: 0
於 2013-05-02 16:25 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
可是我在CalArea中有給radius = r = 10 <==給半徑值

然後又在裡面計算出值傳給intArea1

最後在用GetintArea1將值return出來.

我的觀念是這樣想.

可以請問哪裡出錯嗎...

不好意思麻煩了

非常感謝您


reply to postreply to post
作者 Re:請問大大 關於封裝的問題 [Re:heyipomoea]
s932819





發文: 30
積分: 0
於 2013-05-02 16:58 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你連門(CalArea)都沒敲,門裡的人哪會理你~

reply to postreply to post
作者 Re:請問大大 關於封裝的問題 [Re:heyipomoea]
okuimegumi





發文: 27
積分: 0
於 2013-05-02 18:05 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
CalArea 有給r值
但是你並沒有 call CalArea這個method

簡單的說
先呼叫 CalArea 這個method
r才會賦值
intArea1才會去計算結果
GetintArea1才會拿到有值的結果


reply to postreply to post
真正的高手,是懂得分享自己所知,並樂於教導和提攜後進,而不是一昧的落井下石。
有心向學的,應該是了解問題核心,並能夠查詢和描述問題,而不是一昧的要求解答。
作者 Re:請問大大 關於封裝的問題 [Re:okuimegumi]
heyipomoea





發文: 40
積分: 0
於 2013-05-04 14:19 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
okuimegumi wrote:
CalArea 有給r值
但是你並沒有 call CalArea這個method

簡單的說
先呼叫 CalArea 這個method
r才會賦值
intArea1才會去計算結果
GetintArea1才會拿到有值的結果


謝謝您...已解決


reply to postreply to post
作者 Re:請問大大 關於封裝的問題 [Re:okuimegumi]
heyipomoea





發文: 40
積分: 0
於 2013-05-04 16:30 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
okuimegumi wrote:
CalArea 有給r值
但是你並沒有 call CalArea這個method

簡單的說
先呼叫 CalArea 這個method
r才會賦值
intArea1才會去計算結果
GetintArea1才會拿到有值的結果


謝謝您...已解決


reply to postreply to post
作者 Re:請問大大 關於封裝的問題 [Re:okuimegumi]
heyipomoea





發文: 40
積分: 0
於 2013-05-04 16:30 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
okuimegumi wrote:
CalArea 有給r值
但是你並沒有 call CalArea這個method

簡單的說
先呼叫 CalArea 這個method
r才會賦值
intArea1才會去計算結果
GetintArea1才會拿到有值的結果


謝謝您...已解決


reply to postreply to post
» JWorld@TW »  Java 新手區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8