Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This project will involve improving the structure of this basic database program: testDB.zip and automating the creation of a database table by extracting the table

This project will involve improving the structure of this basic database program: testDB.zip and automating the creation of a database table by extracting the table layout from attributes of a class. To do this, we will utilize the Java reflection API. The example program is poorly structured since all functionality is in main(). Also, the program must be run from a command prompt, which is inconvenient.Your first task will be to refactor this example into a more modularized program with reusable methods to create a table in the database, to add records to the table, to issue basic queries on the database and to set up the program so that it does not have to run from the command line. You may use the derby.jar file provided. Your user's manual must be very clear on how to set up and run your program so that it will work.

You will create a class Vehicle. The class should have five instance fields: make (values: Chevy, Ford, Toyota, Nissan, Hyundai) model (values: compact, intermediate, fullSized, van, suv, pickup) weight (double), engineSize (double) and import (boolean). You should implement this class utilizing the knowledge you gained in Intermediate Programming, such as setting instance fields with mutators (which, for example will ensure that the numeric values are not negative numbers).

You will use the Reflection API to analyze all the instance fields in class Vehicle and to issue a command to create a table with the proper fields and proper data types for all fields. Your program will create a log file named "dbOperations.log" that notes all major database events in this process (all table creation, addition of values, queries, table deletions, etc).

Note that the object oriented concept of composition, in which one class is composed of instances of another class, and classes that have containers quickly complicate the process of performing this type of task. Furthermore, the larger the set of data types we employ, the larger the overall problem we are addressing becomes. Consequently, we will limit data types our program must manage to use of ints, booleans, doubles and Strings. However, if your program encounters a field type that is none of the ones your program must handle, it must generate a log entry providing details of the field in the class that was not created in the database. Presumably, in a deployed system, a human could make decisions regarding how to handle these situations.

Your program will also automate creation of a number of instances of vehicles. Your program should create ten vehicles by randomly selecting makes and models from the above enumerations, and randomly select weights between 1500 and 4000 pounds. Weights must be such that compact cars (1500-2000) weigh less than intermediate cars (2000-2500) and intermediate cars weigh less than he rest. SUVs, full-sized cars, pickups and vans are all in the same weight range (2500-4000).

When the project runs:

When your program runs, it will analyze class Vehicle using the reflection interface to extract the instance fields and it will create a SQL command to create the database table. It will issue that command. After doing that, it will create the 10 vehicle instances. It will then go through the vehicle instances, extracting the values of the fields (again using reflection), create SQL commands to add values to the table, and issue the commands. Finally, the program will issue a SQL query to display all the vehicles that have been stored in the database. Your program will create a log entry for each SQL operation performed. At the end, your program will read and display the log file. All SQl commands should be issued as prepared statements. No interaction with the user should take place. When the program runs, it should do its work and diisplay the output to the console. Please do not have any file output.

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

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions