Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Main
- public static void main(String[] args) throws IOException{
- Scanner sc = new Scanner(System.in);
- Bank_Transact bt = new Bank_Transact();
- bt.storeInfo();
- bt.enterPin();
- bt.menu();
- }
- Bank_Transact
- public void menu() throws IOException{
- System.out.println("Welcome to Power Bank");
- System.out.println("[B] Balance Inquiry");
- System.out.println("[W] Withdraw");
- System.out.println("[D] Deposit");
- System.out.println("[X] Exit");
- char choice = sc.next().charAt(0);
- options(choice, infoPin);
- }
- public void options(char c, String p) throws IOException{
- FileWriter f2 = new FileWriter("C:\\Users\\DELL\\Desktop\\CUST.txt");
- char ans;
- switch(c){
- case 'b':
- case 'B':
- inf.forEach(in -> {
- if(p.equals(in.getPin()))
- System.out.println("The current is PHP " + df.format(Double.parseDouble(in.getDeposit())));
- });
- System.out.print("Do you want to do another transaction[y/n]? ");
- ans = sc.next().charAt(0);
- if(ans == 'y' || ans == 'Y'){
- menu();
- }
- else
- System.exit(0);
- break;
- case 'w':
- case 'W':
- inf.forEach(in -> {
- if(p.equals(in.getPin())){
- System.out.print("Enter the amount to be withdrawn: ");
- int withdraw = sc.nextInt();
- double tempW = Double.valueOf(in.getDeposit()) - withdraw;
- in.setDeposit(Double.toString(tempW));
- }
- });
- System.out.print("Do you want to do another transaction[y/n]? ");
- ans = sc.next().charAt(0);
- if(ans == 'y' || ans == 'Y'){
- menu();
- }
- else
- System.exit(0);
- break;
- case 'd':
- case 'D':
- inf.forEach(in -> {
- if(p.equals(in.getPin())){
- System.out.println("This machine accepts bills only.");
- System.out.print("Enter deposit amount: ");
- double dep = sc.nextDouble();
- double tempB = Double.parseDouble(in.getDeposit()) + dep;
- in.setDeposit(Double.toString(tempB));
- }
- });
- System.out.print("Do you want to do another transaction[y/n]? ");
- ans = sc.next().charAt(0);
- if(ans == 'y' || ans == 'Y'){
- menu();
- }
- else
- System.exit(0);
- break;
- case 'x':
- case 'X':
- for(InfoClass in : inf) {
- System.out.println(in.getPin() + "\t" + in.getName() + "\t" + df.format(Double.parseDouble(in.getDeposit())));
- f2.write(in.getPin());
- f2.write(System.getProperty( "line.separator" ));
- f2.write(in.getName());
- f2.write(System.getProperty( "line.separator" ));
- f2.write(in.getDeposit());
- f2.write(System.getProperty( "line.separator" ));
- }
- f2.close();
- }
- }
- InfoClass
- protected String pin;
- protected String name;
- protected String deposit;
- public InfoClass(){
- pin = "";
- name = "";
- deposit = "";
- }
- public InfoClass(String pin, String name, String deposit){
- this.pin = pin;
- this.name = name;
- this.deposit = deposit;
- }
- public String getPin(){
- return pin;
- }
- public void setPin(String pin){
- this.pin = pin;
- }
- public String getName(){
- return name;
- }
- public void setName(String name){
- this.name = name;
- }
- public String getDeposit(){
- return deposit;
- }
- public void setDeposit(String deposit){
- this.deposit = deposit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement