Results 1 to 7 of 7
  1. #1
    JavaPete is offline Member
    Join Date
    Oct 2012
    Posts
    9
    Rep Power
    0

    Default Program does not want to proceed with options 1,2 and 3.

    Hi everyone,
    New to JAVA and this is my first post.
    I'm following the book Learn to Program with Java from John Smiley. Since the program is available for free I don't think its a problem to print it out here.
    Basically I seem to have written the program just like the book and I do not have any bugs or red lines to show I have mistakes. However, the program will answer back when I do not put the right number choice, or if I leave it blank and if I press cancel. These will all give me back an answer and than exit. However, the 1,2, and 3 response does not work. The GUI just remains blank and waits for another response. Any help appreciated.

    XML Code:
     1 /*
     2  * To change this template, choose Tools | Templates
     3  * and open the template in the editor.
     4  */
     5 package practice;
     6 
     7 
     8 import javax.swing.JOptionPane;
     9 
    10 public class Practice6_2 {
    11     
    12 static double balance = 0;
    13 static double newBalance = 0;
    14 static double adjustment = 0;
    15 
    16 public static void main(String[] args){
    17     String response;
    18     String moreBankingBusiness;
    19     moreBankingBusiness =
    20             JOptionPane.showInputDialog
    21             ("Do you want to do some banking?");
    22     moreBankingBusiness = moreBankingBusiness.toUpperCase();
    23     while (moreBankingBusiness.equals("YES")){
    24         response = JOptionPane.showInputDialog
    25          ("What would you like to do? (1=Deposit, 2=Withdraw, 3=Get Balance)");
    26             if (response == null){
    27             JOptionPane.showMessageDialog
    28                     (null, "You clicked on the Cancel button");
    29             System.exit(0);
    30         }
    31 else
    32             if (response.isEmpty()){
    33             JOptionPane.showMessageDialog
    34                     (null,"You must make an entry in the InputBox");
    35             System.exit(0);
    36             }
    37 else
    38             if (Integer.parseInt(response) < 1 | 
    39                     Integer.parseInt(response) > 3){
    40                 JOptionPane.showMessageDialog
    41                         (null, response + "- is not a valid banking function");
    42                 System.exit(0);
    43             }
    44             if (Integer.parseInt(response) == 1){
    45                 makeDeposit();
    46             }
    47             if (Integer.parseInt(response) == 2){
    48                 makeWithdrawal();
    49             }
    50             if (Integer.parseInt(response) == 3){
    51                 getBalance();
    52             }
    53             moreBankingBusiness =
    54                     JOptionPane.showInputDialog
    55                     ("Do you have more banking business?");
    56             moreBankingBusiness =
    57                     moreBankingBusiness.toUpperCase();
    58             }//end of while
    59             JOptionPane.showMessageDialog
    60                     (null, "Thanks for banking with us!");
    61                     System.exit(0);
    62             }//end of main
    63  
    64 private static void makeDeposit(){
    65     adjustment = Double.parseDouble
    66             (JOptionPane.showInputDialog("Enter the Deposit Amount"));
    67             newBalance = balance + adjustment;
    68             JOptionPane.showMessageDialog
    69                     (null,"***SMILEY NATIONAL BANK***\n\n" +
    70                     "Old Balance is: " + balance + "\n" +
    71                     "Adjustment is: +" + adjustment + "\n" +
    72                     "New Balance is: " + newBalance + "\n");
    73                     balance = newBalance;
    74 }
    75 private static void makeWithdrawal(){
    76     adjustment = Double.parseDouble
    77             (JOptionPane.showInputDialog("Enter the Withdrawal Amount"));
    78             newBalance = balance - adjustment;
    79             JOptionPane.showMessageDialog
    80                     (null,"***SMILEY NATIONAL BANK***\n\n" +
    81                     "Old Balance is: " + balance + "\n" +
    82                     "Adjustment is: -" + adjustment + "\n" +
    83                     "New Balance is: " + newBalance + "\n");
    84                     balance = newBalance;
    85             }
    86 private static void getBalance(){
    87             JOptionPane.showMessageDialog
    88                     (null, "***SMILEY NATIONAL BANK***\n\n" +
    89                     "Your Current Balance is: " + balance );
    90       }
    91 }//end of class
    Last edited by JavaPete; 10-14-2012 at 08:23 PM. Reason: I made it a little more readable but dont know if its in the [code] format

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default Re: Program does not want to proceed with options 1,2 and 3.

    I would replace the line
    if (response.endsWith("")){
    with
    if (response.isEmpty()){

    the endsWith("") is true in all cases....no idea what the author was thinking

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Program does not want to proceed with options 1,2 and 3.

    Hello and welcome! Please use [code][/code] tags when posting code so we can easily read it!

  4. #4
    JavaPete is offline Member
    Join Date
    Oct 2012
    Posts
    9
    Rep Power
    0

    Default Re: Program does not want to proceed with options 1,2 and 3.

    Quote Originally Posted by quad64bit View Post
    Hello and welcome! Please use [code][/code] tags when posting code so we can easily read it!
    Thanks, I need to look into how to do that. I'm new to this.

  5. #5
    Sizzlewump's Avatar
    Sizzlewump is offline Member
    Join Date
    Oct 2010
    Location
    MI, USA
    Posts
    12
    Rep Power
    0

    Default Re: Program does not want to proceed with options 1,2 and 3.

    You should try to repost the code without the line numbers. That would make it easier to look at.
    "The secret to getting what you want is to reject everything that you don't want." -Wolbers

  6. #6
    JavaPete is offline Member
    Join Date
    Oct 2012
    Posts
    9
    Rep Power
    0

    Default Re: Program does not want to proceed with options 1,2 and 3.

    Ok I solved my problems.
    Added else to the if statements and one of the braces were backwards

  7. #7
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Program does not want to proceed with options 1,2 and 3.

    Glad you got it worked out. In the future, use code tags as mentioned above, omit line numbers (no one will want to strip those out when trying to run your code) and post any/all compiler/runtime errors along with your code. Makes it much easier for us to help! Good luck!

Similar Threads

  1. Replies: 1
    Last Post: 03-28-2012, 12:43 PM
  2. HELP - Creating OPTIONS in program and LOOPS
    By whateverme in forum New To Java
    Replies: 14
    Last Post: 12-07-2010, 05:55 AM
  3. Where to proceed? Applets or Swing?
    By Mattedatten in forum New To Java
    Replies: 4
    Last Post: 02-28-2010, 02:48 PM
  4. Replies: 15
    Last Post: 01-07-2009, 04:42 AM
  5. Where to proceed now?
    By Ixnay in forum New To Java
    Replies: 4
    Last Post: 07-29-2007, 07:16 PM

Posting Permissions

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