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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:22:37+00:00 2026-05-12T13:22:37+00:00

I am asking for help on self-help, which is kind of an oxymoron. How

  • 0

I am asking for help on self-help, which is kind of an oxymoron. How do I bug you nice folks less by solving more of my own problems?

I am in my last week of Java programming and I am having a huge hurdle with learning Java. I have read all the books but I keep getting hung up on tiny little issues. It is like trying to build a house of cards. I only know about the parts of the syntax and the uses that the book shows. When I am combining things, I run into horrible hurdles. I try for hours of tinkering to figure them out. The sun docs only show basic uses that don’t seem to help

Here is what I would like:

When I am trying something and it doesn’t work like the following manipulations of an array list, I want to find a place or program that can show examples code of things like adding an additional class instance to an arrayList. Where can I learn concisely about this without having to ask a question or 2 for every syntax error? Where is the Google for Java? Is there a program that will take your errors and show you how to fix them (or offer suggestions)?

/tmp/jc_4083/Inventory.java:101: incompatible types
found   : RatedDVD[]
required: java.util.ArrayList
        dvdlist = temp;
                  ^
/tmp/jc_4083/Inventory.java:110: array required, but java.util.ArrayList found
            if (p != dvdlist[i]) {
                            ^
/tmp/jc_4083/Inventory.java:111: array required, but java.util.ArrayList found
                temp[i-adj] = dvdlist[i];
                                     ^
/tmp/jc_4083/Inventory.java:115: incompatible types
found   : RatedDVD[]
required: java.util.ArrayList
        dvdlist = temp;

Here is my code for this class if anyone is interested in looking at it for me:

//Contruct inv and allow for methods add, get, size, sort, and value
import java.util.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

public class Inventory
{// class Inventory
    private ArrayList<RatedDVD> dvdlist;// declare dvdlist as ArrayList of RatedDVD
    private int numDVDs;

    public Inventory()
    {// method Inventory
        dvdlist = new ArrayList<RatedDVD>();

    }// end method

    // add & get
    public RatedDVD get(int i){return dvdlist.get(i);}// method get

    public void add(DVD d){
    dvdlist = dvdlist d;
    sort();
    }// method add

    public double value()
    {// method value
        double total = 0.0;
        for (int i = 0; i < dvdlist.size(); i++) 
        {// for every pass thru dvdlist add total
        // [DEBUG] consider enhanced for
            total += get(i).feeValue();
        }
        return total;
    }// end method value

    public void sort()
    {// method sort
    // [DEBUG] consider optimization
    int n = dvdlist.size();
        for (int search = 1; search < n; search++) 
        {// for do the following and increment till dvdlist has been searched
            for (int i = 0; i < n-search; i++) 
            {// for step through comparison for entire dvdlist
                if (dvdlist.get(i).getName().compareToIgnoreCase(dvdlist.get(i+1).getName()) > 0) 
                {// if swap necessary then swap
                    RatedDVD temp = dvdlist.get(i);
                    dvdlist.set(i,dvdlist.get(i+1));
                    dvdlist.set(i+1,temp);
                }// end if swap
            }// end for compareto
        }// end outer for
    }// end method sort

    public int size(){return dvdlist.size();}// method size

    public void save() {
        save(true);
    }

    // save it to C:\data\inventory.dat
    public void save(boolean saveagain) {
        try {
            BufferedWriter w = new BufferedWriter(new FileWriter("c:\\data\\inventory.dat"));
            for (int i = 0; i < size(); i++) {
                RatedDVD dvd = get(i);
                w.write( dvd.getItem() + "\n");
                w.write( dvd.getName() + "\n");
                w.write( dvd.getRating() + "\n");
                w.write( dvd.getUnits() + "\n");
                w.write( dvd.getPrice() + "\n");
                w.write( dvd.value() + "\n");
                w.write( dvd.fee() + "\n");
                w.write( dvd.feeValue() + "\n");
                w.newLine();
            }
            // total value of it
            //w.write( value() + "\n");
            w.close();
        } catch (Exception ex) {
            if (saveagain) {
                new File("c:\\data\\").mkdir(); // make file if doesn't exist
                save(false); 
            }
        }
    }

    public int search(String name) {
        for (int i = 0; i < size(); i++) { // check if name string is equal
            if (get(i).getName().equalsIgnoreCase(name)) return i;
        }
        return -1; // we didn't find anything
    }

    // add a new dvd to the end, increasing the array size
    public void add(RatedDVD p) {
        RatedDVD[] temp = new RatedDVD[dvdlist.size()+1];
        for (int i = 0; i < dvdlist.size(); i++) {
            temp[i] = dvdlist[i];
        }
        temp[temp.length-1] = p; // add it at the end
        dvdlist = temp;
    }

    // remove a DVD from the array, and shrink the array size
    public void delete(RatedDVD p) {
        RatedDVD[] temp = new RatedDVD[dvdlist.size()-1];
        int adj = 0;
        for (int i = 0; i < dvdlist.size(); i++) {
            if (p != dvdlist[i]) {
                temp[i-adj] = dvdlist[i];
            }
            else adj = 1;
        }
        dvdlist = temp;
    }
    public int highestNumber() {
        int numb = 0;
        for (int i = 0; i < dvdlist.size(); i++) {
            if (get(i).getItem() > numb) {
                numb = get(i).getItem();
            }
        }
        return numb;
    }   
}// end class inventory
  • 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-12T13:22:37+00:00Added an answer on May 12, 2026 at 1:22 pm

    The dvdlist is an ArrayList, which implements the Collection interface, not an Array (BTW, and this is known as the “program to an interface, not an implementation” principle, you should decalare dvdlist as a java.util.List):

    private ArrayList<RatedDVD> dvdlist;// declare dvdlist as ArrayList of RatedDVD
    

    Have a look at the methods on the Collection interface, you’ll find everything you need for adding and removing elements.

    So, to add a RatedDVD, you don’t need to use a temporary array of RatedDVD that won’t fit anyway into an ArrayList like you’re doing here:

    // add a new dvd to the end, increasing the array size
    public void add(RatedDVD p) {
        RatedDVD[] temp = new RatedDVD[dvdlist.size()+1];
        for (int i = 0; i < dvdlist.size(); i++) {
                temp[i] = dvdlist[i];
        }
        temp[temp.length-1] = p; // add it at the end
        dvdlist = temp;
    }
    

    Instead, just call the add(Object o) method on dvdlist.

    To delete a RatedDVD instance, use the remove(Object o) method on dvdlist.

    For the search() method, consider using contains(Object o) on dvdlist.

    If you need to iterate over a collection, use an Iterator:

    for (Iterator iter = dvdlist.iterator(); iter.hasNext();) {
       RatedDVD ratedDVD = (RatedDVD) iter.next();
       //rest of the code block removed
    }
    

    Or even faster now with Java 5+ and Generics:

    for (RatedDVD ratedDVD : dvdlist) {
       // rest of the code here
    }
    

    Really, you need to dig the the Collection Framework.

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

Sidebar

Related Questions

Im asking to see if anyone could help me with my problem which is
I am asking for help, after hours of trying to figure this out myself.
I have tried refraining from asking for help, but I have had enough! I
I'm new to ADO.NET so asking for help. I have to insert large number
I'm learning Java and find myself sending methods around while asking for help but
Asking for your help on this Oracle query. It's giving me the error 2
After a long time searching and trying I'm asking now for help: My situation:
UPDATE: To help clarify what I'm asking I have posted a little java code
My apologies for asking such a novice question but, I need help building a
I know, I am asking stupid question but your experience will help me to

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.