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 2 of 2

Thread: How to calculate & return highestmonth and lowestmonth as string in interactions tab?

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How to calculate & return highestmonth and lowestmonth as string in interactions tab?

    Trying to create a getHightestMonth out of the Arrays made and return the string of the month for the highest number listed in the array.
    <   public class RainFall
       {  
       // Instance variable
          private String[] monthNames = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
          private double[] values;
     
       // Constructor method
          public RainFall()
          {
             // Nothing to do yet, but good practice to always include a
             // no-argument constructor method
          }
     
       // Overloaded Constructor method - accepts an array of doubles
          public RainFall(double [] newArray)
          {
             values = new double [newArray.length];
     
             for(int i = 0; i < values.length; i++) {
                values[i] = newArray[i]; 
             }
     
     
          }
     
       // Adds up and return the total of the values in the array numbers
          public double getTotal()
          {
             double total = 0.0;
     
             for (double val : values)
             {
                total += val;
             }
     
             return total;
          }
     
       // Return the mean (average) of the values in array numbers
          public double getAverage()
          {
             double average = 0.0;
             average = getTotal() / values.length;
     
             return average;
          }
     
       // Return the Highest Month
          public String getHighestMonth()
          {
             String hiMonth = ""; 
     
             return hiMonth;
          }
     
       // Return the Lowest Month
          public String getLowestMonth()
          {
             String loMonth = "";
     
             return loMonth;
          }  
       }>


  2. #2
    Member
    Join Date
    Mar 2012
    Location
    United States
    Posts
    118
    My Mood
    Inspired
    Thanks
    1
    Thanked 33 Times in 31 Posts

    Default Re: How to calculate & return highestmonth and lowestmonth as string in interactions

    If the array values has the same length as monthNames (obviously being 12) then it is just a matter of getting the index of the highest number in values and return the String in monthNames based on that index.

Similar Threads

  1. Need a non void method to return the first three characters of a string
    By fallout87 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 9th, 2011, 10:00 PM
  2. Return Object does not return the expected output
    By Nour Damer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 13th, 2011, 07:24 AM
  3. Cannot calculate. Please help me....
    By safarina02 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 15th, 2011, 01:11 PM
  4. [SOLVED] Return randomized String to other class in project
    By Fermen in forum Collections and Generics
    Replies: 2
    Last Post: February 16th, 2011, 05:36 PM
  5. How to return sub string from String
    By humdinger in forum Collections and Generics
    Replies: 1
    Last Post: February 14th, 2010, 11:16 AM