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

With the following code, What kind of GUI, for example, JFrame Frame, JPanel pan

ID: 3834268 • Letter: W

Question

With the following code, What kind of GUI, for example, JFrame Frame, JPanel panel, or other ones, can I insert into the code.

Please and Thank You for your time.

//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 java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class GuiAccTest extends Frame implements ActionListener
{
        Label lab=new Label("                                                                                                                                                                 ");
        Label lab1=new Label("                                                                                                                                                                 ");
        TextField t[]=new TextField [4];
        Label l[]=new Label [4];
        Button but=new Button("Create Account");
        Button but1=new Button("Test Account");
        BankAccount b;
        GuiAccTest()
        {
                addWindowListener(new NewWindowAdapter());
                setLayout(new GridLayout(2,0));
                Panel p=new Panel();
                Panel p1=new Panel();
                but.addActionListener(this);
                but1.addActionListener(this);
                p.setLayout(new GridLayout(5,2));
                p1.add(lab1);
                p1.add(lab);
                l[0]=new Label("Account Number");
                l[1]=new Label("Initial Balance");
                l[2]=new Label("Deposit Amount");
                l[3]=new Label("Withdraw Amount");
                for(int i=0;i<4;i++)
                {
                        t[i]=new TextField(10);
                        p.add(l[i]);
                        p.add(t[i]);
                }
                p.add(but);
                p.add(but1);
                but1.setVisible(false);
                l[2].setVisible(false);
                l[3].setVisible(false);
                t[2].setVisible(false);
                t[3].setVisible(false);
                add(p);
                add(p1);
        }
        String testAccount(int d_amt,int w_amt)
        {
                String msg;
                b.deposit(d_amt);
                msg="Transaction Succesful";
                try
                {
                        b.withdraw(w_amt);
                }catch(FundsInsufficientException fe)
                {
                        fe=new FundsInsufficientException(b.amount,w_amt);
                        msg=String.valueOf(fe);
                }
                return msg;
        }
        public void actionPerformed(ActionEvent ae)
        {
                String str=ae.getActionCommand();
                if(str.equals("Create Account"))
                {
                        b=new BankAccount(Integer.parseInt(t[0].getText()),Integer.parseInt(t[1].getText()));
                        but1.setVisible(true);
                        l[2].setVisible(true);
                        l[3].setVisible(true);
                        t[2].setVisible(true);
                        t[3].setVisible(true);
                        but.setVisible(false);
                        l[0].setVisible(false);
                        l[1].setVisible(false);
                        t[0].setVisible(false);
                        t[1].setVisible(false);
                        lab1.setText("Account : "+b.accnum+", Current Balance : "+b.amount);
                        return;
                }
                else
                {
                        lab.setText(testAccount(Integer.parseInt(t[2].getText()),Integer.parseInt(t[3].getText())));
                        lab1.setText("Account : "+b.accnum+", Current Balance : "+b.amount);
                }
        }
        public static void main(String arg[])
        {
                GuiAccTest at=new GuiAccTest();
                at.setTitle("Bank Account Tester");
                at.setSize(600,200);
                at.setVisible(true);
        }
}
class NewWindowAdapter extends WindowAdapter
{
        public void windowClosing(WindowEvent we)
        {
                System.exit(0);
        }
}
class BankAccount
{
        int accnum;
        int amount;
        BankAccount(int num,int amt)
        {
                accnum=num;
                amount=amt;
        }
        public void deposit(int amt)
        {
                amount=amount+amt;
        }
        public void withdraw(int amt) throws FundsInsufficientException
        {
                if(amt>amount)
                        throw new FundsInsufficientException(amount,amt);
                else
                        amount=amount-amt;
        }
}
class FundsInsufficientException extends Exception
{
        int balance;
        int withdraw_amount;
        FundsInsufficientException(int bal,int w_amt)
        {
                balance=bal;
                withdraw_amount=w_amt;
        }
        public String toString()
        {
                return "Your withdraw amount ("+withdraw_amount+") is less than the balance ("+balance+"). No withdrawal was recorded.";
        }
}

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