Question:
Write a Java program to demonstrate the use of inheritance, polymorphism, interfaces and ...?
anonymous
2011-11-16 09:22:40 UTC
Write a Java program to demonstrate the use of inheritance, polymorphism, interfaces and transaction processing. This program will also use the Vector class.

Class Definitions:
You are to begin with the following class (Account.java):

public class Account implements AccountAction {
protected String accountNo, institution, name;
protected double balance;
public Account (String accountNo, String name, String institution,
double balance) {
this.name = name;
this.accountNo = accountNo;
this.balance = balance;
this.institution = institution;
}
public String getAccount() {
return accountNo;
}
/* interface is implemented at this level, but is not used to
manipulate the account directly. The subclasses will override
these. */
public boolean debitAccount(double amt) {
return false;
}
public boolean creditAccount(double amt) {
return false;
}
}

and interface (AccountAction.java):

public interface AccountAction {
public boolean debitAccount(double amt);
public boolean creditAccount(double amt);
}

Make sure these are in different files. You will create two additional files that are the classes CreditCard and CheckingAccount. The two classes will be subclasses of the Account class defined above.

The CheckingAcount class needs no additional instance variables and the CreditCard class will need two additional instance variables:

private int creditLimit;
private double availableCredit;


The CheckingAccount and CreditCard classes should define at least one constructor each. In addition they should override the method toString() and override the debitAccount() and creditAccount() interface methods.

Main Program

The main() method is responsible for verifying two command-line arguments. The first is the transaction file, the second is an error log file. All errors encountered with transactions will be logged to that file (see below).

It is recommended that you create two addition methods:

private static Account findAccount(Vector a, String acctNo)

and

private static void performTrans(Vector a, String action, PrintWriter log)

The first method will assist you in finding an account in the vector that is to have the transaction applied to it. The findAccount() method should return null if the account is not found in the Vector.The second method will free the main() method of the responsibility of the parsing of the transaction components.

All of these methods should be defined in d5.java.

Transaction Processing:

You will need to process transactions from a data file. Each transaction will have its components separated by colons so you can use a split() method call. Each transaction will have different component counts.

The possible transactions are: create, debit, credit and report. Here is an example transaction file:

create:checking:14-748658:First Niagara:John Smith:2000
create:credit:1234678965438765:First Card:Agnes Jones:5000
report
debit:14-748658:500
debit:1234678965438765:700
credit:14-748658:25
report


Details of the transactions:
? All accounts should be stored in a single Vector after they are created.
? New credit cards have a zero balance and the credit limit is specified in the create transaction.
? New checking accounts have the balance specified in the create transaction.
? A debit is a subtraction in all cases.
? A credit is an addition all cases.
? A debit must be denied when there is insufficient funds or greater than available credit.
? The credit card availableCredit must be accurately maintained.
? All data from a report transaction is to be sent to the screen.
? Any errors encountered should be written to the log file.
An example error log is as follows:
Invalid account: debit:10-839723:200
Transaction denied: debit:1234567898765432:600

An example report should include all the components shown:

Account Summary:
Checking account #10-3784665
Bank: Chase
Name on account: Joe Holder
Balance: 1526.33

Credit Account #1234567898765432
Bank: First Card
Issued to: Bob Badger
Credit Limit: 4000
Balance: 3500.00
Available credit: 500.00

Checking account #11-3478645
Bank: Dime
Name on account: Melissa Martin
Balance: 1030.00

End account summary.

The use of foreach loops is very helpful in this project. The code to perform the transactions will make use of several if/else-if/else blocks. Be sure to understand the use of compareTo() and/or compareToIgnoreCase() for processing the transactions.



Transaction test file
Contents of d5.dat:

create:checking:10-3784665:Chase:Joe Holder:2000
create:credit:1234567898765432:First Card:Bob Badger:4000
create:checking:11-3478645:Dime:Melissa Martin:1000
report
debit:10-3784665:523.67
debit:1234567898765432:3500
credit:10-3784665:50
credit:11-3478645:30
debit:10-839723:200
debit:1234567898765432:600
report
Three answers:
McFate
2011-11-16 09:38:19 UTC
If you have a specific question, I'll gladly help. But this looks very much you asking people to do your entire assignment for you.



Imagine that you get someone here at Yahoo Answers to write your entire project for you. What happens later on in the semester when the projects are too complicated for anyone to do here -- and you're on your own, without the experience of working out the easier problems? You'll be sunk.



Someone who does entire homework problems for you, is NOT helping you in the long run, in my opinion. I'll gladly help you with small pieces when you are stuck, or with specific questions. But I'm not going to set you up to fail in your class.
Cynthia
2016-05-16 13:59:24 UTC
It depends how you want to do it. I don't know how your classes, methods or data are set up, so I couldn't say what is necessarily the most effective way.
zinerhat
2011-11-16 09:23:58 UTC
do your own homework


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...