Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Need some Input on an application

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    24
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Need some Input on an application

    Hello everybody , I did an assignment for my java class and would like to have some input ; I have to create a program using a two dimensional array and average the high and the low numbers separatly and then return the largest and lowest index of the array . This is what I got so far

    public class EC {
    static final int High =12; // 12 months in a year
    static final int Low = 12; // 12 months in a year
     
    	 public static void main(String[] args)
    	    {
     
    	     int[][] Temp ={{78,83,98,67,64,87,45,59,98,75,82,68}, // Array of Low Temperature
    	    	   			{454,674,632,3265,62,478,54,428,23,76,65,45}}; //Array of High Temperature 
     
    	       GetData(Temp);
    	        System.out.println(); 
    	        averageHigh(Temp);
    	        System.out.println(); 
    	        averageLow(Temp);
    	        System.out.println(); 
    	        indexHighTemp(Temp);
    	        System.out.println(); 
    	        indexLowTemp(Temp);
    	        System.out.println();
     
    	    }
     
            // reads and store the data 
    		public static void GetData(int matrix[][] )
    		{
    	    			 int row, col;
     
    	    		    for (row = 0; row < matrix.length; row++)
    	    		    {
    	    		        for (col = 0; col < matrix[0].length; col++);
     
    		    }
    		}
    				//  calculate the average high temperature of the year
    		public static void averageHigh(int x[][] ){
     
    			int row, col = 1;
    	        int sum = 0;
     
    	    row= 1 ;
    	    for (col=0;col<x[row].length;col++)
    	    	sum = sum +x[row][col];
    	    System.out.print("The Average of High is " +sum/12);
    		}
     
    		//  calculate the average low temperature of the year
    		public static void averageLow(int x[][] ){
    			int row, col = 0;
    	        int sum = 0;
     
    	    row=  0;
    	    for (col=0;col<x[row].length;col++)
    	    	sum = sum +x[row][col];
    	    System.out.print("The Average of Low is " +sum/12);
    		}
     
     
    		// return index of the highest temperature
    		public static void indexHighTemp(int x[][] ){
     
    			 int max = x[0][0];
    			    for (int row = 0; row < x.length; row++) {
    			        for (int col = 0; col < x[0].length; col++) {
    			            if (x[row][col] > max) {
    			                max = x[row][col];
     
    			            }
    			        }
    			    }
    			    System.out.println("The largest index of the Array is "+max);
     
            }	       
    		// return index of the lowest temperature 
    		public static void indexLowTemp(int x[][] ){
    			int idx =-1;
    			    int d= x[0][0];
    			    for(int row = 0; row < x.length; row++)
    			    for (int col = 0; col < x[0].length; col++)
    			        if(x[row][col] < d) {
    			            idx = x[row][col];
    			        }
    			    System.out.println("The largest index of the Array is "+idx);
    			}
     
    }

    Is this look good or do I have to change anything ?
    Thanks


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Need some Input on an application

    Does it work? Does it do what you expect? Do you understand it? If the answer to all three is "yes", then I really wouldn't worry about it too much. If the answer to one of them is "no", then I'd suggest you ask a more specific question about what you have there.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    24
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need some Input on an application

    yes to all three of your questions but since i am beginner i taught it will beneficial for me to have some people look at what i did

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Need some Input on an application

    One thing I can say is that you should always obey the standard naming conventions. Classes start with an uppercase letter. Methods and variables start with a lowercase letter.

    But really, don't worry too much about doing it exactly the right way at this stage. As long as it works and you understand it, that's good enough. No matter how much time you spend getting it right, in six months you'll look at your code and cringe. That's just how programming is.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. how to run any installed application through my java application??
    By sgsamanthjain in forum Java Theory & Questions
    Replies: 1
    Last Post: April 1st, 2011, 08:17 AM
  2. Replies: 2
    Last Post: March 23rd, 2011, 08:51 AM
  3. [SOLVED] allow a new input, dicarding the last mismatch input without terminating the program
    By voltaire in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 9th, 2010, 04:44 AM
  4. [SOLVED] [help] the application file (.jad) for application does not appear to be the ....
    By ordinarypeople in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: April 4th, 2010, 03:50 AM
  5. Replies: 0
    Last Post: December 3rd, 2009, 04:43 PM