I'm in a beginning programming class, and a lot of this had made sense to me up until this point, where we've started working with methods and I'm not entirely sure I understand the "static," "void," and "return" statements.
For this assignment in particular, I thought I had it all figured out, but it says it "can not find symbol histogram" on the line in the main method, although I'm clearly returning it from another method. Anyone able to help me out?
Assignment: "You see that you may need histograms often in writing your programs so you decide for this program to use your program 310a2 Histograms. You may add to this program or use it as a class. You will also write a class (or method) that will generate random number in various ranges. You may want to have the asterisks represent different values (1, 100, or 1000 units). You may also wish to use a character other than the asterisk such as the $ to represent the units of your graph. Run the program sufficient number of times to illustrate the programs various abilities.
Statements Required: output, loop control, decision making, class (optional), methods.
Sample Output:
Sales for October
Day Daily Sales Graph
2 37081 *************************************
3 28355 ****************************
4 39158 ***************************************
5 24904 ************************
6 28879 ****************************
7 13348 ************* "
Here's what I have:
import java.util.Random;
public class prog310t
{ 
  public static int randInt(int randomNum) //determines the random value for the day
  {   
    Random rand = new Random();
    randomNum = rand.nextInt((40000 - 1000) + 1) + 10000;
    return randomNum;
  }
  public String histogram (int randomNum) //creates the histogram string
  {
    String histogram = "";
    int roundedRandom = (randomNum/1000);
    int ceiling = roundedRandom;
    for (int k = 1; k < ceiling; k++)
    {
      histogram = histogram + "*";
    }
    return histogram;   
  }
  public void main(String[] Args)
  {
    System.out.println("Sales for October\n");
    System.out.println("Day        Daily          Sales Graph");
    for (int k = 2; k < 31; k++)
    {
      if (k == 8 || k == 15 || k == 22 || k == 29)
      {
        k++;
      }
      System.out.print(k + "         ");
      int randomNum = 0;
      randInt(randomNum);
      System.out.print(randomNum + "       ");
      histogram (randomNum);
      System.out.print(histogram + "\n");
    }
  }
}
Edit: Thanks to you guys, now I've figured out what static means. Now I have a new problem; the program runs, but histogram is returning as empty. Can someone help me understand why? New Code:
import java.util.Random;
public class prog310t
{ 
  public static int randInt(int randomNum) //determines the random value for the day
  {   
    Random rand = new Random();
    randomNum = rand.nextInt((40000 - 1000) + 1) + 10000;
    return randomNum;
  }
  public static String histogram (int marketValue) //creates the histogram string
  {
    String histogram = "";
    int roundedRandom = (marketValue/1000);
    int ceiling = roundedRandom;
    for (int k = 1; k < ceiling; k++)
    {
      histogram = histogram + "*";
    }
    return histogram;   
  }
  public static void main(String[] Args)
  {
    System.out.println("Sales for October\n");
    System.out.println("Day        Daily          Sales Graph");
    for (int k = 2; k < 31; k++)
    {
      if (k == 8 || k == 15 || k == 22 || k == 29)
      {
        k++;
      }
      System.out.print(k + "         ");
      int randomNum = 0;
      int marketValue = randInt(randomNum);
      System.out.print(marketValue + "       ");
      String newHistogram = histogram (randomNum);
      System.out.print(newHistogram + "\n");
    }
  }
}



getHistogramto avoid confusing it with the variable.main()needs to bestatic. Consequentlyhistogram()needs to bestaticso thatmaincan call it.{}(Code Sample) button in the toolbar of the editor.marketValuedoes it return an empty string for? It should any time the value is below 1000, certainly.