SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 313 Weeks Ago, 5 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 09 Nov 2017 My Price 10.00

even getting started on this one. Its for Netbeans.

I am having trouble even getting started on this one. Its for Netbeans. Attached are the instructions and the code for the separate files and also a screen cap of what it looks like in netbeans. Examples of w

 

In this exercise, you’ll create a Product application like the one presented in this chapter that uses inheritance. However, you will add an additional kind of product: compact discs.

Create a new subclass named CompactDisc

1. Open the project named ch08_ex2_Product that’s in the ex_starts directory. Then, review the code.

2. Add a class named CompactDisc that inherits the Product class. This new class should work like the Book and Software classes, but it should include public get and set methods for a private instance variable named artist. In addition, its toString method should append the artist name to the end of the string.

Modify the ProductDB class so it returns a CompactDisc object

3. Modify the ProductDB class so it creates at least one CompactDisc object. For example, this object might contain the following information:

Code: sgtp

Description: Sgt. Pepper's Lonely Hearts Club Band Price: $15.00

Artist: The Beatles

Add a protected variable

4. Open the Product class and change the access modifier for the count variable from public to protected.

5. Run the application to make sure that it works correctly and that the count is maintained properly

 

-------------------------------------------------------------------------------------------------------------------

book:

public class Book extends Product

{

                private String author;

 

                public Book()

                {

                                super();

                                author = "";

                                count++;

                }

 

                public void setAuthor(String author)

                {

                                this.author = author;

                }

 

                public String getAuthor(){

                                return author;

                }

 

        @Override

                public String toString()

                {

                                return super.toString() +

                                                "Author:      " + author + "\n";

                }

}

-------------------------------------------------------------------------------------------------------------------

 

Product:

 

import java.text.NumberFormat;

 

public class Product

{

    private String code;

    private String description;

    private double price;

    public static int count = 0;

 

    public Product()

    {

        code = "";

        description = "";

        price = 0;

    }

 

    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 getFormattedPrice()

    {

NumberFormat currency = NumberFormat.getCurrencyInstance();

        return currency.format(price);

    }

 

    @Override

    public String toString()

    {

        return "Code:        " + code + "\n" +

               "Description: " + description + "\n" +

               "Price:       " + this.getFormattedPrice() + "\n";

    }

 

    public static intgetCount()

    {

        return count;

    }

}

 

-------------------------------------------------------------------------------------------------------------------

 

product app: 

 

import java.util.Scanner;

 

public class ProductApp

{

    public static void main(String args[])

    {

        // display a weclome message

System.out.println("Welcome to the Product Selector\n");

 

        // perform 1 or more selections

        Scanner sc = new Scanner(System.in);

        String choice = "y";

        while (choice.equalsIgnoreCase("y"))

        {

System.out.print("Enter product code: ");

            String productCode = sc.next();  // read the product code

sc.nextLine();  // discard any other data entered on the line

 

            // get the Product object

            Product p = ProductDB.getProduct(productCode);

 

            // display the output

System.out.println();

            if (p != null)

System.out.println(p.toString());

            else

System.out.println("No product matches this product code.\n");

 

System.out.println("Product count: " + Product.getCount() + "\n");

 

            // see if the user wants to continue

System.out.print("Continue? (y/n): ");

            choice = sc.nextLine();

System.out.println();

        }

    }

}

-------------------------------------------------------------------------------------------------------------------

 

ProductDB:

 

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("jsps") ||

productCode.equalsIgnoreCase("mcb2"))

        {

            Book b = new Book();

            if (productCode.equalsIgnoreCase("java"))

            {

b.setCode(productCode);

b.setDescription("Murach's Beginning Java");

b.setPrice(49.50);

b.setAuthor("Andrea Steelman");

            }

            else if (productCode.equalsIgnoreCase("jsps"))

            {

b.setCode(productCode);

b.setDescription("Murach's Java Servlets and JSP");

b.setPrice(49.50);

b.setAuthor("Andrea Steelman");

            }

            else if (productCode.equalsIgnoreCase("mcb2"))

            {

b.setCode(productCode);

b.setDescription("Murach's Mainframe COBOL");

b.setPrice(59.50);

b.setAuthor("Mike Murach");

            }

            p = b; // set Product object equal to the Book object

        }

        else if (productCode.equalsIgnoreCase("txtp"))

        {

            Software s = new Software();

s.setCode("txtp");

s.setDescription("TextPad");

s.setPrice(27.00);

s.setVersion("4.7.3");

            p = s; // set Product object equal to the Software object

        }

        return p;

    }

}

-------------------------------------------------------------------------------------------------------------------

 

software.java

 

public class Software extends Product

{

                private String version;

 

                public Software()

                {

                                super();

                                version = "";

                                count++;

                }

 

                public void setVersion(String version)

                {

                                this.version = version;

                }

 

                public String getVersion(){

                                return version;

                }

 

        @Override

                public String toString()

                {

                                return super.toString() +

                                                "Version:     " + version + "\n";

                }

}

 

 

hat the code for each file is like would be nice if possible, thanks.

Attachments:

Answers

(5)
Status NEW Posted 09 Nov 2017 01:11 PM My Price 10.00

----------- He-----------llo----------- Si-----------r/M-----------ada-----------m -----------Tha-----------nk -----------you----------- fo-----------r y-----------our----------- in-----------ter-----------est----------- an-----------d b-----------uyi-----------ng -----------my -----------pos-----------ted----------- so-----------lut-----------ion-----------. P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll -----------be -----------qui-----------ckl-----------y

Not Rated(0)