- Joined
- May 30, 2015
- Posts
- 1,968
- Solutions
- 1
- Reaction
- 4,933
- Points
- 1,079
Pa help naman po sa project ko. First year IT student po ako. Kailangan ko pong gumawa ng ATM program na :
Nagba-balance/wí†hdráw/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. wí†hdráw \n 4. Exit \n Enter Choice :", "ATM",3));
switch (choice) {
case 1 :
inquiry();
break;
case 2:
deposit();
break;
case 3:
wí†hdráw();
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 wí†hdráw() {
int wí†hdráw = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter amount to be wí†hdráwn "));
if(wí†hdráw>cash) {
JOptionPane.showMessageDialog(null, "Your current balance " + two.format(cash));
}
else {
cash-=wí†hdráw;
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) {
}
}
}
Nagba-balance/wí†hdráw/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. wí†hdráw \n 4. Exit \n Enter Choice :", "ATM",3));
switch (choice) {
case 1 :
inquiry();
break;
case 2:
deposit();
break;
case 3:
wí†hdráw();
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 wí†hdráw() {
int wí†hdráw = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter amount to be wí†hdráwn "));
if(wí†hdráw>cash) {
JOptionPane.showMessageDialog(null, "Your current balance " + two.format(cash));
}
else {
cash-=wí†hdráw;
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) {
}
}
}