Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //BANK ACCOUNT CLASS
- package l8q2;
- import java.util.Scanner;
- import java.io.PrintWriter;
- import java.io.FileOutputStream;
- import java.io.IOException;
- /**
- *
- * @author WIF170096
- */
- public class BankAccount {
- Scanner k = new Scanner(System.in);
- private String name;
- private String ic;
- private double depo;
- double savings = 0;
- double withdraw = 0;
- double savings_initial = 0;
- public BankAccount(){
- }
- public BankAccount(String a, String b, double c){
- name = a;
- ic = b;
- savings = c;
- savings_initial = c;
- }
- public String getName(){
- System.out.print("Enter your name: ");
- name = k.nextLine();
- return name;
- }
- public String getIC(){
- System.out.print("Enter your IC: ");
- ic = k.next();
- return ic;
- }
- public double getDepo(){
- depo = k.nextDouble();
- savings_initial = depo;
- return depo;
- }
- public void deposit(){
- savings = savings + depo;
- }
- public void withdraw(){
- withdraw = k.nextDouble();
- savings = savings - withdraw;
- }
- public void display(){
- System.out.printf("Updated balance = RM %.2f \n", savings);
- }
- public void current(){
- System.out.printf("%.2f", savings);
- }
- public void Log(){
- try{
- PrintWriter os = new PrintWriter(new FileOutputStream("Z:/L8Q2/log.txt"));
- os.println("Name: " + name);
- os.println("IC; " + ic);
- os.println("Initial savings: " + savings_initial);
- os.println("Deposit amount: " + depo);
- os.println("Withdraw amount: " + withdraw);
- os.println("Final amount: " + savings);
- os.close();
- System.out.println("Logged");
- }
- catch (IOException e) {
- System.out.println("Problem with output");
- }
- }
- }
- // MAIN/TESTER CLASS
- package l8q2;
- import java.util.Scanner;
- import java.io.PrintWriter;
- import java.io.FileOutputStream;
- import java.io.IOException;
- /**
- *
- * @author WIF170096
- */
- public class L8Q2 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- Scanner p = new Scanner(System.in);
- BankAccount s1 = new BankAccount();
- s1.getName();
- s1.getIC();
- System.out.print("Enter deposit amount: ");
- s1.getDepo();
- s1.deposit();
- System.out.print("Select your transactions(Current Balance: ");
- s1.current();
- System.out.print("):\n");
- System.out.println("1.Deposit \n2.Withdrawal ");
- int check = p.nextInt();
- switch(check){
- case 1:System.out.println("Enter your deposit amount: ");
- s1.getDepo();
- s1.deposit();
- s1.display();
- s1.Log();
- break;
- case 2:System.out.println("Enter your withdrawal amount: ");
- s1.withdraw();
- s1.display();
- s1.Log();
- break;
- default:System.out.println("Please insert the right number.");
- s1.Log();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement