Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Encryption/Decryption Problem Description For this Project you will be working with the BankSimulator, BankAccount, and BankData classes from this weeks Example BlueJ file. import java.io.IOException;

Encryption/Decryption

Problem Description

For this Project you will be working with the BankSimulator, BankAccount, and BankData classes from this weeks Example BlueJ file.

import java.io.IOException; import java.util.Scanner;

/** This program demonstrates random access. You can access existing accounts and deposit money, or create new accounts. The accounts are saved in a random access file. */ public class BankSimulator { public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); BankData data = new BankData(); try { data.open("bank.dat");

boolean done = false; while (!done) { System.out.print("Account number: "); int accountNumber = in.nextInt(); System.out.print("Amount to deposit: "); double amount = in.nextDouble();

int position = data.find(accountNumber); BankAccount account; if (position >= 0) { account = data.read(position); account.deposit(amount); System.out.println("New balance: " + account.getBalance()); } else // Add account { account = new BankAccount(accountNumber, amount); position = data.size(); System.out.println("Adding new account."); } data.write(position, account);

System.out.print("Done? (Y/N) "); String input = in.next(); if (input.equalsIgnoreCase("Y")) { done = true; } } } finally { data.close(); } System.out.println(" Thank you for using the Bank Simulator. Good Bye."); } }

/** A bank account has a balance that can be changed by deposits and withdrawals. */ public class BankAccount { private int accountNumber; private double balance;

/** Constructs a bank account with a zero balance. @param anAccountNumber the account number for this account */ public BankAccount(int anAccountNumber) { accountNumber = anAccountNumber; balance = 0; }

/** Constructs a bank account with a given balance. @param anAccountNumber the account number for this account @param initialBalance the initial balance */ public BankAccount(int anAccountNumber, double initialBalance) { accountNumber = anAccountNumber; balance = initialBalance; }

/** Gets the account number of this bank account. @return the account number */ public int getAccountNumber() { return accountNumber; }

/** Deposits money into the bank account. @param amount the amount to deposit */ public void deposit(double amount) { double newBalance = balance + amount; balance = newBalance; }

/** Withdraws money from the bank account. @param amount the amount to withdraw */ public void withdraw(double amount) { double newBalance = balance - amount; balance = newBalance; }

/** Gets the current balance of the bank account. @return the current balance */ public double getBalance() { return balance; } }

import java.io.IOException; import java.io.RandomAccessFile;

/** This class is a conduit to a random access file containing bank account records. */ public class BankData { private RandomAccessFile file;

public static final int INT_SIZE = 4; public static final int DOUBLE_SIZE = 8; public static final int RECORD_SIZE = INT_SIZE + DOUBLE_SIZE;

/** Constructs a BankData object that is not associated with a file. */ public BankData() { file = null; }

/** Opens the data file. @param filename the name of the file containing bank account information */ public void open(String filename) throws IOException { if (file != null) { file.close(); } file = new RandomAccessFile(filename, "rw"); }

/** Gets the number of accounts in the file. @return the number of accounts */ public int size() throws IOException { return (int) (file.length() / RECORD_SIZE); }

/** Closes the data file. */ public void close() throws IOException { if (file != null) { file.close(); } file = null; }

/** Reads a bank account record. @param n the index of the account in the data file @return a bank account object initialized with the file data */ public BankAccount read(int n) throws IOException { file.seek(n * RECORD_SIZE); int accountNumber = file.readInt(); double balance = file.readDouble(); return new BankAccount(accountNumber, balance); }

/** Finds the position of a bank account with a given number. @param accountNumber the number to find @return the position of the account with the given number, or -1 if there is no such account */ public int find(int accountNumber) throws IOException { for (int i = 0; i < size(); i++) { file.seek(i * RECORD_SIZE); int a = file.readInt(); if (a == accountNumber) { return i; } // Found a match } return -1; // No match in the entire file }

/** Writes a bank account record to the data file. @param n the index of the account in the data file @param account the account to write */ public void write(int n, BankAccount account) throws IOException { file.seek(n * RECORD_SIZE); file.writeInt(account.getAccountNumber()); file.writeDouble(account.getBalance()); } }

Change them so that:

There is a GUI front-end

The Account Number and Balance are encrypted and stored.

Come up with a SIMPLE encryption algorithm

Specifications

The program should the following components:

Account Number label and field

Balance label and field

Format as a currency field

User cannot change.

Deposit Amount label and field

Deposit Button - Deposits the amount entered

Clear Button Clears all fields.

Exit Button Terminates the program.

Error Checking

A numeric amount in the Deposit Amount field when the Deposit Button is pressed.

try-catch blocks where appropriate.

Commenting

No loop variables. a, b, c, x, y, z, etc.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

How often will the 360 feedback process be repeated?

Answered: 1 week ago