Problem

Random transactions. Develop a generator that takes an argument N, generates N random Tran...

Random transactions. Develop a generator that takes an argument N, generates N random Transaction objects (see exercises 2.1.21 and 2.1.22), using assumptions about the transactions that you can defend. Then compare the performance of shellsort, mergesort, quicksort, and heapsort for sorting N transactions, for N=103, 104, 105, and 106

exercises 2.1.21

Comparable transactions. Using our code for Date (page 247) as a model, expand your implementation of Transaction (exercise 1.2.13) so that it implements Comparable, such that transactions are kept in order by amount.

Exercise: 1.2.13

Using our implementation of Date as a model (page 91), develop an implementation of Transaction.

Solution :

public class Transaction implements Comparable{private final double amount;public int compareTo(Transaction that){if (this.amount > that.amount) return +1;if (this.amount

exercises 2.1.22

Transaction sort test client. Write a class SortTransactions that consists of a static method main() that reads a sequence of transactions from standard input, sorts them, and prints the result on standard output (see exercise 1.3.17).

exercise

Do exercise 1.3.16 for Transaction.

This list of exercises is intended to give you experience in working with linked lists. Suggestion: make drawings using the visual representation described in the text.

exercise 1.3.16

Using readA11Ints() on page 126 as a model, write a static method readA11Dates() for Date that reads dates from standard input in the format specified in the table on page 119 and returns an array containing them.

Solution :

public class SortTransactions{public static Transaction[] readTransactions(){ /* See Exercise 1.3.17 */ }public static void main(String[] args){Transaction[] transactions = readTransactions();Shell.sort(transactions);for (Transaction t : transactions)StdOut.println(t);}}

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 2.5