Results 1 to 15 of 15

Thread: Help me please

  1. #1
    whateverme is offline Member
    Join Date
    Oct 2010
    Posts
    51
    Rep Power
    0

    Default Help me please

    Hi. I'm writting a program that processes listening figures for the radio station. Listening figures are recorded separately during morning and afternoon.
    There are 3 shows in the morning and 3 shows in the afternoon.
    so this program I'm trying to write will asks in turn for the figures for each morning shows and then prints the total. It does then the same for the afternoon shows. Finally it prints the overall total.
    So I used for loops.

    Java Code:
     
    
    import javax.swing.*; // import the swing library for I/O
    
    class whatever
    {
        public static void main (String[] param)
        {
            
            radio();
            System.exit(0);
            
        } // END main
    
        public static void radio()
        {
    
           for (int i=7; i<=11; i=i+2)
           { 
            String radioshow;String morning; float morning1; String afternoon; float afternoon1; float totalfig;
            radioshow = JOptionPane.showMessageDialog(null, " The total number of Gleeful listeners this morning was" + totalfig + "million");
            morning = JOptionPane.showInputDialog("What were the morning listening figures for the" + i + "am show?");
        	morning1 = Float.parseFloat(morning);
        	afternoon = JOptionPane.showInputDialog("What were the afternoon listening figures for the" + i + "am show?"); 
        	afternoon1 = Float.parseFloat(afternoon);
        
        	totalfig = morning1 + afternoon1;
        
        
        
            }
          
        } // END radio
        
    } // END class whatever
    But I'm getting an error
    Java Code:
    whatever.java:41: incompatible types
    found   : void
    required: java.lang.String
            radioshow = JOptionPane.showMessageDialog(null, " The total number of Gleeful listeners this morning was" + totalfig + "million");
                                                     ^
    1 error
    Is the program I have written correct?

  2. #2
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

    You are trying to assign a variable "radioshow" to a Message Dialog. It's a message dialog, not an input dialog.
    Sincerely, Joshua Green
    Please REP if I help :)

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

    Default

    I second Josh's response and recommend that you check out the JOptionPane API to find another method there that might work better for you.

  4. #4
    whateverme is offline Member
    Join Date
    Oct 2010
    Posts
    51
    Rep Power
    0

    Default

    You are trying to assign a variable "radioshow" to a Message Dialog. It's a message dialog, not an input dialog.
    __________________
    Sincerely,
    Josh Green
    what do you mean? i did message dialog not input dialog

  5. #5
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

    A message dialog just outputs something to the screen. You can't store anything into a variable because there is nothing to store.
    Sincerely, Joshua Green
    Please REP if I help :)

  6. #6
    whateverme is offline Member
    Join Date
    Oct 2010
    Posts
    51
    Rep Power
    0

    Default

    Ok so I modified it a bit.
    but now how do I make sure the program to get a total number of morning listeners and a total number of afternoon listeners?

    so that it will ask user type in answer for every question and in the end there will be a message dialog that appears with the total for morning listeners. the same goes to afternoon.

    Java Code:
     
    import javax.swing.*; // import the swing library for I/O
    
    class whatever
    {
        public static void main (String[] param)
        {
            
            radio();
            System.exit(0);
            
        } // END main
    
    
        public static void radio()
        {
    
           for (int i=7; i<=11; i=i+2)
           { 
            String morningshow; float morning1; float morning2; 
            
            morningshow = JOptionPane.showInputDialog("What were the morning listening figures for the " + i + " am show?");
        	morning1 = Float.parseFloat(morningshow);
        	morning2 = morning1;
        	
        	
        	JOptionPane.showMessageDialog(null, " The total number of Gleeful listeners this morning was " + morning2 + " million");
            }
            
            for (int i=1; i<=10; i=i+3)
            {
            String afternoonshow; float afternoon1; float afternoon2;
            
        	afternoonshow = JOptionPane.showInputDialog("What were the afternoon listening figures for the " + i + " pm show?"); 
        	afternoon1 = Float.parseFloat(afternoonshow);
        	afternoon2 = afternoon1;
        	
        	
        	JOptionPane.showMessageDialog(null, " The total number of Gleeful listeners this afternoon was " + afternoon2 + " million");
            }
            
       		
          
        } // END radio
        
    } // END class whatever

  7. #7
    whateverme is offline Member
    Join Date
    Oct 2010
    Posts
    51
    Rep Power
    0

    Default

    please help me this time

  8. #8
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

    Well, first of all, morning2 and afternoon2 are useless variables. You don't need them. Why make morning2 = morning1 if you can just use the variable morning1?
    Sincerely, Joshua Green
    Please REP if I help :)

  9. #9
    whateverme is offline Member
    Join Date
    Oct 2010
    Posts
    51
    Rep Power
    0

    Default

    TRUE.
    I have no idea what was going on with my head. deleted them.

  10. #10
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

    Okay, and as for the totals. All you need is a new variable, something like..."float sum = 0". And then just add to that variable every time the user makes an input. A running total.
    Sincerely, Joshua Green
    Please REP if I help :)

  11. #11
    whateverme is offline Member
    Join Date
    Oct 2010
    Posts
    51
    Rep Power
    0

    Default

    what do you mean by this
    And then just add to that variable every time the user makes an input. A running total.
    I know this. but I don't know how do I get to make a total of all the inputs.
    Java Code:
     float sum = 0;
    
    sum = sum + i

  12. #12
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

    The variable "i" is not your input variable. But the concept is correct.
    Sincerely, Joshua Green
    Please REP if I help :)

  13. #13
    whateverme is offline Member
    Join Date
    Oct 2010
    Posts
    51
    Rep Power
    0

    Default

    I did this. And I'm getting it one by one. For example " what were the morning listening figures for 7am show?" then I get " The total number of Gleeful listeners this morning was " + whatever I put before + " million" this repeats again for the 9am, 11am.
    I do I total up everything and the total only appears once.

    Java Code:
    String morningshow; float morning1; float sum = 0;
            
            morningshow = JOptionPane.showInputDialog("What were the morning listening figures for the " + i + " am show?");
        	morning1 = Float.parseFloat(morningshow);
      		sum = sum + morning1;
        	
        	
        	JOptionPane.showMessageDialog(null, " The total number of Gleeful listeners this morning was " + sum + " million");

  14. #14
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

    The adding of the sum should be inside your loops that you had before.
    Sincerely, Joshua Green
    Please REP if I help :)

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

Posting Permissions

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