Right now i have an array of objects. Each object contain code, name, price and amount.
1. How am I going to add an object containing all those properties into the array ?
2. How am I going to edit(replace with new properties) the properties of the object inside the array ?
Please help.
Thanks very much.
also, i would recommend you learn about ArrayList and LinkedList, which are much easier to use than regular arrays.
I have a question here:
why am I getting a nullpointerexception in this code ?
The one in red is the one that the compiler complaining about. Can you tell me what is wrong with that ? I really cant figure out what is wrong.Code:public class Showroom{ private Vehicle stocks[]; private double width; private double height; private double length; //-------------------------------- public Showroom(){ stocks[0]=new Vehicle(); stocks[1]=new Vehicle(); stocks[2]=new Vehicle(); stocks[3]=new Vehicle(); stocks[4]=new Vehicle(); width=0.0; height=0.0; length=0.0; } public void setStocks(Vehicle v, int x){ stocks[x]=v; } public Vehicle getStocks(int x){ return stocks[x]; } public double calculateArea(){ return width*height*length; } public void setWidth(double a){ width=a; } public double getWidth(){ return width; } public void setHeight(double b){ height=b; } public double getHeight(){ return height; } public void setLength(double c){ length=c; } public double getLength(){ return length; } public static void main(String args[]){ Showroom s = new Showroom(); Vehicle myVehicle; myVehicle = new Vehicle("abc", "green", 3, 3, 3); s.setStocks(myVehicle, 0); System.out.println(s.getStocks(0)); } }
Thanks.
instead of
try that...Code:private Vehicle stocks[];
Code:private Vehicle stocks[] = new Vehicle[sizeOfArray];
Your stocks and vehicle, are they separate classes or what?
i think "stocks" is just the name of array..
Guess he didn't show us that, it doesn't matter anyway...
i already posted the solution and i'm quite sure, it will fix it.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks