View Single Post
  #1 (permalink)  
Old 04-13-2008, 09:05 PM
adelgado0723 adelgado0723 is offline
Member
 
Join Date: Apr 2008
Posts: 6
adelgado0723 is on a distinguished road
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:
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[0]; for(int i = 1; i < profit.length; i++) if(profit[i] > highestValue ) highestValue = profit[i]; return highestValue; } public double findlowestValue() { double lowestValue = profit[0]; 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
Sponsored Links