私は6つのタスクを完了する必要がありますが、それらを表示する方法はわかりません。私は必要な各タスクを計算するためにすべてのコードを持っていますが、それは私のテスタークラスに適用することになると私は立ち往生しています。以下は元のクラスのコードです。これらは、実行する必要のあるタスクです。テスタークラスに2つの配列を表示
- 表に示すように、元のデータセットを表示します。
- スーパーマーケットチェーンの平均利益。
- 利益が最も高い都市。
- 平均以上の利益を持つすべての都市のリスト。
- 都市とその利益は、利益の降順で表示されます。
- は各スーパーマーケットのパフォーマンスを示す水平グラフを作る
package supermarkets;
public class Supermarkets
{
private String[] city = {"Miami", "Sunrise", "Hollywood",
"Tallahassee", "Jacksonville", "Orlando", "Gainesville", "Pensacola",
"Ocala", "Sebring"};
private double[] profit = {10200000, 14600000, 17000000, 6000000,
21600000, 9100000, 8000000, 12500000, 2000000, 4500000};
public Supermarkets(String[] c, double[] p)
{
//array for the city
city = new String[c.length];
for (int i = 0; i < c.length; i++)
city[i] = c[i];
//array for the profits
profit = new double[p.length];
for(int i = 0; i < p.length; i++)
profit[i] = p[i];
}
//sums up the profits from the cities
public double sumArray()
{
double sum = 0;
for (int i = 0; i < profit.length; i++)
sum = sum + profit [i];
return sum;
}
//calculates the average of the profits from the cities
public double average()
{
return sumArray()/profit.length;
}
//shows highest profit
double findHighestProfit()
{
double highest = profit[0];
for(int i = 1; i < profit.length; i++)
{
if (profit [i] > highest)
highest = profit [i];
}
return highest;
}
//gives the above average profit
public String aboveAvarage()
{
String s = "";
double avg = average();
for (int i = 0; i < profit.length; i++)
if (profit [i] > avg)
s = s + city[i] + " " + profit[i] + "\n";
return s;
}
//creates a graph showing city and profits
public String makeGraph()
{
String s = "";
for (int i = 0; i < profit.length; i++)
{
s = s + city[i] + " ";
int x = (int) Math.floor(profit[i]);
for(int j = 1; j <=x; j++)
s = s + "*";
s = s + "\n";
}
return s;
}
//resets profits position from least to greatest
public int findPosition(int startScanFrom)
{
int position = startScanFrom;
for (int i = startScanFrom + 1; i < profit.length; i++)
if (profit[i] < profit[position])
position = i;
return position;
}
//swaps values for city and profits
public void swap(int i, int j)
{
// Swap the profits
double temp = profit[i];
profit[i] = profit[j];
profit[j] = temp;
// Swap the cities
String str = city[i];
city[i] = city[j];
city[j] = str;
}
}
System.out.println(sumArray())だけでなく、 ?他のすべての場合も同様です。あなたはここで何がびっくりしていますか? テスターをもっとうまく動作させる方法がわからない場合 - (テスターメイン) スーパーマーケットsm =新しいSuperMarket(); System.out.println(sm.sumArray()); – djechlin