Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the printItem() method for the base class. Sample output for below program: Last name: Smith First and last name: Bill Jones // ===== Code

Write the printItem() method for the base class. Sample output for below program:

Last name: Smith First and last name: Bill Jones 

// ===== Code from file BaseItem.java ===== public class BaseItem { protected String lastName;

public void setLastName(String providedName) { lastName = providedName; return; }

// FIXME: Define printItem() method

/* Your solution goes here */

} // ===== end =====

// ===== Code from file DerivedItem.java ===== public class DerivedItem extends BaseItem { private String firstName;

public void setFirstName(String providedName) { firstName = providedName; return; }

@Override public void printItem() { System.out.print("First and last name: "); System.out.println(firstName + " " + lastName); return; } } // ===== end =====

// ===== Code from file ItemInventory.java ===== import java.util.ArrayList;

public class ItemInventory { public static void main (String [] args) { BaseItem baseItemPtr; DerivedItem derivedItemPtr; ArrayList itemList = new ArrayList(); int i = 0;

baseItemPtr = new BaseItem(); baseItemPtr.setLastName("Smith");

derivedItemPtr = new DerivedItem(); derivedItemPtr.setLastName("Jones"); derivedItemPtr.setFirstName("Bill");

itemList.add(baseItemPtr); itemList.add(derivedItemPtr);

for (i = 0; i < itemList.size(); ++i) { itemList.get(i).printItem(); }

return; } } // ===== end =====

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions

Question

Analyse the process of new product of development.

Answered: 1 week ago

Question

Define Trade Mark.

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago