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

  • SEARCH
  • Home
  • 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 8210615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:07:56+00:00 2026-06-07T10:07:56+00:00

Below is my learning objective. I got it started, but I don’t really know

  • 0

Below is my learning objective. I got it started, but I don’t really know where to go from here to implement the program in main. I would appreciate any help!

Objective:

  • Add an Iterator object to the card collection
  • Iterators are added to collections by creating a private inner class.
  • You may use any of the inner class types that are appropriate
  • Enumerators and Iterators use a large number to determine when the collection changes.
  • Implement the correct methods, interfaces, and extend the appropriate classes for a class consistent with the Java API.

    public class CardCollection {
    
    private ArrayList<Card> cards;
    private ArrayList<Note> notes;
    
    public CardCollection() { //constructor initializes the two arraylists
      cards = new ArrayList<Card>();
      notes = new ArrayList<Note>();
     }
    
    private class Card implements Iterable<Card> { //create the inner class
    
        public Iterator<Card> iterator() { //create the Iterator for Card
            return cards.iterator();
        }
    }
    
    private class Note implements Iterable<Note> { //create the inner class
    
        public Iterator<Note> iterator() { //create the Iterator for Note
            return notes.iterator();
        }
    
    }
    
    public Card cards() {
        return new Card();
     }
    
     public Note notes() {
         return new Note();
     }
    
     public void add(Card card) {
         cards.add(card);
     }
    
     public void add(Note note) {
         notes.add(note);
     }
    
    }
    
  • 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-07T10:08:00+00:00Added an answer on June 7, 2026 at 10:08 am

    You have two concepts here that I think you may be mixing up. An object if Iterable if you can iterate over some internal elements.

    So if I have a shopping cart with items in it, I can iterate over my groceries.

    public class ShoppingCart implements Iterable<GroceryItem>
    {
       public Iterator<GroceryItem> iterator()
       {
          // return an iterator
       }
    }
    

    So in order to use this functionality, I need to provide an Iterator. In your code example, you are reusing the iterators from ArrayList. From your exercise description, I believe you need to implement one yourself. For example:

    public class GroceryIterator implements Iterator<GroceryItem>
    {
      private GroceryItem[] items;
      private int currentElement = 0;
    
      public GroceryIterator(GroceryItem[] items)
      {
        this.items = items;
      }
    
      public GroceryItem next() // implement this
      public void remove() // implement this
      public boolean hasNext() // implement this
    }
    

    So I sorta gave you a hint with the constructor/member variables. After you make this class, your Iterable class (my ShoppingCart) will return my new iterator.

    The assignment recommends using a private inner class for your custom Iterator.

    Good luck

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

Sidebar

Related Questions

Below my code for installing vcider. I am learning chef but have not seen
I'm learning decorators and here I'm trying to change the below to decorator pattern.
I'm learning Python and trying to test some rest web_service applications. From the below
I'm learning Ajax at the moment. The code below basically receives the echo from
I am getting the below error for line 8. Learning from ch.11/12 of the
so I have this jQuery script below that works. But since I'm just learning
sorry for the silly question, but I'm still in the process of learning Objective-C
learning about loops (still a beginner) in VB.net. I have got the below code
I am learning how to use pointers, so i wrote the below program to
I am new to AS3. When learning AS3, I get the below code from

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.