Display Strings from a 2 dimensional array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • owz
    New Member
    • Nov 2006
    • 14

    #1

    Display Strings from a 2 dimensional array

    This is what im trying 2 get
    Sales Figures for 2006 in £000's


    Sales staff name 1st Quarter 2nd Quarter 3rd Quarter 4th Quarter Max Min Total

    John Smith 24 30 15 17 30 15 86
    Joe Jones 24 19 10 20 24 10 73
    Jill Evans 24 21 20 28 28 20 93

    Quarterly totals 72 70 45 65

    Total sales are £252,000


    Star performers by quarters are:
    Quarter 1 John Smith
    Quarter 2 John Smith
    Quarter 3 Jill Evans
    Quarter 4 Jill Evans


    i am haveing problems with displaying the star performers. I have got the code 2 display the correct value for the quarter, but the names do not work and are duplicated.

    this is what i get:

    Star performers by quarters are:

    Quarters John Smith

    Quarters Paul Evans correct

    Quarters John Smith

    Quarters John Smith correct

    Quarters Jill Evans

    Quarters Paul Evans

    Quarters Steven Smith correct

    Quarters John Smith

    Quarters Joe Jones

    Quarters Jill Evans correct

    all help is welcome. thanx in advance.



    Code:
    import java.io.*;
    
    public class SalesDetails
    {
    
            public static void main(String[] args) throws IOException
            {
    
        
        final String   textFilesPath = "C:\\Documents and Settings\\owz\\Desktop\\UNI WORK\\Comp Programming\\";//f:\Desktop\UNI WORK\computer programming
        BufferedReader inputFile;
        String        name;
        int             year;
        String [] names=new String[8];
        int [] [] salesFigures= new int [8] [4];
        int people=0;
        int max;
        int min;
        int total;
        int maxtotal=0;
       
        inputFile = Text.open ( textFilesPath + "sales details.txt" );
    
        System.out.println ( "Salesmen Name\\Sales Figures" );
        
        
        year= Text.readInt (inputFile);
        name= Text.readLine (inputFile);
    
        while ( name.equals ( "****" ) == false )
        {
           names[people]= name;
            for (int q=0; q<4; q++) {    
            
            
            salesFigures[people][q]= Text.readInt ( inputFile );
            }
        people=people +1;
        
         
        
          name = Text.readLine ( inputFile );
    
        }//end-while
    
        inputFile.close();
            
    
        
        
        
        
       
        System.out.print("\t\t\t\t\t");    System.out.println("Sales Figures for 2007 in £000's \n");
        
        System.out.println("Sales staff name\t       1st quarter\t       2st quarter\t       3st quarter\t       4st quarter\t      Max\t       Min\t           Total \n");
         
          for (int i=0;i<people; i++) {
              System.out.print(names[i]);
              if (names[i].length()<=11) {
                  System.out.print("\t");
              }
              for (int q=0; q<4; q++) {    
              
              
             System.out.print("\t\t"+ salesFigures[i][q]);
              }
                  max=salesFigures[i][0];
                  min=salesFigures[i][0];
              for (int q=1; q<4; q++) {
              
              if (salesFigures[i][q]>max) {
                  max=salesFigures[i][q];
              }
                if(salesFigures[i][q]<min) 
                min=salesFigures[i][q];
              } 
              
              
                 total=0;
                  for (int q=0; q<4; q++) {
                  
                  total=total+salesFigures[i][q];
                  
                     }     
                     
                     
             {               
                 maxtotal = maxtotal + total;
          
            System.out.print("\t       "+ max +"\t        "+ min+"\t\t  "+ total);
            
            
             System.out.println(); 
            
             }//output max,min and total
           
          }//ouput people and they're figures 
           System.out.println();
           System.out.print("Quarterly totals");
          
          int qTotal;
          for (int q=0; q<4; q++) {
             qTotal = 0;
             for (int i=0;i<people; i++) {
               
                   qTotal = qTotal + salesFigures[i][q];
                 
             }
             
             System.out.print("\t\t"+qTotal);  
            
         }
         
          System.out.println();
          System.out.print("\t\t\t\t\t\t\t\t\t\t\tTotal Sales = £" +maxtotal+",000"  );
          System.out.println();
          System.out.println();
          System.out.print("Star performers by quarters are:");
          System.out.println();
          
          
            
       
          
          int maxsales;
          String maxnames=("");
          
          
          for (int q=0; q<4; q++) {
        
             maxsales = 0;
              
             for (int i=0;i<people;i++) {
                 if (salesFigures[i][q]>maxsales) {
                 
                          
                     maxsales=salesFigures[i][q];
                          
                     
                         //System.out.println("Quarters\t" +maxsales) ;
                        
                          System.out.println("Quarters\t" +names[i]) ;
                                            
                      }  
                         
                 }
          
          //System.out.println("Quarters\t" +names[i]) ;
      }            
                 
          
        
        
      }//main     
    }//InputFile
  • owz
    New Member
    • Nov 2006
    • 14

    #2
    Originally posted by owz
    This is what im trying 2 get
    Sales Figures for 2006 in £000's


    Sales staff name 1st Quarter 2nd Quarter 3rd Quarter 4th Quarter Max Min Total

    John Smith 24 30 15 17 30 15 86
    Joe Jones 24 19 10 20 24 10 73
    Jill Evans 24 21 20 28 28 20 93

    Quarterly totals 72 70 45 65

    Total sales are £252,000


    Star performers by quarters are:
    Quarter 1 John Smith
    Quarter 2 John Smith
    Quarter 3 Jill Evans
    Quarter 4 Jill Evans


    i am haveing problems with displaying the star performers. I have got the code 2 display the correct value for the quarter, but the names do not work and are duplicated.

    this is what i get:

    Star performers by quarters are:

    Quarters John Smith

    Quarters Paul Evans correct

    Quarters John Smith

    Quarters John Smith correct

    Quarters Jill Evans

    Quarters Paul Evans

    Quarters Steven Smith correct

    Quarters John Smith

    Quarters Joe Jones

    Quarters Jill Evans correct

    all help is welcome. thanx in advance.



    Code:
    import java.io.*;
    
    public class SalesDetails
    {
    
            public static void main(String[] args) throws IOException
            {
    
        
        final String   textFilesPath = "C:\\Documents and Settings\\owz\\Desktop\\UNI WORK\\Comp Programming\\";//f:\Desktop\UNI WORK\computer programming
        BufferedReader inputFile;
        String        name;
        int             year;
        String [] names=new String[8];
        int [] [] salesFigures= new int [8] [4];
        int people=0;
        int max;
        int min;
        int total;
        int maxtotal=0;
       
        inputFile = Text.open ( textFilesPath + "sales details.txt" );
    
        System.out.println ( "Salesmen Name\\Sales Figures" );
        
        
        year= Text.readInt (inputFile);
        name= Text.readLine (inputFile);
    
        while ( name.equals ( "****" ) == false )
        {
           names[people]= name;
            for (int q=0; q<4; q++) {    
            
            
            salesFigures[people][q]= Text.readInt ( inputFile );
            }
        people=people +1;
        
         
        
          name = Text.readLine ( inputFile );
    
        }//end-while
    
        inputFile.close();
            
    
        
        
        
        
       
        System.out.print("\t\t\t\t\t");    System.out.println("Sales Figures for 2007 in £000's \n");
        
        System.out.println("Sales staff name\t       1st quarter\t       2st quarter\t       3st quarter\t       4st quarter\t      Max\t       Min\t           Total \n");
         
          for (int i=0;i<people; i++) {
              System.out.print(names[i]);
              if (names[i].length()<=11) {
                  System.out.print("\t");
              }
              for (int q=0; q<4; q++) {    
              
              
             System.out.print("\t\t"+ salesFigures[i][q]);
              }
                  max=salesFigures[i][0];
                  min=salesFigures[i][0];
              for (int q=1; q<4; q++) {
              
              if (salesFigures[i][q]>max) {
                  max=salesFigures[i][q];
              }
                if(salesFigures[i][q]<min) 
                min=salesFigures[i][q];
              } 
              
              
                 total=0;
                  for (int q=0; q<4; q++) {
                  
                  total=total+salesFigures[i][q];
                  
                     }     
                     
                     
             {               
                 maxtotal = maxtotal + total;
          
            System.out.print("\t       "+ max +"\t        "+ min+"\t\t  "+ total);
            
            
             System.out.println(); 
            
             }//output max,min and total
           
          }//ouput people and they're figures 
           System.out.println();
           System.out.print("Quarterly totals");
          
          int qTotal;
          for (int q=0; q<4; q++) {
             qTotal = 0;
             for (int i=0;i<people; i++) {
               
                   qTotal = qTotal + salesFigures[i][q];
                 
             }
             
             System.out.print("\t\t"+qTotal);  
            
         }
         
          System.out.println();
          System.out.print("\t\t\t\t\t\t\t\t\t\t\tTotal Sales = £" +maxtotal+",000"  );
          System.out.println();
          System.out.println();
          System.out.print("Star performers by quarters are:");
          System.out.println();
          
          
            
       
          
          int maxsales;
          String maxnames=("");
          
          
          for (int q=0; q<4; q++) {
        
             maxsales = 0;
              
             for (int i=0;i<people;i++) {
                 if (salesFigures[i][q]>maxsales) {
                 
                          
                     maxsales=salesFigures[i][q];
                          
                     
                         //System.out.println("Quarters\t" +maxsales) ;
                        
                          System.out.println("Quarters\t" +names[i]) ;
                                            
                      }  
                         
                 }
          
          //System.out.println("Quarters\t" +names[i]) ;
      }            
                 
          
        
        
      }//main     
    }//InputFile
    No problem have solved it now needed 2 diclear the array
    salesFiugres[0][0];

    Comment

    Working...