0

Part of a program I did.
I don't understand why it doesn't work.

import java.util.Scanner; 
public class Reports {

public static void main(String args[])
{
    int[][] sales = new int[6][4];
    String [] company = {"Dallas","Chicago","Boston","New York","Seattle","Washington"};
    EnterData(sales,company);
    Highest(sales,company);
}

public static void EnterData(int sales[][],String company[]) 
{
    Scanner input = new Scanner(System.in);
    for(int i = 0; i < 6; i++){
    System.out.println("\nEnter The Quarterly Sales For " + company[i]+ "\n");

    for(int j = 0; j<4; j++)
    {
        System.out.print("Enter The Sales For Quarter " + (1+j)+ ": ");
        sales[i][j]= input.nextInt();
        while(sales[i][j]<0)
        {
            System.out.print("Enter The Sales For Quarter " + (1+j)+ ": ");
            sales[i][j]= input.nextInt();
        }
    }
public static void Highest(int sales[][],String company[])
{
    int value; 
    int highest = 0;
    int i;
    int j;

for(i = 0; i<4;i++){
    value = 0;
    highest = 0;

  for( j = 0 ;j<6;j++)
      if(value < sales[j][i])
         highest = j;
   System.out.println(highest);

   System.out.println("The Comapny With Highest Sales In The "+ (i+ 1) + " Quarter is " + company[highest] + "\n");
}
}
2
Contributors
3
Replies
22
Views
3 Years
Discussion Span
Last Post by Accouter
0

what is the result you expect? what is the result you get? are there any error messages? does it compile? does it run? .... ?

0

It does run, but it's not displaying the right company with the highest quarterly sales.
Dallas sales is stored in sales[0],Chicago sales[1]...etc (remember it's a 2d array)
i'm trying to compare the quarterly sales of each division and store the one with the highest. Then use that value in the string array to output the right company's name.

for(i = 0; i<4;i++){   // this goes through each sales for the quarter
value = 0;
highest = 0;
  for( j = 0 ;j<6;j++)  // this goes through each company
  if(value < sales[j][i]) 
     highest = j;
   System.out.println(highest);
    System.out.println("The Comapny With Highest Sales In The "+ (i+ 1) + " Quarter is " + company[highest] + "\n");

Edited by Accouter: typo

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.