•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 391,563 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,738 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 2749 | Replies: 37 | Solved
![]() |
I have just been using a standard String to input and return information. I am trying to impliment an Array in to this inventory program so that I can store and view more than one item at a time.
I think I have done ok until I get to the Return part of the program. I have tried several different things but nothing seems to work.
As it is, I am getting a "cannot find symbol" error message on "cdName" in the return statment. Any help on what I am doing wrong?
I think I have done ok until I get to the Return part of the program. I have tried several different things but nothing seems to work.
As it is, I am getting a "cannot find symbol" error message on "cdName" in the return statment. Any help on what I am doing wrong?
public class Compactdisk
{// begin class
//InventoryCD class has 5 fields
String cdName[]; // cd name array
float price; // price of cd
int itemno; // item number of cd
int nstock; // how many units in stock
//Compact disk class constructor
public Compactdisk()
// 4 fields need to be set up
{
cdName = new String [25];
price = 0;
itemno = 0;
nstock = 0;
}
// set values
public void setCDName(String diskName)
{
cdName = cdName;
}
public void setPrice(float cdPrice)
{
price = cdPrice;
}
public void setItemno(int cdItemno)
{
itemno = cdItemno;
}
public void setNstock(int cdStock)
{
nstock = cdStock;
}
// return values
public String getCDName()
{
return cdName();
}
public float getPrice()
{
return (price);
}
public int getItemno()
{
return (itemno);
}
public int getNstock()
{
return (nstock);
}
// returns inventory value
public float getValue()
{
return(price * nstock);
}
}// end class I never drew first, but I drew first blood.
I'm no ones son, unforgiven.
I'm no ones son, unforgiven.
I did have it all in one line to begin with, (declaring and creating)
String cdName[] = new String [25]
but it is easier for me to read this way, and I get the same error either way.
Those are the only two ways I have learned to do this, unless I am just way off base right now and doing something wrong.
String cdName[] = new String [25]
but it is easier for me to read this way, and I get the same error either way.
Those are the only two ways I have learned to do this, unless I am just way off base right now and doing something wrong.
I never drew first, but I drew first blood.
I'm no ones son, unforgiven.
I'm no ones son, unforgiven.
I am really starting to feel dumb. I am either missing something right in front of my face, or completely do not understand the question. I see what I think is the variable name several times, through the setup, initialization and everything.
//InventoryCD class has 5 fields
String cdName[]; // cd name array
// 4 fields need to be set up
cdName = new String [25];
// set values
public void setCDName(String diskName)
{
cdName = cdName;
I tried diskName as well, just because I was so frustrated, but same error.
//InventoryCD class has 5 fields
String cdName[]; // cd name array
// 4 fields need to be set up
cdName = new String [25];
// set values
public void setCDName(String diskName)
{
cdName = cdName;
I tried diskName as well, just because I was so frustrated, but same error.
I never drew first, but I drew first blood.
I'm no ones son, unforgiven.
I'm no ones son, unforgiven.
The problem appears to be that I was trying to set up and array to take the place of cdName, and that is not what I really wanted to do.
I want an array to use cdName. So had gone through and tried to replace all my cd name variables, gets, and sets with array instances and it was just confusing itself. I put my code back the way it was, added an array and that seems to have gotten the first step done.
Code now looks like this:
Now if I can effectivley impliment and use this array is another story altogether. We will see.
I want an array to use cdName. So had gone through and tried to replace all my cd name variables, gets, and sets with array instances and it was just confusing itself. I put my code back the way it was, added an array and that seems to have gotten the first step done.
Code now looks like this:
public class Compactdisk
{// begin class
// set up array
String cdaName[]= new String[5];
//InventoryCD class has 5 fields
String cdName; // cd name
float price; // price of cd
int itemno; // item number of cd
int nstock; // how many units in stock
//Compact disk class constructor
public Compactdisk()
// 4 fields need to be set up
{
cdName = "";
price = 0;
itemno = 0;
nstock = 0;
}
// set values
public void setCDName(String diskName)
{
cdName = diskName;
}
public void setPrice(float cdPrice)
{
price = cdPrice;
}
public void setItemno(int cdItemno)
{
itemno = cdItemno;
}
public void setNstock(int cdStock)
{
nstock = cdStock;
}
// return values
public String getCDName()
{
return (cdName);
}
public float getPrice()
{
return (price);
}
public int getItemno()
{
return (itemno);
}
public int getNstock()
{
return (nstock);
}
// returns inventory value
public float getValue()
{
return(price * nstock);
}
}// end classNow if I can effectivley impliment and use this array is another story altogether. We will see.
I never drew first, but I drew first blood.
I'm no ones son, unforgiven.
I'm no ones son, unforgiven.
That was part of my misunderstanding. I was going to create an array for each variable. (I thought each variable would be a different type and require its own array).
Now I understand that I can use a single array for all field types. I just left in named cdaName because that made the most sence to me, it will be an array of cd information.
My problem now is that I do not understand where to put this array. I want it to be populated with information input from the user, so I think I need to keep all my get and set code, but where does my array tie in? Do I need to create another class completley?
I think my array should look something like
but I cannot find any examples of such a beast for me to learn and build off of.
Now I understand that I can use a single array for all field types. I just left in named cdaName because that made the most sence to me, it will be an array of cd information.
My problem now is that I do not understand where to put this array. I want it to be populated with information input from the user, so I think I need to keep all my get and set code, but where does my array tie in? Do I need to create another class completley?
I think my array should look something like
String cdaName[]= new String{cdName, price, itemno, nstock}; I never drew first, but I drew first blood.
I'm no ones son, unforgiven.
I'm no ones son, unforgiven.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
- Scanning an inputted array of words, and separating each word into a new array? (C)
- PHP Arrays - I can't do em! (PHP)
Other Threads in the Java Forum
- Previous Thread: How to stop opening multiple instance for a jar file
- Next Thread: Writing Servlets (Maybe)



Linear Mode