954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

sorting arrays in java

/**

Program name: MonthlySales.java
Author: Dominick Saccoccio
Date: 2-19-08
Description: The program provides an end-of-the-year sales analysis for a company.
The revenue contains total sales for each month, where revenue
={ 16692, 2504, 2463, 1857, 2369, 2684, 3374, 2630, 2531, 1928, 2692, 2578}
presents the sales of January to December.

*/
public class MonthlySales

{
private final int JANUARY = 1;
private final int DECEMBER = 12;
private int [ ] REVENUE = { 0, 16692, 2504, 2463, 1857, 2369,3684, 2374, 2630, 2531, 1928, 2692, 2578 };


public int total ( ) sum= sum + i;

public int average ( )

public int hightestMonth ( )

public int monthsRevenue (int month)

public void printTable ( )


} // end of MonthlySales class

nuch1311
Newbie Poster
10 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

Need help sorting the array to get the highest number. Also need help to find the totatl and the average of the array.

nuch1311
Newbie Poster
10 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 
Arrays.sort(array);

Read the API docs.

Edit: Also read the API doc for Calendar, as the months, and Days of the week already have assigned int values.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 
Need help sorting the array to get the highest number.


You do not need to sort to get the highest element. Sorting is expensive. Getting the highest element is easy. Just go through and keep track of the highest one seen so far.

bugmenot
Posting Whiz in Training
225 posts since Nov 2006
Reputation Points: 53
Solved Threads: 34
 
Also need help to find the total and the average of the array.


loop through the array and get sum after that get average.

DangerDev
Posting Pro in Training
485 posts since Jan 2008
Reputation Points: 165
Solved Threads: 59
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You