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

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

Expert Answer

 

//Product.java starts here
package murach.business;
import java.text.NumberFormat;
public class Product {
    private String code;
    private String description;
    private double price;
    static int count = 0;
    public Product() {
        //Incrementing count each time a Product is created
        count++;
    }
    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.java starts here

package murach.db;
//import murach.business.Book;
import murach.business.Product;
//import murach.business.Software;
import murach.business.Album;

public class ProductDB {

    public static Album 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;
        Album a = new Album();
        if(productCode.equalsIgnoreCase("sgtp")){
            a.setArtist("The Beatles");
            a.setCode(productCode);
            a.setDescription("Sgt. Peppers");
            a.setPrice(14.99);
            p=a;
        }

        //Because we are returning an Album object, we can not use this function for Book or Software objects

        //If you need to use this for Book and Software as well,
        // just change the return type of getProduct(String productCode) to Product and return p.
        // And then uncomment the below block

        /*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 a;
    }
    public static void main(String[] args) {

        //Create an Album object
        Album A = getProduct("sgtp");

        //Display the details of this product
        System.out.println("Code: " + A.getCode());
        System.out.println("Description: " + A.toString());
        System.out.println("Price: " + A.getPriceFormatted());
        System.out.println("Product Count: " + Product.getCount());
    }
}

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.