I understand that this means I'm using more memory than is available to the JVM, but I'm not sure why or what to do about it.
The purpose of the program is to simulate an item in a store that is being tracked with a bar code id number (or value) for identification purposes. Each item in the store is tracked with both an id value and an inventory amount. The program should take in values from a file, sort them, and print them.
import java.util.*;
import java.io.*;
public class Store {
Item o;
ArrayList <Item> myStore = new ArrayList <Item>();
ArrayList <Item> flipper = new ArrayList <Item>();
public void storeStuff(){
Scanner in;
try{
in = new Scanner(new File("/home/chris/Desktop/file50.txt"));
while(in.hasNext()){
o = new Item(in.nextInt(), in.nextInt()); //the item class takes in an Id value and the total inventory for that item
myStore.add(o);
}
}catch(IOException i){
System.out.println("Error: " + i.getMessage());
}
}
public void sort(ArrayList <Item> list){
System.out.println("sorting method accessed");
int pointer = 0;
System.out.println(myStore.size() + " myStore");
System.out.println(flipper.size() + " flipper");
for(int i = 0; i < list.size(); i++){
pointer = 0;
if(flipper.size() < 1){
//if a list is empty, simply add an item
flipper.add(myStore.get(i));
}
else{
//if the item being added to the 2nd arraylist is less than the item currently in that space, insert it, thus pushing back all other values
for(int j = 0; j < flipper.size(); j++){
if(myStore.get(i).getId() < flipper.get(j).getId()){
flipper.add(j, myStore.get(i));
}
}
}
}
}
public void run(){
storeStuff();
sort(myStore);
for(int i = 0; i < flipper.size(); i++){
System.out.println(flipper.get(i).getId() + " " + flipper.get(i).getInv());
}
}
}