Begnner Java please help with simple methods !! Problem: Display Welcome Screen
ID: 3882809 • Letter: B
Question
Begnner Java please help with simple methods !!
Problem:
Display Welcome Screen
3. Allow user to slide card
a. Simulate card sliding by asking user to enter account number
i. Check account number against valid account numbers
– If number is invalid allow three attempts then print error message – Please contact your financial institution
– If number is valid proceed to Step 4.
4. Allow user to enter personal identification number (PIN)
a. Simulate by asking user to enter account number
i. Check PIN against valid PINs.
– If number is invalid allow three attempts then print error message – Please contact your financial institution
– If number is valid proceed to Step 5.
5. Display the main menu
a. Balance Inquiry
b. Fast Cash
c. Withdrawal
d. Deposit
e. Quit
6. Allow user to choose from menu – Assume MyATM is an object.
a. If choice = a proceed to the method to get the balance (i.e. MyATM.getBalance()) .
b. If choice = b proceed to the method to get the fast cash (i.e. MyATM.getFastCash()) .
c. If choice = c proceed to the method to withdraw cash (i.e. MyATM.getWithdrawal()) .
i. Ask user for amount of withdrawal
ii. If the balance > withdrawal amount proceed with transaction
– Subtract withdrawal.
– Update balance.
iii. If the balance < withdrawal announce insufficient funds and end transaction
iv. If the balance = withdrawal amount display warning message about balance and end transaction
d. If choice = d proceed to the method to accept the deposit (i.e. MyATM.getDeposit())
i. Ask user for amount of deposit
ii. Update balance
e. If choice = e proceed to the method to end the transaction(i.e. MyATM.endTranaction())
i. Print receipt if requested
ii. Print Thank You message to customer
Test Data
Valid Account Numbers
int [] AcctNum = { 1234, 2341, 3412, 4123}
Valid PINS
int [] PIN = {234, 341, 412, 123}
Beginning Balances
int [] InitBal = {1000, 2000, 300, 0}
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
MY CODE:
ATM.java
import javax.swing.*;
import java.util.Scanner;
public class ATM {
public static void main(String args[]){
int acctnumpanel, pinnumpanel;
Scanner input = new Scanner(System.in);
JOptionPane.showMessageDialog(null, "Welcome to Bank ");
int AcctNum[] = {1234, 2341, 3412,4123};
int PIN[]= {234, 341, 412, 123};
int InitBal[] = {1000,2000,300, 0};
acctnumpanel = Integer.parseInt(JOptionPane.showInputDialog("Please insert your account number!"));
if (acctnumpanel==1234)
System.out.println("valid");
if (acctnumpanel==2341)
System.out.println("valid");
if (acctnumpanel==3412)
System.out.println("valid");
if (acctnumpanel==4123)
System.out.println("valid");
else
System.out.println("Please try again");
pinnumpanel = Integer.parseInt(JOptionPane.showInputDialog("Please enter your pin number!"));
if (pinnumpanel==234)
System.out.println("valid");
if (pinnumpanel==341)
System.out.println("valid");
if (pinnumpanel==412)
System.out.println("valid");
if (pinnumpanel==123)
System.out.println("valid");
else
System.out.println("Please try again");
System.out.println("Welcome to main menu");
Balance balanceObject = new Balance();
balanceObject.BalanceInquiry();
FastCash fastcashobject = new FastCash();
fastcashobject.quickCash();
Withdraw withdrawObject = new Withdraw();
withdrawObject.withdrawMoney();
Deposit depositObject = new Deposit();
depositObject.depositMoney();
}
Balance.java
import java.util.Scanner;
public class Balance {
public void BalanceInquiry() {
Scanner aN = new Scanner(System.in);
int balance,
int aN=0;
System.out.println("Please select Account 1-4");
System.out.println(aN.nextLine());
switch (aN) {
case 1:
if (aN==1)
System.out.println("Welcome Account Number 1 your balance is $1000");
break;
case 2:
if (aN==2)
System.out.println("Welcome Account Number 2 your balance is $2000");
break;
case 3:
if (aN==3)
System.out.println("Welcome Account Number 3 your balance is $300");
break;
case 4:
if (aN==4)
System.out.println("Welcome Account Number 4");
break;
default:
System.out.println("Please Contack your Financial Institution");
}
}
}
FastCash.java
import java.util.Scanner;
public class FastCash {
public void quickCash() {
System.out.println(" Please enter fash cash amount");
Scanner temp = new Scanner(System.in);
System.out.println(temp.nextLine());
}
}
Withdraw.java
import java.util.Scanner;
public class Withdraw {
int balance;
int balance1=1000 ,balance2=2000,balance3=300, balance4 = 0;
Scanner withdraw = new Scanner(System.in);
public void withdrawMoney() {
System.out.println(" Please enter amount you would like to withdraw");
int temp= input.nextLine();
if (acctnumpanel==1234)
System.out.println("your new balance is " (balance1-withdraw));
if (acctnumpanel==2341)
System.out.println("your balance is" (balance2 - withdraw));
if (acctnumpanel==3412)
System.out.println("your balance is" (balance3 - withdraw));
if (acctnumpanel==4123)
System.out.println("your balance is" (balance4 - withdraw));
else
System.out.println("Please try again");
}
Deposit.java
import java.util.Scanner;
public class Deposit {
int balance;
int balance1=1000 ,balance2=2000,balance3=300, balance4 = 0;
Scanner depo = new Scanner(System.in);
public void depositMoney() {
System.out.println(" Please enter amount you would like to deposit");
int temp= input.nextLine();
if (acctnumpanel==1234)
System.out.println("your new balance is " (balance1+temp));
if (acctnumpanel==2341)
System.out.println("your balance is" (balance2 + temp));
if (acctnumpanel==3412)
System.out.println("your balance is" (balance3 + temp));
if (acctnumpanel==4123)
System.out.println("your balance is" (balance4 + temp));
else
System.out.println("Please try again");
}
}
}
}
}
}
Thx for help in advanced
Explanation / Answer
Here is your java ATM program:
ATM Java:
import javax.swing.*;
import java.util.Scanner;
public class ATM
{
int usertry=0;
int acctnumpanel, pinnumpanel;
int AcctNum[] = {1234, 2341, 3412,4123};
int account_index=0;
int PIN[]= {234, 341, 412, 123};
int InitBal[] = {1000,2000,300, 0};
boolean isac=false,ispin=false;
boolean CheckAcNo() //to check account no
{
acctnumpanel = Integer.parseInt(JOptionPane.showInputDialog("Please insert your account number!"));
{
for(int i=0;i<AcctNum.length;i++)
{
if(AcctNum[i]==acctnumpanel)
{
account_index=i;
usertry=0;
isac=true;
return isac;
}
}
}
if(usertry>2)
return isac;
System.out.println("Wrong Account no");
usertry++;
CheckAcNo();
return isac;
}
boolean CheckPinNo()//to check pin no
{
pinnumpanel = Integer.parseInt(JOptionPane.showInputDialog("Please enter your pin number!"));
if(PIN[account_index]==pinnumpanel)
{
usertry=0;
ispin=true;
return ispin;
}
if(usertry>2)
return ispin;
System.out.println("Wrong PIN");
usertry++;
CheckPinNo();
return ispin;
}
int getBalance(int index)//to get balance
{
return InitBal[index];
}
void withdraw(int amount)//to withdraw
{
if(amount>InitBal[account_index])
JOptionPane.showMessageDialog(null,"You dont have that much money");
else
{
InitBal[account_index]-=amount;
JOptionPane.showMessageDialog(null,"Withdraw done");
menu();
}
}
void deposit(int amount)//to deposit
{
InitBal[account_index]+=amount;
JOptionPane.showMessageDialog(null,"deposit done");
menu();
}
void menu()
{
int menuinput = Integer.parseInt(JOptionPane.showInputDialog("Menu 1. Balance Inquiry " +
"2. Fast Cash " +
"3. Withdrawal " +
"4. Deposit " +
"5. Quit"));
switch(menuinput)
{
case 1:
JOptionPane.showMessageDialog(null,getBalance(account_index));
menu();
break;
case 2:
JOptionPane.showMessageDialog(null,"Sorry you didnt provide any info about this option");
break;
case 3:
int amount = Integer.parseInt(JOptionPane.showInputDialog("Enter amount"));
withdraw(amount);
break;
case 4:
int depositamount = Integer.parseInt(JOptionPane.showInputDialog("Enter amount"));
deposit(depositamount);
break;
case 5:
System.exit(0);
break;
default:
System.out.println("wrong menu item");
menu();
}
}
public static void main(String[] args)
{
ATM ob=new ATM();
Scanner input = new Scanner(System.in);
JOptionPane.showMessageDialog(null, "Welcome to Bank ");
if(ob.CheckAcNo())
{
if(ob.CheckPinNo())
{
System.out.println("Welcome to main menu");
ob.menu();
}
else
{
JOptionPane.showMessageDialog(null, "Please contact your financial institution");
System.exit(0);
}
}
else
{
JOptionPane.showMessageDialog(null, "Please contact your financial institution");
System.exit(0);
}
}
}
I hope this solves your problem
Comment if you have any problem in above code
And please give it a thumbs up if it solved your problem :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.