Results 1 to 5 of 5
  1. #1
    myalani is offline Member
    Join Date
    Oct 2011
    Posts
    2
    Rep Power
    0

    Post user input program

    hi
    im new to java and i have a question about the following program. basically, i want to get the user input and show and output on the screen, however, the input dialogue doesn't show and i dont know why??
    Java Code:
    package math;
    
    import javax.swing.JOptionPane;
    
    public class NewClass {
        int PIN = 1234;
        double account_number;
        double beg_bal = 1000.0;
        String user_name;
        public static void main (String[] args){
            new NewClass();
        }
        public double deposit(String amount){
            double a;
            amount = JOptionPane.showInputDialog("Enter the amount to deposit: ");
            a = Double.parseDouble(amount);
            beg_bal = beg_bal + a;
            System.out.println("Your new balance is:\n");
            JOptionPane.showMessageDialog(null,"Your new balance is:"+ beg_bal,"Results",JOptionPane.PLAIN_MESSAGE);
            System.exit(0);
            return (beg_bal);
        }
        public double withd_transfer(String amount){
            double b;
            amount = JOptionPane.showInputDialog("Enter the amount to withdraw/transfer: ");
            b = Double.parseDouble(amount);
            beg_bal = beg_bal + b;
            System.out.println("Your new balance is:\n");
            return (beg_bal);
        }
        
        }
    thanks in advance

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

    Default Re: user input program

    Where do you call the deposit or withd_transfer methods? Your main only calls the NewClass constructor -- where's you code for that?

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

    Default Re: user input program

    all your code does is create a NewClass (please use better names in future) object and then ends. When do you call any methods?

  4. #4
    myalani is offline Member
    Join Date
    Oct 2011
    Posts
    2
    Rep Power
    0

    Default Re: user input program

    Quote Originally Posted by Fubarable View Post
    Where do you call the deposit or withd_transfer methods? Your main only calls the NewClass constructor -- where's you code for that?

    I want to call these methods by prompting the user, but should I call these methods inside the main function in order to do that?

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,784
    Rep Power
    7

    Default Re: user input program

    You would call them in the most appropriate location. You need to decide where that is.

Similar Threads

  1. User Input???
    By jonytek in forum New To Java
    Replies: 8
    Last Post: 01-13-2013, 02:52 PM
  2. Need help getting input(first/last name) from user
    By nightrise420 in forum New To Java
    Replies: 11
    Last Post: 09-11-2010, 03:09 AM
  3. Replies: 13
    Last Post: 04-16-2010, 02:51 AM
  4. how to get input from User
    By Alvaro in forum New To Java
    Replies: 7
    Last Post: 01-15-2010, 11:02 PM
  5. User input- Pop Up Box
    By dedachi in forum AWT / Swing
    Replies: 3
    Last Post: 03-23-2009, 04:47 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
  •