Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java please: Write a Java program that does the following jobs. Step1. Creates a Car table with car manufacturers, models, model years, and fuel efficiency

Java please:

Write a Java program that does the following jobs.

Step1. Creates a Car table with car manufacturers, models, model years, and fuel efficiency ratings.

Step2. Reads data from a text file and insert the cars to the table created in Step 1.

Step3. Interact with the user, where the user can select one of the following actions.

- (Q) Quit: quit the program

- (A) Add a car: insert a car to the table

- (C) Calculate avg: calculate the average

- (W) Write the entire table to a text file

- (P) Print the entire table

- (M) Print a subset of the rows based on efficiency

The user can choose one of these actions with typing Q,A,C, W, P, or M in the console. When adding a car, the user must provide manufacturer, model, year, and mpg through the console.

When writing the table to a text file, the user must provide output text file name. When selecting a subset of the rows based on efficiency an upper bound value must be provided.

Four files are provided with the assignment. **THESE ARE POSTED BELOW**

1. CarDB.java: the main class of this assignment.

2. Database.properties: file for Apache Derby

3. SimpleDataSource.java: file for Apache Derby

4. Carmpg.txt: sample text file for Step 2.

Provide one source file (CarDB.java). In other words, Database.properties, SimpleDataSource.java, or Carmpg.txt are not submitted. In modifying the source file,

1. Do not change the file (class) names. Points will be deducted if you have different names.

2. Fill in your name in the @author section of the comment in each of the files. If you do not, points will be deducted.

Make sure to submit source file (*.java). Class file (*.class) will not be graded and receive zero credit.

**(CarDB)

import java.sql.Connection;

import java.sql.Statement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.io.IOException;

/**

* Code for HW5

* @author

*/

/**

Creates the Car table, insert some data into the table,

and drop the table from a database.

*/

//ARGS database.properties

public class CarDB

{

public static void main(String[] args) throws IOException, SQLException,

ClassNotFoundException

{

if (args.length == 0)

{

System.out.println("Usage: java CarDB propertiesFile");

System.exit(0);

}

SimpleDataSource.init(args[0]);

...

}

}

**SimpleDataSource.java

import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.io.FileInputStream; import java.io.IOException; import java.util.Properties;

/** A simple data source for getting database connections. */ public class SimpleDataSource { private static String url; private static String username; private static String password;

/** Initializes the data source. @param fileName the name of the property file that contains the database driver, URL, username, and password */ public static void init(String fileName) throws IOException, ClassNotFoundException { //complete this method }

/** Gets a connection to the database. @return the database connection */ public static Connection getConnection() throws SQLException { //complete this method } }

**database.properties

jdbc.url=jdbc:derby:BigJavaDB;create=true # With other databases, you may need to add entries such as these # jdbc.username=admin # jdbc.password=secret # jdbc.driver=org.apache.derby.jdbc.EmbeddedDriver

**carmpg.txt

2017 Toyota Prius 52

2017 Kia Optima 31

2017 Hyundai Sonata 31

2017 Nissan Altima 31

2017 Chevrolet Malibu 30

2017 Honda Accord 30

2017 Mazda 6 29

2017 Subaru Legacy 29

2017 Toyota Camry 27

2017 Chrysler 200 27

2017 Ford Fusion 27

2017 Volkswagen Passat 27

2017 Volkswagen CC 25

2017 Chevrolet Impala 25

2017 Buick LaCrosse 25

2017 Nissan Maxima 25

2017 Buick Regal 24

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

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago