Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How would I store data about the artist to the album, and how do I modify the productDB? Beggning of java Use inheritance with the

How would I store data about the artist to the album, and how do I modify the productDB?

Beggning of java

Use inheritance with the Product application

modify the Product application so it provides for an additional kind of product: a music album. When you enter the code for a music album, it should look like this:

Enter product code sgtp Description Sgt. Peppers(The Beatles) Price $14.99 Product count 1

Create a new subclass named Album

I. Import the project named ch 11-ex l-Product that's in the ex-starts folder. Then, review the code. 2. In the murach business package, create a new class named Album that inherits the Product class. This new class should store data about the artist of the album. In addition, its toString method should append the name of the artist to the end of the string Modify the ProductDB class so it returns an Album object 3. Modify the ProductDB class so it creates at least one Album object. 4. Run the application to make sure that it works correctly.

Modify the protected variable 5, open the Product class and delete the protected access modifier for the count variable. This restricts the availability of this variable even further, making it only available to the other classes in the current package. 6 Run the application to make sure that the count is maintained properly.

PRODUCT CODE:

package murach.business;

import java.text.NumberFormat;

public class Product {

private String code; private String description; private double price; protected static int count = 0;

public Product() { }

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); }

@Override public String toString() { return description; }

public static int getCount() { return count; } }

PRODUCTDB CODE:

package murach.db;

import murach.business.Book; import murach.business.Product; import murach.business.Software;

public class ProductDB {

public static Product getProduct(String productCode) { // In a more realistic application, this code would // get the data for the product from a file or database // For now, this code just uses if/else statements // to return the correct product data

Product p = null;

if (productCode.equalsIgnoreCase("java") || productCode.equalsIgnoreCase("jsp") || productCode.equalsIgnoreCase("mysql")) { Book b = new Book(); if (productCode.equalsIgnoreCase("java")) { b.setCode(productCode); b.setDescription("Murach's Java Programming"); b.setPrice(57.50); b.setAuthor("Joel Murach"); } else if (productCode.equalsIgnoreCase("jsp")) { b.setCode(productCode); b.setDescription("Murach's Java Servlets and JSP"); b.setPrice(57.50); b.setAuthor("Mike Urban"); } else if (productCode.equalsIgnoreCase("mysql")) { b.setCode(productCode); b.setDescription("Murach's MySQL"); b.setPrice(54.50); b.setAuthor("Joel Murach"); } p = b; // set Product object equal to the Book object } else if (productCode.equalsIgnoreCase("eclipse")) { Software s = new Software(); s.setCode("eclipse"); s.setDescription("Eclipse"); s.setPrice(0.00); s.setVersion("4.4.2"); p = s; // set Product object equal to the Software object } return p; } }

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

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions