質問編集履歴

4

修正

2019/01/23 08:08

投稿

irm
irm

スコア25

test CHANGED
File without changes
test CHANGED
@@ -124,7 +124,7 @@
124
124
 
125
125
  int i = 0;
126
126
 
127
- int numberOfSouvenirs = SouvenirDistribution.Distribute(totalSouvenirs,names);
127
+ int numberOfSouvenirs = sd.Distribute(totalSouvenirs,names);
128
128
 
129
129
  for(i = 0; i < names.Count; i++)
130
130
 

3

修正

2019/01/23 08:08

投稿

irm
irm

スコア25

test CHANGED
File without changes
test CHANGED
@@ -146,8 +146,6 @@
146
146
 
147
147
  こちらが、Personクラスです。
148
148
 
149
-
150
-
151
149
  ```C#
152
150
 
153
151
  public class Person
@@ -198,4 +196,4 @@
198
196
 
199
197
  }
200
198
 
201
- ``
199
+ ```

2

Personクラスと、メインウィンドウでのDistributeメソッドの使われ方を追加しました。

2019/01/23 08:06

投稿

irm
irm

スコア25

test CHANGED
File without changes
test CHANGED
@@ -97,3 +97,105 @@
97
97
 
98
98
 
99
99
  ```
100
+
101
+
102
+
103
+
104
+
105
+ メインウィンドウ内のDistributeメソッド適用箇所です↓BtnDivide_Clickは、ボタンにより分配が実行されます。
106
+
107
+ ```C#
108
+
109
+ //nameとageプロパティが入っています↓
110
+
111
+ List<Person> names = new List<Person>();
112
+
113
+
114
+
115
+ private void BtnDivide_Click(object sender, RoutedEventArgs e)
116
+
117
+ {
118
+
119
+ SouvenirDistribution sd = new SouvenirDistribution();
120
+
121
+ int totalSouvenirs = int.Parse(TxtTotalSouvenirs.Text);
122
+
123
+
124
+
125
+ int i = 0;
126
+
127
+ int numberOfSouvenirs = SouvenirDistribution.Distribute(totalSouvenirs,names);
128
+
129
+ for(i = 0; i < names.Count; i++)
130
+
131
+ {
132
+
133
+  //Personクラス内のToString()メソッド内の内容で構成された人名リストに、お土産の分配数が追加される形です。
134
+
135
+ NameList.Items[i] += $" {numberOfSouvenirs} 個";
136
+
137
+
138
+
139
+ }
140
+
141
+
142
+
143
+ ```
144
+
145
+
146
+
147
+ こちらが、Personクラスです。
148
+
149
+
150
+
151
+ ```C#
152
+
153
+ public class Person
154
+
155
+ {
156
+
157
+
158
+
159
+ //プロパティ
160
+
161
+ public int Age { get; set; }
162
+
163
+ public string FirstName { get; set; }
164
+
165
+ public string LastName { get; set; }
166
+
167
+ public string Name { get; set; }
168
+
169
+
170
+
171
+ //コンストラクタ
172
+
173
+ public Person(string name, int age)
174
+
175
+ {
176
+
177
+ Age = age;
178
+
179
+ Name = name;
180
+
181
+ }
182
+
183
+
184
+
185
+ // 名前リストに表示される内容 「名前,年齢才」
186
+
187
+ public override string ToString()
188
+
189
+ {
190
+
191
+ return Name + ", " + Age + "才";
192
+
193
+
194
+
195
+ }
196
+
197
+
198
+
199
+ }
200
+
201
+ ``

1

タイトル変更したつもりが変更できていませんでした。

2019/01/23 08:05

投稿

irm
irm

スコア25

test CHANGED
@@ -1 +1 @@
1
- public virtual double UseCredit(double creditLimit, double amountSpent, double cr) {
1
+ お土産を分配するためのクラス
test CHANGED
File without changes