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 6787883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:25:08+00:00 2026-05-26T17:25:08+00:00

A homework assignment requires me to make a bag data structure in Java by

  • 0

A homework assignment requires me to make a bag data structure in Java by implementing java.util.Collections. The bag data must be stored in an array. I cannot seem to be able to get my class methods to access the array I give each object in the class.

Here’s the code giving me the issue:

import java.util.*;
import java.lang.*;

class Bag<T> implements Collection<T> {

//MAIN METHOD///////////////////////////////

public static void main(String[] args) {

Bag<Integer> bravo = new Bag<Integer>();

System.out.println(bravo.size());

}///////////////////////////////////////////


//CONSTUCTOR///////////////////////////
public Bag() {

T[] bagarray = (T[])new Object[10];

}
///////////////////////////////////////


//METHODS/////////////////////////////////////////////////////////////////////////////////

public int size() {

int temp;

temp = bagarray.length;

return temp;

}

During compile I’m given an cannotfindsymbol error for bagarray. Yet, I have written code before performing this exact same maneuver.

It has to be some minute detail, but I’ve been racking my brain for a while on this problem.
Where am I going wrong?

  • 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-05-26T17:25:09+00:00Added an answer on May 26, 2026 at 5:25 pm

    The array should be an instance variable; it is currently a local in the constructor.

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

Sidebar

Related Questions

Some classmates and I are working on a homework assignment for Java that requires
My kiddo had a homework assignment to write Blackjack in Java. I helped him
Our homework assignment asks us to prove that the Java LinkedList implementation is doubly-linked
I just had a homework assignment that wanted me to add all the Java
We've gotten a homework assignment in Java, which relates to inheritance. I don't have
I'm working on a homework assignment that requires me to write a program that
I'm working on a homework assignment in which I'm required to use char arrays
For a homework assignment I was given a Card class that has enumerated types
I got a homework assignment asking me to invoke a function without explicitly calling
I have a homework assignment where I need to take input from a file

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.