1. Member Join Date
Apr 2008
Posts
6
Rep Power
0

## Array program help

This is the assignment:
Purpose of exercise:
To understand the concept of arrays, by being able to manipulate the elements in one-dimensional arrays.

Problem

The management of a certain chain of supermarkets would like to know on a comparative basis the performance its supermarkets in each city. The data in the following table shows the amount of profit for all of the supermarkets in each city periodically.

City Profit
Miami \$10,200,000
Sunrise \$14,600,000
Hollywood \$17,000,000
Tallahassee \$6,700,000
Jacksonville \$3,600,000
Orlando \$9,100,000

The information required must be presented in the following order:

 The original data set as shown in the table.
 A horizontal bar graph showing the performance for each city, to the nearest million dollars.
 The average profit for the supermarket chain
 The city with the lowest profit.
 The city with the highest profit
 List all those cities with profit at or above the mean.
 The standard deviation of profits.
 List in descending order of profit, the cities and their respective profit.

To carryout this exercise, convince yourself of the following classes:

 GetData  used to acquire the data values.
 Statistics  find statistical measures such as: mean, standard deviation, graph, find the largest and smallest profit, and to sort the arrays
 TestStats  utilizes the other classes in order to generate the report.

Note:
(1) You need two arrays: one for the name of the cities, and the other for the dollar amount.
(2) It is a good practice to preserve the original array, so make a copy of the original data set.

and this is what I have so far:
Java Code:
```public class Management {
double[] profit;
String[] city;
String[] originalCity,aboveAverage;
double average,deviation;

Management(String[] thisCity, double[] thisProfit, String[] originCity)
{
city = thisCity;
profit = thisProfit;
originalCity = originCity;
}
@Override
public String toString(){
return "City" + '\t' + "Profit" + '\n' + city + '\t' + profit + 'n';
}
public double getSum()
{
double sum = 0;
for(int i = 0; i < profit.length; i++)
sum = sum + profit[i];
return sum;
}
public double average()
{
return getSum()/profit.length;
}
public String aboveAverage()
{
String s = "";
double avg = average();
for(int i = 0; i < profit.length; i++)
if(profit[i] > avg)
s = city[i] + "" + profit[i] + '\n';
return s;
}
public double getDeviation()
{
double sumdifference = 0;
double mean = average();
for(int i = 0; i < profit.length; i++)
sumdifference = sumdifference + Math.pow((profit[i]- 1), mean);
return Math.sqrt(sumdifference/profit.length);
}
public double findhighValue()
{
double highestValue = profit;
for(int i = 1; i < profit.length; i++)
if(profit[i] > highestValue )
highestValue = profit[i];
return highestValue;
}
public double findlowestValue()
{
double lowestValue = profit;
for(int i = 1; i > profit.length; i++)
if(profit[i] > lowestValue)
lowestValue = profit[i];
return lowestValue;
}
public String barGraph()
{
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 <= i; j++)
s = s + "*";
s = s + '\n';
}
return s;
}
public int findPosition(int startfrom)
{
int position = startfrom;
for(int i = startfrom + 1; 1 < profit.length; i++)
if(profit[i] < profit[position])
position = i;
return position;

}
void swap(int i, int j)
{
//Swap profits
double money = profit[i];
profit[i] = profit[j];
profit[j] = money;

//Swap cities
String str = city[i];
city [i] = city[j];
city[j] = str;
}
}```
please set me in the right direction. Help me divide it into classes and with the array/array list.
Any help would be really appreciated. Thanks!!!  Reply With Quote

2. ## Your code has no main method to test your class. I suggest writing a main method to do so and start from there. At a glance, things seem okay with your code.... so I'm not 100% sure what you're asking exactly.. and the "Note" above is pretty specific so simply do what it says. When you run into a problem, defined as something not functioning correctly due to syntactical or logic related reasons, then I can be better positioned to assist you. Actually.. in retrospect, you already have two arrays, named profit and city, which is what you are supposed to do found in the "Note" section.

Summing it up, 1) start with a tester method(can be a main method), and 2) define your problem specifically(if you run into any).  Reply With Quote

3. ## I agree....

regards,
sukatoa  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•