Results 1 to 6 of 6

Thread: Execuse me...

  1. #1
    konayuki1510 is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default Execuse me...

    Execuse me...

    I need to write a program about this question...

    This program will show how many calls were received in a call centre on 7 consecutive days and you will need to be able to enter and store 7 separate integers.

    import javax.swing.JOptionPane;

    class CallData
    {
    public static void main (String[] args)
    {
    int[] anArray;

    anArray = new int[7];

    anArray[0] = 0;
    anArray[1] = 0;
    anArray[2] = 0;
    anArray[3] = 0;
    anArray[4] = 0;
    anArray[5] = 0;
    anArray[6] = 0;

    String s;
    s = JOptionPane.showInputDialog(null, "Please enter the number of calls for monday");

    int numstring = Integer.parseInt(s);

    displayData(anArray);

    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);

    }


    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    13

    Default

    at this point i dont know how to store the value, then ask for values for the other days of the week
    How about a loop? When dealing with arrays you usually need a loop do anything. Loop to put values into the array. Loop to display values in an array. Loop to find a value in an array.

  3. #3
    konayuki1510 is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default

    i don't know how to write a loop for read the input..

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    13

    Default

    There is no loop to read user input.

    There are loops which I hope you can write.
    There are many ways to get user input and I can see in the above code you know one of them.

    Now put the two concepts together. Just to help:
    Java Code:
    loop {
        get user input;
        assign input into array;
    }
    The two lines inside the loop can be combined into a single statement.

  5. #5
    konayuki1510 is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default

    import javax.swing.JOptionPane;

    public class CallData
    {
    public static void main (String[] args)
    {
    int[] anArray = new int[7]; //allocates memory for 7 integers
    // Take input and pass to array
    String s;
    s = JOptionPane.showInputDialog(null, "Please enter the number of calls for monday");
    int d = Integer.parseInt(s);
    for(int i = 0; i < anArray.length; i++) {
    anArray[i] = s.nextInt();
    }
    displayData(anArray);
    }

    public static void displayData(int[] anArray){
    String[] days = new String[]{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};

    for(int i = 0; i < anArray.length; i++) {
    System.out.println("Number of calls on " + days[i] + " is " + anArray[i]);
    }

    int highestCallDay = 0;
    for(int i = 0; i < (anArray.length - 1); i++) {
    if(anArray[i] > anArray[i + 1]) {
    highestCallDay = anArray[i];
    System.out.println(highestCallDay);

    }
    }

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

    }
    }

    I try to modify the structure of the program , but in line10, it say "it cannot find symbol method nextInt()"

    What can I do?

  6. #6
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    10

    Default

    welcome to the forum, please use code tags so it is easy to read and code formats will not be ignored

Posting Permissions

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