Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2009
    Posts
    1
    Rep Power
    0

    Default Java Programming, Array Help

    Sorry I am new to Java, so please have patience.

    If I have placed this thread in the wrong place, please move it to the appropiate place.


    I need to write a program which shows me how many calls were received in a call centre on 7 consecutive days and will need to be able to enter and store 7 seperate integers

    it will need a main method that declares and uses the arrays to stsore the number of calls on each day of the week and another method to display the calls on each day of the 7 days (mon - saturday) and display the day with the highest number of calls

    it must ensure that the array is passed as a parameter between the two methods

    so far i have this

    import javax.swing.JOptionPane;

    class CallData
    {

    public static void main (String[] args)
    {
    int[] anArray; // declares the array

    anArray = new int[7]; //allocates memory for 7 integers

    anArray[0] = ''; // initialize first element
    anArray[1] = ''; // initialize second element
    anArray[2] = ''; // etc.
    anArray[3] = '';
    anArray[4] = '';
    anArray[5] = '';
    anArray[6] = '';

    s = JOptionPane.showInputDialog(null, "Please enter the number of calls for monday"); ( at this point i dont know how to store the value, then ask for values for the other days of the week

    displayData

    System.exit(0);

    }

    public static void displayData (anArray);

    {

    int highcallday;

    System.out.println("The number of calls for Monday is " + anArray[0]);
    System.out.println("The number of calls for Tuesday is " + anArray[1]);
    System.out.println("The number of calls for Wednesday is " + anArray[0]);
    System.out.println("The number of calls for Thursday is " + anArray[0]);
    System.out.println("The number of calls for Friday is " + anArray[0]);
    System.out.println("The number of calls for Saturday is " + anArray[0]);
    System.out.println("The number of calls for Sunday is " + anArray[0]);


    highcallday = 0;
    for ( int i = 0; i < testArray.length; i++ )
    {
    if ( highcallday[i] >= avg )
    {
    highcallday++;
    }
    }

    System.out.println("The highest number of calls is " + highcallday);

    }


    }

    i've made lots of mistakes and i dont know where i am going wrong

    much help appreciated

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    A couple of points:

    Java Code:
    anArray[0] = '';
    anArray[...] is an int, and so you will have an error if you try to initialize it to non-int values.

    If you just declare the array as an array of int, I believe that you don't need to initialize it as it should be filled with zeros. Note that this isn't true for arrays of objects. For those you have to initialize each and every item in the array.

    Java Code:
    s = JOptionPane.showInputDialog(null,/*...*/);//....
    You're using a variable here, s, without declaring it. Before you can use any variable at all, it must be declared first. For instance
    Java Code:
    String s = JOptionPane....
    and here:
    Java Code:
    displayData
    You're trying to call a method here without using parenthesis or passing any required parameters.

    These are just some of the errors present, but unfortunately there are a lot more. The bottom line here is: you need to do some reading and studying before attempting any coding. You can't just randomly type code and hope and pray that it will work. I suggest that you hit your books and / or the Sun Java tutorial and learn the basics you'll need for your class. Best of luck!
    Last edited by Fubarable; 01-24-2009 at 03:47 PM.

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Methods...

    For understanding the method part, passing arguments and returning values, here's a link with some useful info (look for one of my posts, #7, towards the end)...
    Help with really simple coding

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. Java Programming in Netbeans
    By cserenop51 in forum NetBeans
    Replies: 5
    Last Post: 11-05-2008, 04:21 AM
  2. java game programming
    By gammaman in forum New To Java
    Replies: 1
    Last Post: 12-25-2007, 02:01 AM
  3. Java networking programming (I)
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 12-24-2007, 08:21 PM
  4. Java Applet 3D programming
    By ramk in forum Java Applets
    Replies: 0
    Last Post: 11-28-2007, 11:36 PM
  5. Java Programming
    By JavaForums in forum Java Tutorial
    Replies: 0
    Last Post: 07-29-2007, 12:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •