Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7910623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:56:01+00:00 2026-06-03T12:56:01+00:00

To make the explanation easier I’ll give a quick overview of the program. I’m

  • 0

To make the explanation easier I’ll give a quick overview of the program. I’m supposed to create an “online book store.” I have abstract class Item and 2 subclasses, Apparel and Textbooks. In the main the user will first “fill” the store with either textbooks or apparel and then “sell” items, given they’re in stock.

In the main I created an array of Item (abstract) that will hold objects of both Textbook and Apparel types, acting like the “store”. My problem comes in when trying to access the array.

When “selling” an item, the user, for example, inputs the title of the book they want to purchase. I have to validate that this title is “in stock” (i.e. in the Item array)

This is my method for buying the book (i is the # of items in the store, store is the abstract array, and its not complete as you can see. I’m stuck on the if statement)

public static void buyBook(Item[] store, int i)
{
    TextBook book = new TextBook();

    String title;
    title = JOptionPane.showInputDialog("Book title: ");

    for(int j = 0; j < i; j++)
    {
        if(store[j] instanceof TextBook)
        {
            if()
        }
}

My idea is to compare title (the user’s input) to those of Textbook type in store (abstract array)
I know its wrong but something like:

store[j].getTitle().compareTo(title)

BUT of course store[j] can’t access getTitle (because its in TextBook, the subclass)

And now I’m completely stuck. Some guidance would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T12:56:04+00:00Added an answer on June 3, 2026 at 12:56 pm

    Downcast is your friend. ((TextBook)store[j]).getTitle().compareTo(title) Also, why not use for-each? for (Item item : store) if (item instanceof TextBook) ...

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working in python 2.7. I have two lists (simplified to make explanation more clear):
Here is more specific explanation of what I want to make clear: I have
Some explanation: for a project I'm working on I have to write a program
EDIT To make it easier to read I've rewritten my explanation here. In short,
Hopefully this explanation will make sense, but what is the best way (if it
I want to add explanation between cells. I'm experimenting with sections, trying to make
Can anybody, given example below, make to me an explanation how FLOAT works in
I am working on a game with some friends, and to make life easier
I am going to develop on iPhone platform. Can some one make an explanation
To make a long explanation short, suffice it to say that my Rails app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.