teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

全体のコードを示します。

2020/09/25 14:28

投稿

kurokuro
kurokuro

スコア39

title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,48 @@
1
1
  現在、javaを学習しています。学習を進める中で、getメソッドを用いて、値を他メソッドに戻り値として返したかったのですが、値が反映されません。下記の変数rateをreportメソッド内に返したいです。ちなみに、変数win,loseなどは、メンバー変数として定義しています。
2
2
  ```
3
+   class BaseBallTeam {
4
+ private String name;
5
+ private int win;
3
-   public void report(){
6
+ private int lose;
7
+ private int draw;
4
8
 
9
+ public BaseBallTeam(String name,int win, int lose, int draw){
10
+ this.name = name;
11
+ this.win = win;
12
+ this.lose = lose;
13
+ this.draw = draw;
14
+ }
15
+
16
+ public String getName(){
17
+ return this.name;
18
+ }
19
+ public void setName(String name){
20
+ this.name = name;
21
+ }
22
+
23
+ public int getWin(){
24
+ return this.win;
25
+ }
26
+ public void setWin(int win){
27
+ this.win = win;
28
+ }
29
+
30
+ public int getLose(){
31
+ return this.lose;
32
+ }
33
+ public void setLose(int lose){
34
+ this.lose = lose;
35
+ }
36
+
37
+ public int getDraw(){
38
+ return this.draw;
39
+ }
40
+ public void setDraw(int draw){
41
+ this.draw = draw;
42
+ }
43
+
44
+ public void report(){
45
+
5
46
  double rate = getRate();
6
47
 
7
48
  System.out.println(name+"の2019年の成績は"+this.win+"勝"+this.lose+"敗"+this.draw+"分、勝率は"+rate+"です。");
@@ -13,4 +54,8 @@
13
54
 
14
55
  return rate;
15
56
  }
57
+
58
+
59
+ }
60
+
16
61
  ```