Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Add the code that works with the array of product data- In Java NetBeans In the ProductDB class, add code that implements the getProductByIndex method.

Add the code that works with the array of product data- In Java NetBeans

  1. In the ProductDB class, add code that implements the getProductByIndex method. Use the Product class constructor to create an object for the row with index i. Return the Product object for the product data at the specified index.
  2. In the Main class, add code that uses the getProductByIndex method and displays the data thats returned by it.
  3. Run the application and make sure it works correctly. At this point, it should print data for the PRODUCT BY INDEX heading.
  4. In the ProductDB class, add code that implements the getProductByCode method. Use the Product class constructor to create an object for the row that has a code matching the input parameter. Return the Product object for the product data with the specified code.
  5. In the Main class, add code that uses the getProductByCode method and displays the data thats returned by it.
  6. Run the application and make sure it works correctly. At this point, it should print data for the PRODUCT BY CODE heading.
  7. In the ProductDB class, add code that implements the getAllProducts method. Use the Product class constructor to create the objects. This should return an array of Product objects for all of the product data.
  8. In the Main class, add code that uses the getAllProducts method and displays the data thats returned by it. To do that, youll need to loop through the array of Product objects thats returned.
  9. Run the application and make sure it works correctly. At this point, it should print data for the LIST OF ALL PRODUCTS heading.

Column Index

Row Index

0

1

2

0

"java"

"Murach's Java Programming"

"57.50"

1

"jsp"

"Murach's Java Servlets and JSP"

"57.50"

2

"mysql"

"Murach's MySQL"

"54.50"

import murach.business.Product; import murach.db.ProductDB;

public class Main {

public static void main(String[] args) { Product product = ProductDB.getProductByCode("jsp"); System.out.println("PRODUCT BY CODE"); System.out.println("Code: "); System.out.println("Description: "); System.out.println("Price: "); System.out.println("----------------------------------------------"); product = ProductDB.getProductByIndex(0); System.out.println("PRODUCT BY INDEX"); System.out.println("Code: "); System.out.println("Description: "); System.out.println("Price: "); System.out.println("----------------------------------------------"); Product[] products = ProductDB.getAllProducts(); System.out.println("LIST OF ALL PRODUCTS"); for (int i = 0; i < 3; i++) { System.out.println("Code: "); System.out.println("Description: "); System.out.println("Price: "); System.out.println(); } System.out.println("----------------------------------------------"); } }

*********

import murach.business.Product;

public class ProductDB { private static String[][] productsArray = { {"java", "Murach's Java Programming", "57.50"}, {"jsp", "Murach's Java Servlets and JSP", "57.50"}, {"mysql", "Murach's MySQL", "54.50"} }; public static Product getProductByIndex(int i) { // TODO: Add code here to return Product object return null; } public static Product getProductByCode(String code) { // TODO: Add code here to return Product object return null; } public static Product[] getAllProducts() { // TODO: Add code here to return array of Product objects return null; } }

*********

import java.text.NumberFormat;

public class Product {

private String code; private String description; private double price;

public Product() { code = ""; description = ""; price = 0; }

public Product(String code, String description, double price) { this.code = code; this.description = description; this.price = price; }

public void setCode(String code) { this.code = code; }

public String getCode() { return code; }

public void setDescription(String description) { this.description = description; }

public String getDescription() { return description; }

public void setPrice(double price) { this.price = price; }

public double getPrice() { return price; }

public String getPriceFormatted() { NumberFormat currency = NumberFormat.getCurrencyInstance(); return currency.format(price); } }

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

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions