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

This project will involve improving the structure of this basic database: 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, and 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 provided. Your user's manual must be very clear on how to set up your program so that it will work. You will create a class Vehicle. The class should have five instance fields: make (Chevy, Ford, Toyota, Nissan, Hyundai) model (compact, intermediate, fullSized, SUV) 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 interface 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 can 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. 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 the rest. SUVs, full-sized cars, pickups and vans are all in the same weight range (2500-4000). Toyota, Nissan, and Hyundai are imports. 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 use this information to create a SQL command to create the database table. It will issue that command. After creating the table, 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 SQL commands to insert the data. Finally, the program will issue three SQL queries to display: all information about all the vehicles that have been stored in the database. all vehicles that weigh more than 2500 pounds all imported SUVs Your program will create a log entry for each SQL operation performed. At the end, your program will read and display the log file. Your program should run by executing a batch file. You may have to "unpackage" your source files for everything to work. Be sure you properly locate any input files.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!