QuestionQuestion

Problem Description
In this you will create many useful classes for our end goal of making an ATM database!

• Transaction
o Keeps track of withdrawals/deposits from/into an account.
• Account
o Keeps track of a list of Transactions for a customer.

Solution Description
Classes:

• Transaction
o fields:
- TransactionType type;
- double amount;
- Optional<String> comment; (See link above for Optional documentation)
o methods:
- Getter methods for all fields.
- boolean hasComment() should return true if comment is not empty, false otherwise.
o constructors:
- one that takes in type and amount in that order and assigns them. Sets the comment to Optional.empty().
- one that takes in type and amount in that order and assigns them. Also take in a third parameter that is a String that represents that
• Account
o fields:
value of the comment. Properly initialize the comment field with this String.
- List<Transaction> pastTransactions
o methods:
- Transaction getTransaction(int n): returns the nth transaction from pastTransactions. n will always be valid.
- List<Transaction> findTransactionsByPredicate(Predicate<Transaction> predicate): Returns a list of Transactions
from pastTransactions filtered by the predicate. If the predicate
returns true when a Transaction is passed in, keep it. Otherwise filter it out of the returned list. Must not
modify pastTransactions field. (See link above for documentation on Predicate)
- List<Transaction> getTransactionsByAmount(double amount): returns a list of Transactions with an amount field that equals the parameter amount. Must not modify pastTransactions field. Must call findTransactionsByPredicate with an instance of an inner class.
- List<Transaction> getWithdrawals(): returns a list of Transactions that are withdrawals. Must not modify pastTransactions field. Must
call findTransactionsByPredicate with an instance created with an anonymous inner class.
- List<Transaction> getDeposits(): returns a list of Transactions that are deposits. Must not modify pastTransactions field. Must
call findTransactionsByPredicate with an instance created with a lambda expression.
- List<Transaction> getTransactionsWithCommentLongerThan(int length): returns a list of Transactions with comments that are longer than length.
Must not modify pastTransactions field. Must
call findTransactionsByPredicate but you can use whatever technique to create the Predicate that you like.
- List<Transaction> getTransactionsWithComment(): returns a list of Transactions with a comment that is not empty. Must not modify pastTransactions field. Must
call findTransactionsByPredicate with a lambda expression or method reference. Method references aren’t taught but they are very useful so feel free to look up how to use them!
- Getter for pastTransactions.
o constructors

- Make a constructor that takes in a List of Transactions assign that list to pastTransactions.
If there are any classes that you are unfamiliar with (e.g. Predicate or Optional), look them up in Javadocs. Make the visibility of all the methods and fields as you see best fits good programming style.

Allowed imports
• Optional
• Predicate
• List
• Any subclass of List

Running and Testing
You should create your own testing class to verify that your code works.   Make sure that all your code can be compiled and ran from the command line.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.util.Optional;

/**
*/
public class Transaction {

    TransactionType type;

    double amount;

    Optional<String> comment;

    public Transaction(TransactionType deposit, double v) {
       this.type = deposit;
       this.amount = v;
       this.comment = Optional.empty();
    }

    public Transaction(TransactionType deposit, double v, String comment) {
       this.type = deposit;
       this.amount = v;
       if (comment != null) {
            this.comment = Optional.of(comment);
       }else {
            this.comment = Optional.empty();
       }
    }

    public TransactionType getType() {
       return type;
    }

    public void setType(TransactionType type) {
       this.type = type;
    }

    public double getAmount() {
       return amount;
    }

    public void setAmount(double amount) {
       this.amount = amount;
    }

    public Optional<String> getComment() {
       return comment;
    }

    public void setComment(Optional<String> comment) {
       this.comment = comment;
    }

    boolean hasComment() {
       return comment.isPresent();
    }
}...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

50% discount

Hours
Minutes
Seconds
$25.00 $12.50
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats