0

I have homework where I have to write a small program that asks for a number and returns the month assigned to that number.

So far I have written two different classes, one to prompt the user for int, and the other with the arrays of month. Now my problem is to pass over the months to the main class when the user enters a number.

So far for the main class I have this and I have no idea on how to proceed... I get:

java:17: error: array required, but Date found System.out.println(monthName[index]); 

I tried to be as detailed as possible.

    import java.util.Scanner;

public class Driver {

    public static void main(String[] args)
    {
        Utility input = new Utility();
        final int MONTH_NAMES = 12;
        int[] month = new int[MONTH_NAMES];
        Date monthName = new Date();
        {
        System.out.println(input.queryForInt("Enter the number for a month ")) ;
        }


    for (int index = 0; index < 12; index++)
        System.out.println(monthName[index]);
}
}
rgettman
  • 176,041
  • 30
  • 275
  • 357
  • 3
    monthName is not an array ... also what exactly do you want to achieve? – LostBoy Sep 30 '13 at 21:59
  • I want to query the user for a number and based on that number (1-12) return the corresponding month. And yeah I was thinking that was the problem too but I have no clue on how to proceed from there :\ –  Oct 01 '13 at 00:46
  • Have a look at http://stackoverflow.com/questions/1038570/how-can-i-convert-an-integer-to-localized-month-name-in-java – LostBoy Oct 01 '13 at 08:01

3 Answers3

0

Your System.out line is not referencing the array you named month.

Tyler Iguchi
  • 1,074
  • 8
  • 14
0

I don't think you intended to use Date monthName here

System.out.println(monthName[index]);

Judging by the number of indexes your for loop is counting, it looks like you wanted to use int[] month.

System.out.println(month[index]);
  • I'm going to try that as soon as I get home! Long train ride Thanks! –  Oct 01 '13 at 00:51
0

mouthName is a Date object, not an array. Also, why use a for loop to print out a whole year's mouth?

I think it can change the last for loop to System.out.printLn(mouthName.getMouth()) if the input.queryForIntmethod can successfully pass the int mouth to the mouthName object.

Stephanie Yang
  • 252
  • 1
  • 4
  • 13
  • I used a for loop so it keeps on running after the user enters his data or as my professor says "the program will look broken." –  Oct 01 '13 at 00:52