Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-13-2008, 09:05 PM
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!!!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-14-2008, 11:24 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 740
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
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).
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on July 13, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-16-2008, 02:19 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 508
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
I agree....

regards,
sukatoa
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing a program within a program gibsonrocker800 New To Java 5 05-12-2008 09:24 AM
how to right a program that find kth number in two sorted array? fireball2008 New To Java 8 04-22-2008 04:21 AM
How to execute an External Program through Java program Java Tip java.io 0 04-04-2008 03:40 PM
Need help with my 1st array program Phobos0001 New To Java 5 03-22-2008 07:23 AM
How to execute an External Program through Java program JavaBean Java Tips 0 10-04-2007 10:33 PM


All times are GMT +3. The time now is 11:39 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org