Question: Need some help with this. Please as soon as possible, thanks so much people of Chegg. In this exercise, youll modify a version of the

Need some help with this. Please as soon as possible, thanks so much people of Chegg.

In this exercise, youll modify a version of the Product application so it adds a class named MyProduct that extends the Product class and enhances its functionality.

Review the application

1. Open the project named ch11_ex4_Product in the extra_ex_starts directory.

2. Open the classes and review their code.

3. Run the application to make sure it works correctly.

Create a new subclass and use it

4. In the murach.business package, create a new class named MyProduct that inherits the Product class. This new class should add the following method to the Product class:

public String getPrice(NumberFormat nf)

This method should format the price for the product using the format thats provided by the NumberFormat object thats passed as a parameter.

5. In the ProductDB class, modify the getProduct method so it returns a MyProduct object, not a Product object.

6. In the ProductApp class, modify the code so it uses a MyProduct object, not a Product object. This should include using the getPrice method thats only available from the MyProduct class to apply currency formatting to the price.

7. Run the application to make sure that it still works correctly.

Code:

ProductDB:

package murach.db;

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 double price = Double.parseDouble(productsArray[i][2]); Product p = new Product(productsArray[i][0], productsArray[i][1], price); return p; } public static Product getProductByCode(String code) { // TODO: Add code here to return Product object for(int i=0;i

Need some help with this. Please as soon as possible, thanks so

Main.java:

package murach.ui;

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:"+product.getCode()); System.out.println("Description:"+ product.getCode()); System.out.println("Price:"+product.getPrice()); System.out.println("----------------------------------------------"); product = ProductDB.getProductByIndex(0); System.out.println("PRODUCT BY INDEX"); System.out.println("Code:"+ product.getCode()); System.out.println("Description:"+product.getDescription()); System.out.println("Price:"+product.getPrice()); System.out.println("----------------------------------------------"); Product[] products = ProductDB.getAllProducts(); System.out.println("LIST OF ALL PRODUCTS"); for (int i = 0; i

much people of Chegg. In this exercise, youll modify a version of

Product.java

package murach.business;

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(); String priceFormatted = currency.format(price); return priceFormatted; } }

the Product application so it adds a class named MyProduct that extends

the Product class and enhances its functionality. Review the application 1. Open

package murach.db: import murach . business. Product; public class ProductDB i 3 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" 10 12 13 14 15 16 17 18 19 20 21 public static Product getProductByIndex(int i) i // TODO: Add code here to return Product object double price = Double.parseDouble (productsArray[1] [2]); Product p new Product (productsArray[1] [0], productsArray[1] [1], price); return p: public static Product getProductByCode (String code) i // TOD0: Add code here to return Product object for (int i=0;i

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!