🔒 Closed Sample ATM

Status
Not open for further replies.

AnimePahe

Forum Guru
Pa help naman po sa project ko. First year IT student po ako. Kailangan ko pong gumawa ng ATM program na :

Nagba-balance/withdraw/deposit (done)
Chine-check kung existing ba 'yung account number (done)
Kailangan 8 digits lang 'yung account number (help)
Username and password (help)

Sana matulungan niyo ako. Hindi ko na kasi siya ma-gets :( Advance din 'yung mga nabasa ko sa google kaya 'di ko din ma-apply.

So ito po 'yung code ko :

import java.text.*;
import javax.swing.JOptionPane;
import java.util.*;
import java.io.*;

public class Bank {

public static double cash;
public static int account;
public static int register;
public static DecimalFormat two = new DecimalFormat("0.00");

public static void main(String[] args) {
myAccount();
mainMenu();

}

static void myAccount() {

int account = Integer.parseInt(JOptionPane.showInputDialog(null,"1. Register Account \n 2. Login \n 3. Exit"));
readTextFile();

switch (account) {

case 1:
registerAccount();
break;

case 2 :
loginAccount();

case 3:
System.exit(0);
break;

}

}

static void registerAccount() {
register = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter 8-Digit Account Number"));
double deposit = Double.parseDouble(JOptionPane.showInputDialog(null,"Enter initial deposit"));
cash=deposit;
checkTextFile();
registerTextFile();
myAccount();
}

static void loginAccount() {
account = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter 8-digit account number"));

if(account==register) {
JOptionPane.showMessageDialog(null,"Your account exists.");
JOptionPane.showInputDialog(null,"Please enter a new 8-digit number.");
mainMenu();
}

else {
JOptionPane.showMessageDialog(null,"Your account doesn't exists.");
myAccount();
}

mainMenu();
}


static void checkTextFile() {
try {
Scanner myNotepad = new Scanner (new File ("account.txt"));
account=myNotepad.nextInt();
} catch (Exception e) {

}

}

static void registerTextFile() {
try {
FileWriter out = new FileWriter("account.txt",false);
out.write(Double.toString(cash));
} catch (Exception e) {

}
}

static void mainMenu() {
readTextFile();

int choice = Integer.parseInt(JOptionPane.showInputDialog(null,"1. Balance Inquiry \n 2. Deposit \n 3. Withdraw \n 4. Exit \n Enter Choice :", "ATM",3));

switch (choice) {

case 1 :
inquiry();
break;

case 2:
deposit();
break;

case 3:
withdraw();
break;

case 4:
myAccount();
break;

}

}

static void inquiry() {

JOptionPane.showMessageDialog(null, "Your current balance " + two.format(cash));
mainMenu();
readTextFile();

}

static void deposit() {
double deposit = Double.parseDouble(JOptionPane.showInputDialog(null,"Enter amount to be deposited","ATM",3));
cash+=deposit;
writeTextFile();
JOptionPane.showMessageDialog(null, "Your current balance " + two.format(cash));
mainMenu();
}

static void withdraw() {
int withdraw = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter amount to be withdrawn "));
if(withdraw>cash) {
JOptionPane.showMessageDialog(null, "Your current balance " + two.format(cash));
}

else {
cash-=withdraw;
writeTextFile();
JOptionPane.showMessageDialog(null, "Your current balance " + two.format(cash));
}
}

static void readTextFile() {
try {
Scanner myNotepad = new Scanner (new File ("cash.txt"));
cash=myNotepad.nextDouble();
} catch (Exception e) {

}
}

static void writeTextFile() {
FileWriter out;
try {
out = new FileWriter("cash.txt",false);
out.write(Double.toString(cash));
out.close();
} catch (Exception e) {

}

}


}
 
tama. gamit ka ng len, length, count or any function ni Java para mabilang mo kung 8 characters sya. tapos saka mo gamitan yung uname at pw matching ng combination of Equality and conditional operators para malaman mo kung match yung usname na nasa record at pw na nasa record. gamit ka ng id nung user para mabilis ang pullout ng data nung user. kaya mo yan kid. lahat ng stud dumaan sa ganyan.
 
tama. gamit ka ng len, length, count or any function ni Java para mabilang mo kung 8 characters sya. tapos saka mo gamitan yung uname at pw matching ng combination of Equality and conditional operators para malaman mo kung match yung usname na nasa record at pw na nasa record. gamit ka ng id nung user para mabilis ang pullout ng data nung user. kaya mo yan kid. lahat ng stud dumaan sa ganyan.
Salamat po. Medyo hirap padin ako sa user at pass haha. Anyways, thank you po sa inyo.
 
Status
Not open for further replies.

About this Thread

  • 4
    Replies
  • 425
    Views
  • 3
    Participants
Last reply from:
AnimePahe

Trending Topics

Online now

Members online
439
Guests online
1,484
Total visitors
1,923

Forum statistics

Threads
2,279,849
Posts
28,993,576
Members
1,226,183
Latest member
gro
Back
Top