# How to i solve this java senario??

• 12-16-2010, 07:19 PM
Rachel_B
How to i solve this java senario??
I am trying to teach myself java at the moment so i would love to know how to complete this scenario in java....i am trying to use eclipse!? thanks! x

The production department of a local manufacturer would like to produce statistics, including histograms, for the productivity of its manufacturing staff in 2008 and 2009. The company is involved in the manufacture of utility vehicles for the construction industry. Staff work in shift teams comprised of 20 employees.

Write a program to read the amount of items produced by each shift team for the two years, generate a histogram for each year and the statistics. The details are given below:

• For each year calculate
o The average amount of items produced;
o The shift team in each year with the highest amount of items produced and the amount; and
o The shift team in each year with the lowest amount of items produced and the amount.

• Over the two years
o The average amount of goods produced for each shift team

Your program should include the following methods:-

 A method readStats () which takes an array of integers as a parameter to hold the amount produced by each shift team for one year. It should read the quantities of items produced from the keyboard into the array.

 A method calculateandDisplayStats() which takes an array of integers holding the amount produced by each shift team for one year and displays the statistics for that year. This method should call other value methods:
 one to return the average amount produced for the year
 one to return the position in the array of the shift team with the highest productivity
 one to return the position in the array of the shift team with the lowest productivity.

 A method yearlyStats() which will take two arrays of integers representing the amount produced for each year and display the average amount produced for each shift team.

 A method printChart() which takes an array of integers as a parameter holding the amount produced by each shift team for one year and prints a histogram for that year.
• 12-16-2010, 07:21 PM
KevinWorkman
• 12-16-2010, 07:21 PM
Eranga
Ok, what you have done so far, can you show us over here?
• 12-16-2010, 07:28 PM
Rachel_B
This is where i have got so far up until the average but i am struggling to get a grasp on the arrays...!?

Code:

```// Name: Rachel Bell // Date:22/12/2010 /* The program shown below is designed to calculate the  * average amount of items produced and find the shift team  * with the lowest and highest amount of products produced  */ import java.util.Scanner; // import input utility public class Trial {                 public static void main (String[]args){ //start the main method                                 System.out.println("*******************************");                 System.out.println("  \tNumbers Program                  ");                 System.out.println("*******************************");                                 Scanner numbers = new Scanner (System.in);                                 System.out.print ("Please enter the amount of shift teams for each year");                 final int amount = numbers.nextInt();                                 int[] year_1= new int[amount]; // initialising array                 int[] year_2= new int[amount];                                 year_1 = readStats(year_1);                 System.out.println("We will now look at the second year");                 year_2 = readStats(year_2);                 System.out.println("All values have now been entered");                 calculateandDisplayStatsYear1(amount,year_1);                 calculateandDisplayStatsYear2(amount,year_2);                         static int[] readStats (int[]year)         {                 Scanner numbers = new Scanner (System.in);                 for( int i=0; i<year.length; i++)                 {                         System.out.print("Enter the amount produced by shift team "+(i+1));                         year[i] = numbers.nextInt();                 }                 return year;         }                 static void calculateandDisplayStats1 (int [] amount, int year, int [] total)                                                 void calculateandDisplayStatsYear1(int [] amount, int year_1){                 System.out.println("****************************************************");                 System.out.println("display the average amount of items produced " + year_1);                                                                 System.out.println("*****************************************************");                 System.out.println("display the highest amount of items produced " + year + "is" + );                                 System.out.println("***************************************************");                 System.out.println("display the lowest amount of items produced " + year + "is" + );                                 }                                 static double calculateandDisplayStatsYear11(int [] amount, int year_1){                 double total=0;                 for( int i=0; i<amount.length; i++);                 return total;                 }                 static double calculateandDisplayStatsYear2(int [] amount, int year_2){                 double total=0;                 for( int i=0; i<amount.length; i++);                 return total;                 } }```
• 12-16-2010, 07:31 PM
Eranga
Please use code tags next time. Unformated codes are really hard to read.
• 12-16-2010, 07:34 PM
Eranga
What you've done here is real mess. Do you know about methods in Java?
• 12-16-2010, 07:39 PM
Rachel_B
I know i am trying to teach myself how to do java at the moment...:( i have a rough idea about methods but i am only at a beginner level, just trying to figure out how i would go about completing this scenario and then learn from that!?

Even if i could get the average done then it might give me a better insight into how to layout your program etc.

Many Thanks :)
• 12-16-2010, 07:47 PM
Eranga
Okay then.

Actually my first advice is you yo study about more methods in Java.

Second point is never implement a large process in a single method. Basic idea about methods is that the functionality (or the process) you want to implement is more specific as well as a smaller one. And also don't write everything in main method.

As a startup, and since you are newbie to Java, cold you step-down your requirement and show it here. Then I'll help you to complete one step at a time.