By GokiSoft.com|
19:49 20/02/2023|
Java Basic
[Source Code] Java Basic - Quản lý ATM - Quản lý tài khoản ngân hàng - C2206L
Java Basic - Quản lý ATM - Quản lý tài khoản ngân hàng
#Account.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.gokisoft.lesson10.bt1302;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
*
* @author diepvan
*/
public class Account {
String accountName;
String accountNo;
int money;
String phoneNumber;
String address;
List<Transaction> transferList;
List<Transaction> addList;
public Account() {
transferList = new ArrayList<>();
addList = new ArrayList<>();
}
public String getAccountName() {
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
public String getAccountNo() {
return accountNo;
}
public void setAccountNo(String accountNo) {
this.accountNo = accountNo;
}
public int getMoney() {
return money;
}
public void setMoney(int money) {
this.money = money;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public String toString() {
return "accountName=" + accountName + ", accountNo=" + accountNo + ", money=" + money + ", phoneNumber=" + phoneNumber + ", address=" + address;
}
public void input() {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap ten: ");
accountName = scan.nextLine();
System.out.println("Nhap STK: ");
accountNo = scan.nextLine();
System.out.println("Nhap so tien: ");
money = Integer.parseInt(scan.nextLine());
System.out.println("Nhap SDT: ");
phoneNumber = scan.nextLine();
System.out.println("Nhap dia chi: ");
address = scan.nextLine();
}
public void transfer() {
Transaction tran = new Transaction();
tran.transfer();
if(tran.getMoney() <= money) {
money -= tran.getMoney();
transferList.add(tran);
}
}
public void add() {
Transaction tran = new Transaction();
tran.add();
money += tran.getMoney();
addList.add(tran);
}
public void showTransferHistory() {
System.out.println("Lich su chuyen tien: ");
for (Transaction transaction : transferList) {
System.out.println(transaction.toStringTranser());
}
}
public void showAddHistory() {
System.out.println("Lich su nap tien: ");
for (Transaction transaction : addList) {
System.out.println(transaction.toStringAdd());
}
}
public void display() {
System.out.println(this);
}
}
#Main.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.gokisoft.lesson10.bt1302;
import java.util.Scanner;
/**
*
* @author diepvan
*/
public class Main {
public static void main(String[] args) {
Account account = new Account();
Scanner scan = new Scanner(System.in);
int choose;
//Kiem tra login
System.out.println("======== LOGIN =========");
do {
System.out.println("Nhap ten tai khoan: ");
String username = scan.nextLine();
System.out.println("Nhap mat khau: ");
String pwd = scan.nextLine();
if(username.equalsIgnoreCase("dieptv") && pwd.equals("123")) {
System.out.println("Dang nhap thanh cong!!!");
break;
} else {
System.out.println("Kiem tra tai khoan hoac mat khau!!!");
}
} while(true);
do {
showMenu();
choose = Integer.parseInt(scan.nextLine());
switch (choose) {
case 1:
account.input();
break;
case 2:
account.add();
break;
case 3:
account.transfer();
break;
case 4:
account.showAddHistory();
break;
case 5:
account.showTransferHistory();
break;
case 6:
System.out.println("Thoat!!!");
break;
default:
System.out.println("Nhap sai!!!");
break;
}
} while (choose != 6);
}
static void showMenu() {
System.out.println("1. Khoi tao tai khoan");
System.out.println("2. Nap tien");
System.out.println("3. Gui tien");
System.out.println("4. Xem lich su nap tien");
System.out.println("5. Xem lich su gui tien");
System.out.println("6. Thoat");
System.out.println("Chon: ");
}
}
#Transaction.java
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.gokisoft.lesson10.bt1302;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
/**
*
* @author diepvan
*/
public class Transaction {
String accountNo;
int money;
Date createdAt;
String node;
public Transaction() {
}
public String getAccountNo() {
return accountNo;
}
public void setAccountNo(String accountNo) {
this.accountNo = accountNo;
}
public int getMoney() {
return money;
}
public void setMoney(int money) {
this.money = money;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public String getNode() {
return node;
}
public void setNode(String node) {
this.node = node;
}
public String toStringTranser() {
return "accountNo=" + accountNo + ", money=" + money + ", createdAt=" + getCreatedAtString() + ", node=" + node;
}
public String toStringAdd() {
return "money=" + money + ", createdAt=" + getCreatedAtString() + ", node=" + node;
}
public void transfer() {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap TK nhan: ");
accountNo = scan.nextLine();
do {
System.out.println("Nhap so tien: ");
money = Integer.parseInt(scan.nextLine());
} while(money <= 0);
System.out.println("Noi dung chuyen tien: ");
node = scan.nextLine();
createdAt = new Date();
}
public void add() {
Scanner scan = new Scanner(System.in);
do {
System.out.println("Nhap so tien nap: ");
money = Integer.parseInt(scan.nextLine());
} while(money <= 0);
System.out.println("Noi dung nap tien: ");
node = scan.nextLine();
createdAt = new Date();
}
public String getCreatedAtString() {
DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
String strDate = dateFormat.format(createdAt);
return strDate;
}
}
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)