Write a java code method that will allow you to withdraw an amount from a bank a
ID: 3654653 • Letter: W
Question
Write a java code method that will allow you to withdraw an amount from a bank account. Also, write a java code method that will allow you to deposit into an account as well.Explanation / Answer
import java.util.*; public class CheckingAccount { public static void main(String[] args) { Scanner input = new Scanner(System.in); final int FLAG = 0; double moneyEntry=0.0; System.out.println("Enter deposits and/or withdrawals. End with " + FLAG); int i=0; moneyEntry = input.nextDouble(); double [] deposit = new double [100]; double [] withdrawal = new double [100]; while(moneyEntry!= FLAG) { for ( i= 0; i < 100000; i ++) if (moneyEntry >0.0) { deposit [i] = 0; deposit [i]+=moneyEntry; moneyEntry = input.nextInt(); } else withdrawal [i] = 0; withdrawal [i]+=moneyEntry; moneyEntry = input.nextInt(); } System.out.printf("%8s%20s %n" , "Transaction" , "Balance"); for ( i = 0; i < 100000; i++) System.out.printf("%8s%20s " , deposit[i]); System.out.printf("%8s%20s " , withdrawal[i]); System.out.println(); } } or import java.io.*; // needed for File and IOException import java.util.Scanner; //imports scanner class import java.text.DecimalFormat; public class DepositWithdraw { public static void main(String[] args)throws IOException { double intRate ; double interestEarned; double amount=0.00; double bal=500.00; // Create a Scanner object for keyboard input. Scanner keyboard = new Scanner(System.in); // Get the annual interest rate. System.out.print("What is the annual interest rate?"); intRate= keyboard.nextDouble(); // Create a SavingAccount object. SavingAccount SavingAccount1= new SavingAccount(bal,intRate); // Open the Deposits.txt file. File file = new File ("Deposits.txt"); System.out.println("works1"); Scanner inputFile = new Scanner(file); // Get the deposits from the Deposits.txt file while (inFile.hasNext()) while (inputFile.hasNext()); { System.out.println("works1"); //Read numbers double num1 = inputFile.nextDouble(); //Add the numbers amount += num1; } System.out.println("works2"); //Deposit the file input. SavingAccount1.deposit(amount); //Close the Deposits.txt file inputFile.close(); // Open the Withdrawals.txt file. //Open Withdrawal file File file2 = new File("Withdrawal.txt"); Scanner inputFile2 = new Scanner(file2); System.out.println("works3"); // Get the withdrawals from the Withdrawals.txt file while (inFile.hasNext()) while (inputFile2.hasNext()); { //Read numbers double num2 = inputFile2.nextDouble(); //Subtract amount-= num2; } System.out.println("works4"); inputFile2.close(); // Close the Withdrawals.txt file. // Get the balance before adding interest. SavingAccount1.getBalance(); // Add the interest. SavingAccount1.addInterest(); // Calculate the interest earned. SavingAccount1.getLastInterest(); System.out.println("works5"); // Display the interest earned and the balance. System.out.println("Account balance $" + SavingAccount1.getBalance()); System.out.println("Total interest earned $" + SavingAccount1.getLastInterest()); } }//end classRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.