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

質問編集履歴

4

codeに変更

2021/08/06 03:51

投稿

oppaiboinboin17
oppaiboinboin17

スコア1

title CHANGED
File without changes
body CHANGED
@@ -35,4 +35,14 @@
35
35
  carp.show_team_result
36
36
  swallows.show_team_result
37
37
  コード
38
- ```
38
+ ```
39
+ Giants の2020年の成績は 67勝 45敗 8分、勝率は 0.5982142857142857です。
40
+ Tigers の2020年の成績は 60勝 53敗 7分、勝率は 0.5309734513274337です。
41
+ Dragons の2020年の成績は 60勝 55敗 5分、勝率は 0.5217391304347826です。
42
+ BayStars の2020年の成績は 56勝 58敗 6分、勝率は 0.49122807017543857です。
43
+ Carp の2020年の成績は 52勝 56敗 12分、勝率は 0.48148148148148145です。
44
+ Swallows の2020年の成績は 41勝 69敗 10分、勝率は 0.37272727272727274です。
45
+ と出力したいのですが
46
+ team.rb:22:in `new': wrong number of arguments (given 4, expected 0) (ArgumentError)
47
+ from team.rb:22:in `<main>'
48
+ とエラー文が出ます。なぜでしょうか?よろしくお願いいたします。

3

codeに変更

2021/08/06 03:51

投稿

oppaiboinboin17
oppaiboinboin17

スコア1

title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,4 @@
1
- ```ここに言語を入力
2
- コード
3
- # クラス定義
1
+ ```# クラス定義
4
2
  class Team
5
3
 
6
4
  # インスタンスが持つ変数(値)
@@ -35,4 +33,6 @@
35
33
  dragons.show_team_result
36
34
  baystars.show_team_result
37
35
  carp.show_team_result
38
- swallows.show_team_result
36
+ swallows.show_team_result
37
+ コード
38
+ ```

2

codeに変更

2021/08/06 03:49

投稿

oppaiboinboin17
oppaiboinboin17

スコア1

title CHANGED
File without changes
body CHANGED
@@ -1,88 +1,38 @@
1
1
  ```ここに言語を入力
2
2
  コード
3
- ```# クラス定義
3
+ # クラス定義
4
4
  class Team
5
5
 
6
6
  # インスタンスが持つ変数(値)
7
7
  attr_accessor :name, :win, :lose, :draw,
8
8
 
9
9
  # インスタンスを初期化するための、特別なメソッド
10
- def initialize
10
+ def initialize(name, win, lose, draw)
11
- self.name = "Giants"
12
- self.win = 67
13
- self.lose = 45
14
- self.draw = 8
15
- end
11
+ end
16
- def initialize
17
- self.name = "Tigers"
18
- self.win = 60
19
- self.lose = 53
20
- self.draw = 7
21
- end
22
- def initialize
23
- self.name = "Dragons"
24
- self.win = 60
25
- self.lose = 55
26
- self.draw = 5
27
- end
28
- def initialize
29
- self.name = "BayStars"
30
- self.win = 56
31
- self.lose = 58
32
- self.draw = 6
33
- end
34
- def initialize
35
- self.name = "Carp"
36
- self.win = 52
37
- self.lose = 56
38
- self.draw = 12
39
- end
40
- def initialize
41
- self.name = "Swallows"
42
- self.win = 41
43
- self.lose = 69
44
- self.draw = 10
45
- end
46
12
 
47
13
  # インスタンスが持つメソッド(処理)
48
14
  def calc_win_rate
49
15
  return win.to_f/(win+lose)
50
16
  end
51
17
 
52
- def show_team_result
18
+ def show_team_result()
53
19
  puts "#{self.name}の2020年の成績は#{self.win}勝#{self.lose}敗#{self.draw}分、勝率は#{self.calc_win_rate}"
54
20
  end
55
21
  end
56
22
 
57
23
  # インスタンスの生成と、変数への代入
58
- giants = Team.new("Giants", )
24
+ giants = Team.new("Giants", 67, 45, 8)
59
- tigers = Team.new
25
+ tigers = Team.new("Tigers", 60, 53, 7)
60
- dragons = Team.new
26
+ dragons = Team.new("Dragons", 60, 55, 5)
61
- baystars = Team.new
27
+ baystars = Team.new("Baystars", 56, 58, 6)
62
- carp = Team.new
28
+ carp = Team.new("Carp", 52, 56, 12)
63
- swallows = Team.new
29
+ swallows = Team.new("Swallows", 41, 69, 10)
64
30
 
65
31
 
66
32
  # インスタンスの使用
67
- giants.show_team_result
33
+ giants.show_team_resul
68
34
  tigers.show_team_result
69
35
  dragons.show_team_result
70
36
  baystars.show_team_result
71
37
  carp.show_team_result
72
- swallows.show_team_result
38
+ swallows.show_team_result
73
-
74
- Swallowsの2020年の成績は41勝69敗10分、勝率は0.37272727272727274
75
- Swallowsの2020年の成績は41勝69敗10分、勝率は0.37272727272727274
76
- Swallowsの2020年の成績は41勝69敗10分、勝率は0.37272727272727274
77
- Swallowsの2020年の成績は41勝69敗10分、勝率は0.37272727272727274
78
- Swallowsの2020年の成績は41勝69敗10分、勝率は0.37272727272727274
79
- Swallowsの2020年の成績は41勝69敗10分、勝率は0.37272727272727274
80
- になってしまいます。
81
-
82
- Giants の2020年の成績は 67勝 45敗 8分、勝率は 0.5982142857142857です。
83
- Tigers の2020年の成績は 60勝 53敗 7分、勝率は 0.5309734513274337です。
84
- Dragons の2020年の成績は 60勝 55敗 5分、勝率は 0.5217391304347826です。
85
- BayStars の2020年の成績は 56勝 58敗 6分、勝率は 0.49122807017543857です。
86
- Carp の2020年の成績は 52勝 56敗 12分、勝率は 0.48148148148148145です。
87
- Swallows の2020年の成績は 41勝 69敗 10分、勝率は 0.37272727272727274です。
88
- にするにはどうしたらいいでしょうか?よろしくお願いいたします。

1

codeに変更

2021/08/06 03:46

投稿

oppaiboinboin17
oppaiboinboin17

スコア1

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,6 @@
1
+ ```ここに言語を入力
2
+ コード
1
- # クラス定義
3
+ ```# クラス定義
2
4
  class Team
3
5
 
4
6
  # インスタンスが持つ変数(値)