package week_9; import java.util.ArrayList; import static…
Question package week_9; import java.util.ArrayList; import static… package week_9; import java.util.ArrayList;import static input.InputUtils.*;public class DBConfig { /* * Don’t modify this class. * * Your code will use the db_url variable to create a connection to the database. * You can access this variable from elsewhere in the project with, * * DBConfig.db_url * * When the tests run, they’ll find this variable and change it to the * location of the test database. When the tests end, they’ll change it back * to the original value. * * You don’t need to do anything in your code to make this happen, * except making sure that the products.db and the products_test.db * databases exist before the code, or the tests, run. * * See instructions in the Lab 9 Questions.md file for creating the databases. * * */ static String db_url = “jdbc:sqlite:products.db”; }package week_9;public class Product { private String name; private int quantity; Product(String name, int quantity){ this.name = name; this.quantity = quantity; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getQuantity() { return quantity; } public void setQuantity(int quantity) { this.quantity = quantity; }} package week_9;/** Talk to your database from here. Use the db_url variable in DBConfig to create your database connection This is necessary so the tests can replace your database with a test database. You can access this variable with DBConfig.db_url*/public class ProductDB { // TODO add methods here to work with the database. private String name; private String description; private double price; private int quantity; private String type; public ProductDB() { name = “no name yet”; description = “nothing yet”; price = 0; quantity = 0; type = “no type yet”; } public ProductDB(String aName, String descrip, double aPrice, int aQuantity, String aType) { name = aName; description = descrip; price = aPrice; quantity = aQuantity; type = aType; } public String getName() { return name; } public void setName(String aName) { name = aName; } public String getDescription() { return description; } public void setDescription(String aDescription) { description = aDescription; } public double getPrice() { return price; } public void setPrice(double aPrice) { price = aPrice; } public void incrementQuantity(int increment) { quantity += increment; } public void decrementQuantity(int decrement) { quantity -= decrement; } public String getType() { return type; } public void setType(String aType) { if (aType == “Pet” || aType == “Supply”) { type = aType; } else { System.out.println(“Error”); } } public String toString() { String result = “”; result = “Product’s name: ” + name + “nDescription: ” + description + “nPrice: ” + price + “nQuantity: ” + quantity + “nType: “+ type; return result; }} package week_9;import java.util.ArrayList;import static input.InputUtils.*;class ProductManager { ProductDB database; // TODO use this object to access instance methods in the ProductDB class private final String menu = “” + “1. Show all productsn” + “2. Add a productn” + “3. Edit a product’s quantityn” + “4. Delete a productn” + “9. Quit”; public static void main(String[] args) { // You do not need to modify this method. ProductManager productManager = new ProductManager(); productManager.start(); } public void start() { // You do not need to modify this method. database = new ProductDB(); showMenuDoAction(); } private void showMenuDoAction() { // You do not need to modify this method. int choice; while (true) { System.out.println(menu); choice = intInput(“Enter choice”); if (choice == 1) { showAll(); } else if (choice == 2) { addProduct(); } else if (choice == 3) { editProductQuantity(); } else if (choice == 4) { deleteProduct(); } else if (choice == 9) { break; // end the loop } else { System.out.println(“Invalid choice, please try again”); } } } protected void showAll() { // TODO write and call method in ProductDB to fetch all products, sorted by product name. // TODO display all product names and quantities neatly, // for example, display the name and quantity of one product per row. // Call method in ProductDB to fetch all products, sorted by product name. ArrayList


