Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How can I modify the following code using GUI, for example adding JButton, JFram

ID: 3834229 • Letter: H

Question

How can I modify the following code using GUI, for example adding JButton, JFrame, JLabel or other examples that can be used to create a GUI.

Here is the code:

//VirtualATM.java
import javax.swing.JOptionPane;
public class VirtualATM
{
   public static void main(String[] args) {
       //items and balances
       int SaveBalance=4000;
       int CheckBalance=4000;
       //set values for mortage balance, student balance
       //auto balance and personal balance
       int MortBalance = 350000, StudBalance = 75000,
               AutoBalance = 35000, PersBalance = 5000;
       int pas, wid, dep;
       int num;
       int Snum, Swid, Sdep = 0;
       int Cnum, Cwid = 0, Cdep;
       int Lnum;
       int back;
       int pass = 0;
       //welcome to atm
       JOptionPane.showMessageDialog(null, "Welcome to My ATM","ATM",
               JOptionPane.INFORMATION_MESSAGE);
       //pin
       pass=Integer.parseInt(JOptionPane.showInputDialog(null, "Please Enter Your Four Digit Pin","ATM",
               JOptionPane.QUESTION_MESSAGE));
       //input pin

       if ( pass < 10000 && pass > 0000)
       {

           //if pin is correct
           do{
               //choose account
               String f=JOptionPane.showInputDialog(null,"Please Choose Your Account "+"[1] Checking Account "
                       +"[2] Savings Account "+"[3] Loans ", "MyBank",JOptionPane.QUESTION_MESSAGE);
               num=Integer.parseInt(f);

               switch(num){
               //Checking account
               case 1:
                   String g=JOptionPane.showInputDialog(null,"Please Choose Your Transaction "
                           +"[1] Check Balance "
                           +"[2] Withdraw "+"[3] Deposit ", "MyBank",JOptionPane.QUESTION_MESSAGE);
                   Cnum=Integer.parseInt(g);
                   if (Cnum==1)
                   {
                       JOptionPane.showMessageDialog(null,
                               "Your Balance is "+CheckBalance+" dollars","ATM",
                               JOptionPane.INFORMATION_MESSAGE);
                   }
                   if (Cnum==2)
                   {
                       Cwid=Integer.parseInt(JOptionPane.showInputDialog(null,"Please Enter Amount to Withdraw "
                               ,"ATM",JOptionPane.INFORMATION_MESSAGE));
                       if(CheckBalance==200)
                       {
                           JOptionPane.showMessageDialog(null,"Your Balance is below 200",
                                   "ATM",JOptionPane.ERROR_MESSAGE);}
                       if (Cwid>CheckBalance)
                       {
                           JOptionPane.showMessageDialog(null,"Insufficient Funds!","ATM",JOptionPane.ERROR_MESSAGE);
                       }
                       CheckBalance=CheckBalance-Cwid;
                       JOptionPane.showMessageDialog(null,"Please collect your money"+" "+"Your Remaining Balance is"+CheckBalance,"ATM",JOptionPane.INFORMATION_MESSAGE);
                       if(CheckBalance<200){
                           JOptionPane.showMessageDialog(null,"Your Balance is below 200.Please maintain minimum balance","ATM",JOptionPane.ERROR_MESSAGE);}


                   }

                   else if (Cnum == 3)
                   {
                       Cdep=Integer.parseInt(JOptionPane.showInputDialog(null,""
                               + "Please Enter Amount to Deposit ",
                               "ATM",JOptionPane.INFORMATION_MESSAGE));
                       CheckBalance=Cdep+CheckBalance;
                       JOptionPane.showMessageDialog(null,"Your Current Balance is"+CheckBalance,"ATM",JOptionPane.INFORMATION_MESSAGE);
                   }
                   break;

                   //Savings account
               case 2:
                   String h=JOptionPane.showInputDialog(null,"Please Choose Your Transaction "
               +"[1] Check Balance "
               +"[2] Withdraw "
               +"[3] Deposit ", "MyBank",JOptionPane.QUESTION_MESSAGE);
                   Snum=Integer.parseInt(h);
                   if (Snum==1)
                   {
                       JOptionPane.showMessageDialog(null,"Your Balance is "+SaveBalance+" dollars","ATM",JOptionPane.INFORMATION_MESSAGE);
                   }
                   if (Snum==2)
                   {
                       Swid=Integer.parseInt(JOptionPane.showInputDialog(null,"Please Enter Amount to Withdraw "
                               ,"ATM",JOptionPane.INFORMATION_MESSAGE));
                       if (Swid>SaveBalance)
                       {
                           JOptionPane.showMessageDialog(null,"Insufficient Funds!","ATM",JOptionPane.ERROR_MESSAGE);
                       }
                       else
                       {
                           SaveBalance=SaveBalance-Swid;
                           JOptionPane.showMessageDialog(null,"Your Remaining Balance is"+SaveBalance,"ATM",JOptionPane.INFORMATION_MESSAGE);
                       }
                   }
                   //option 3 For deposit
                   else if (Snum ==3)
                       {
                           dep=Integer.parseInt(JOptionPane.showInputDialog(null,"Please Enter Amount to Deposit ",
                                   "ATM",JOptionPane.INFORMATION_MESSAGE));
                           SaveBalance=dep+SaveBalance;
                           JOptionPane.showMessageDialog(null,"Your Current Balance is"+SaveBalance,"ATM",JOptionPane.INFORMATION_MESSAGE);
                       }
                  
                   break;
                   //Loans
               case 3:
                   String i=JOptionPane.showInputDialog(null,"Please Choose the Loan you would like to make a payment on "+"[1] Mortgage "
                           +"[2] Student Loan "+"[3] Auto Loan " + "[4] Personal Loan ", "MyBank",JOptionPane.QUESTION_MESSAGE);
                   Lnum=Integer.parseInt(i);
                   if (Lnum==1)
                   {
                       JOptionPane.showMessageDialog(null,"Your Current Balance is "
                   +MortBalance+" dollars",
                   "ATM",
                   JOptionPane.INFORMATION_MESSAGE);
                       MortBalance=MortBalance-3500;
                       JOptionPane.showMessageDialog(null,
                               "Your remaing Mortgage loan is "+Math.abs(MortBalance),
                               "ATM",JOptionPane.INFORMATION_MESSAGE);
                   }
                   if (Lnum==2)
                   {
                       JOptionPane.showMessageDialog(null,"Your Current Balance is "+StudBalance+" dollars","ATM",JOptionPane.INFORMATION_MESSAGE);
                       StudBalance=StudBalance-250;
                       JOptionPane.showMessageDialog(null,"Your Student loan have to be paid is"+Math.abs(StudBalance),"ATM",JOptionPane.INFORMATION_MESSAGE);
                   }
                   if (Lnum==3)
                   {
                       JOptionPane.showMessageDialog(null,"Your Current Balance is "+AutoBalance+" dollars","ATM",JOptionPane.INFORMATION_MESSAGE);
                       AutoBalance=AutoBalance-500;
                       JOptionPane.showMessageDialog(null,"Your Auto loan have to paid is "+Math.abs(AutoBalance),"ATM",JOptionPane.INFORMATION_MESSAGE);
                   }
                   if (Lnum==4)
                   {
                       JOptionPane.showMessageDialog(null,"Your Current Balance is "+PersBalance+" dollars","ATM",JOptionPane.INFORMATION_MESSAGE);
                       PersBalance=PersBalance-1000;
                       JOptionPane.showMessageDialog(null,"Your Personal loan have to be paid is "+Math.abs(PersBalance),"ATM",JOptionPane.INFORMATION_MESSAGE);
                   }
                   break;
               default:System.exit(0);
               }

               //Return to top
               back=JOptionPane.showConfirmDialog(null,"Would you like to make another transaction","ATM",JOptionPane.YES_NO_OPTION);
           } while(back==0);

       }
       //End if
       //incorrect pin
       else{
           JOptionPane.showMessageDialog(null,"Please re-enter PIN","Incorrect PIN",JOptionPane.ERROR_MESSAGE);
       }
   }}

Explanation / Answer

import javax.swing.JOptionPane;
public class VirtualATM
{
   public static void main(String[] args) {
       //items and balances
       int SaveBalance=4000;
       int CheckBalance=4000;
       //set values for mortage balance, student balance
       //auto balance and personal balance
       int MortBalance = 350000, StudBalance = 75000,
               AutoBalance = 35000, PersBalance = 5000;
       int pas, wid, dep;
       int num;
       int Snum, Swid, Sdep = 0;
       int Cnum, Cwid = 0, Cdep;
       int Lnum;
       int back;
       int pass = 0;
       //welcome to atm
       JOptionPane.showMessageDialog(null, "Welcome to My ATM","ATM",
               JOptionPane.INFORMATION_MESSAGE);
       //pin
       pass=Integer.parseInt(JOptionPane.showInputDialog(null, "Please Enter Your Four Digit Pin","ATM",
               JOptionPane.QUESTION_MESSAGE));
       //input pin
       if ( pass < 10000 && pass > 0000)
       {
           //if pin is correct
           do{
               //choose account
               String f=JOptionPane.showInputDialog(null,"Please Choose Your Account "+"[1] Checking Account "
                       +"[2] Savings Account "+"[3] Loans ", "MyBank",JOptionPane.QUESTION_MESSAGE);
               num=Integer.parseInt(f);
               switch(num){
               //Checking account
               case 1:
                   String g=JOptionPane.showInputDialog(null,"Please Choose Your Transaction "
                           +"[1] Check Balance "
                           +"[2] Withdraw "+"[3] Deposit ", "MyBank",JOptionPane.QUESTION_MESSAGE);
                   Cnum=Integer.parseInt(g);
                   if (Cnum==1)
                   {
                       JOptionPane.showMessageDialog(null,
                               "Your Balance is "+CheckBalance+" dollars","ATM",
                               JOptionPane.INFORMATION_MESSAGE);
                   }
                   if (Cnum==2)
                   {
                       Cwid=Integer.parseInt(JOptionPane.showInputDialog(null,"Please Enter Amount to Withdraw "
                               ,"ATM",JOptionPane.INFORMATION_MESSAGE));
                       if(CheckBalance==200)
                       {
                           JOptionPane.showMessageDialog(null,"Your Balance is below 200",
                                   "ATM",JOptionPane.ERROR_MESSAGE);}
                       if (Cwid>CheckBalance)
                       {
                           JOptionPane.showMessageDialog(null,"Insufficient Funds!","ATM",JOptionPane.ERROR_MESSAGE);
                       }
                       CheckBalance=CheckBalance-Cwid;
                       JOptionPane.showMessageDialog(null,"Please collect your money"+" "+"Your Remaining Balance is"+CheckBalance,"ATM",JOptionPane.INFORMATION_MESSAGE);
                       if(CheckBalance<200){
                           JOptionPane.showMessageDialog(null,"Your Balance is below 200.Please maintain minimum balance","ATM",JOptionPane.ERROR_MESSAGE);}

                   }
                   else if (Cnum == 3)
                   {
                       Cdep=Integer.parseInt(JOptionPane.showInputDialog(null,""
                               + "Please Enter Amount to Deposit ",
                               "ATM",JOptionPane.INFORMATION_MESSAGE));
                       CheckBalance=Cdep+CheckBalance;
                       JOptionPane.showMessageDialog(null,"Your Current Balance is"+CheckBalance,"ATM",JOptionPane.INFORMATION_MESSAGE);
                   }
                   break;
                   //Savings account
               case 2:
                   String h=JOptionPane.showInputDialog(null,"Please Choose Your Transaction "
               +"[1] Check Balance "
               +"[2] Withdraw "
               +"[3] Deposit ", "MyBank",JOptionPane.QUESTION_MESSAGE);
                   Snum=Integer.parseInt(h);
                   if (Snum==1)
                   {
                       JOptionPane.showMessageDialog(null,"Your Balance is "+SaveBalance+" dollars","ATM",JOptionPane.INFORMATION_MESSAGE);
                   }
                   if (Snum==2)
                   {
                       Swid=Integer.parseInt(JOptionPane.showInputDialog(null,"Please Enter Amount to Withdraw "
                               ,"ATM",JOptionPane.INFORMATION_MESSAGE));
                       if (Swid>SaveBalance)
                       {
                           JOptionPane.showMessageDialog(null,"Insufficient Funds!","ATM",JOptionPane.ERROR_MESSAGE);
                       }
                       else
                       {
                           SaveBalance=SaveBalance-Swid;
                           JOptionPane.showMessageDialog(null,"Your Remaining Balance is"+SaveBalance,"ATM",JOptionPane.INFORMATION_MESSAGE);
                       }
                   }
                   //option 3 For deposit
                   else if (Snum ==3)
                       {
                           dep=Integer.parseInt(JOptionPane.showInputDialog(null,"Please Enter Amount to Deposit ",
                                   "ATM",JOptionPane.INFORMATION_MESSAGE));
                           SaveBalance=dep+SaveBalance;
                           JOptionPane.showMessageDialog(null,"Your Current Balance is"+SaveBalance,"ATM",JOptionPane.INFORMATION_MESSAGE);
                       }
                  
                   break;
                   //Loans
               case 3:
                   String i=JOptionPane.showInputDialog(null,"Please Choose the Loan you would like to make a payment on "+"[1] Mortgage "
                           +"[2] Student Loan "+"[3] Auto Loan " + "[4] Personal Loan ", "MyBank",JOptionPane.QUESTION_MESSAGE);
                   Lnum=Integer.parseInt(i);
                   if (Lnum==1)
                   {
                       JOptionPane.showMessageDialog(null,"Your Current Balance is "
                   +MortBalance+" dollars",
                   "ATM",
                   JOptionPane.INFORMATION_MESSAGE);
                       MortBalance=MortBalance-3500;
                       JOptionPane.showMessageDialog(null,
                               "Your remaing Mortgage loan is "+Math.abs(MortBalance),
                               "ATM",JOptionPane.INFORMATION_MESSAGE);
                   }
                   if (Lnum==2)
                   {
                       JOptionPane.showMessageDialog(null,"Your Current Balance is "+StudBalance+" dollars","ATM",JOptionPane.INFORMATION_MESSAGE);
                       StudBalance=StudBalance-250;
                       JOptionPane.showMessageDialog(null,"Your Student loan have to be paid is"+Math.abs(StudBalance),"ATM",JOptionPane.INFORMATION_MESSAGE);
                   }
                   if (Lnum==3)
                   {
                       JOptionPane.showMessageDialog(null,"Your Current Balance is "+AutoBalance+" dollars","ATM",JOptionPane.INFORMATION_MESSAGE);
                       AutoBalance=AutoBalance-500;
                       JOptionPane.showMessageDialog(null,"Your Auto loan have to paid is "+Math.abs(AutoBalance),"ATM",JOptionPane.INFORMATION_MESSAGE);
                   }
                   if (Lnum==4)
                   {
                       JOptionPane.showMessageDialog(null,"Your Current Balance is "+PersBalance+" dollars","ATM",JOptionPane.INFORMATION_MESSAGE);
                       PersBalance=PersBalance-1000;
                       JOptionPane.showMessageDialog(null,"Your Personal loan have to be paid is "+Math.abs(PersBalance),"ATM",JOptionPane.INFORMATION_MESSAGE);
                   }
                   break;
               default:System.exit(0);
               }
               //Return to top
               back=JOptionPane.showConfirmDialog(null,"Would you like to make another transaction","ATM",JOptionPane.YES_NO_OPTION);
           } while(back==0);
       }
  
       else{
           JOptionPane.showMessageDialog(null,"Please re-enter PIN","Incorrect PIN",JOptionPane.ERROR_MESSAGE);
       }
   }}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote