Java Reference
In-Depth Information
Programming Assignments
1 Designing a Relational Database Table
Modify the relationship diagram shown in Figure 11-3 on page 697 for the
StockTracker database to include a new table for recording stock trades. The
StockTrades table will capture for all users both buy and sell transactions of
a given stock; the date and time of the transaction; the price per share of the
stock; the number of shares bought or sold; and the total price paid or received,
including any fees paid. Indicate the field(s) used as keys and the relationship(s)
to any other table(s). Identify the cardinality of all relationships. Explain how
your selection and order of keys used would prevent duplication of records and
provide access to all transactions for a) all stocks for a given user, b) a particular
stock for a given user, and c) only buy or sell transactions.
2 Creating a New Table for an Existing Database
Make a copy of the StockTracker database and name it, StockTracker2. Create
an ODBC data source name, also named StockTracker2, that references this
database. Write a Java utility program that will create the new table designed in
Assignment 1, adding it to the StockTracker2 database. The program can be a
console program and does not need a GUI interface. The new table should
include all of the fields listed in assignment 1. Additionally, it should create the
key(s) and relationship(s) indicated in your design. In the program, create some
test data and add to the database, remembering to keep data in the tables syn-
chronized (i.e., do not add a transaction for a nonexistent user or stock), which
may require writing data to other tables in the database as well. Finally, using
Access, open the database, click Tools on the menu bar and then click
Relationships. Verify that the relationship diagram looks like your original
design. Hint: Use the data type INT to create an SQL numeric field.
3 Implementing a Serialization Utility Class
Create a Java class, ObjUtil, that will provide object serialization and
deserialization methods for use by any other class. This class has no constructor,
as no object of the class will be created. Rather, the two methods, much like
methods in the Math class, are called without an object. After creating and com-
piling the new class, test it by using its methods in place of the corresponding
methods in the MakeDB and StockTrackerDB classes. Hint: Review static
methods.
4 Using a Database Query Result
Write a Java program to query the StockTracker database for all users and all
stocks held by each user. List the user's ID, first name, and last name followed by
their stocks, including both the stock symbol and stock description (name).
This can be a console application that produces output to the screen, as shown
Search WWH ::




Custom Search