I ask for help about self-help, which is a type of oxymoron. How can I rid you of good people by solving more of my own problems?
I am in the last week of Java programming, and I have a huge obstacle in learning Java. I have read all the books, but I keep focusing on small issues all the time. It is like trying to build a house of cards. I only know about those parts of the syntax and uses that the book shows. When I combine things, I face terrible obstacles. I have been trying to understand them for many hours. Only basic uses are displayed in the sun, which do not seem to help.
Here is what I would like:
When I tried something and it doesnโt work, like the following manipulations with the list of arrays, I want to find a place or program that can show an example of code for such things as adding an additional instance of the class to arrayList. Where can I briefly find out about this without asking a question or 2 for each syntax error? Where is Google for Java? Is there a program that will take your mistakes 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:
import java.util.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
public class Inventory
{
private ArrayList<RatedDVD> dvdlist;
private int numDVDs;
public Inventory()
{
dvdlist = new ArrayList<RatedDVD>();
}
public RatedDVD get(int i){return dvdlist.get(i);}
public void add(DVD d){
dvdlist = dvdlist d;
sort();
}
public double value()
{
double total = 0.0;
for (int i = 0; i < dvdlist.size(); i++)
{
total += get(i).feeValue();
}
return total;
}
public void sort()
{
int n = dvdlist.size();
for (int search = 1; search < n; search++)
{
for (int i = 0; i < n-search; i++)
{
if (dvdlist.get(i).getName().compareToIgnoreCase(dvdlist.get(i+1).getName()) > 0)
{
RatedDVD temp = dvdlist.get(i);
dvdlist.set(i,dvdlist.get(i+1));
dvdlist.set(i+1,temp);
}
}
}
}
public int size(){return dvdlist.size();}
public void save() {
save(true);
}
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();
}
w.close();
} catch (Exception ex) {
if (saveagain) {
new File("c:\\data\\").mkdir();
save(false);
}
}
}
public int search(String name) {
for (int i = 0; i < size(); i++) {
if (get(i).getName().equalsIgnoreCase(name)) return i;
}
return -1;
}
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;
dvdlist = temp;
}
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;
}
}
source
share