katalyst
03-27-2009, 02:06 AM
wow, normally i pick stuff up right away, but im struggling with this little problem in java..
i need to create an array as a class data type. the 'candy' array will have 4 fields, id, item name, weight, and price (all strings). i want the user to specify the array size instead of hard-coding it and then all i want is to be able to output the 4 records, one item in the array at a time.
seems so easy, but im brain-farting on the syntax and how to setup the classes and methods inside them....
can someone PLEASSSE help get me pointed in the right direction? here is what i have so far:
import staugIO.StaugIO; //import StaugIO() class
public class Program {
StaugIO io = new StaugIO();
public static void main(String[] args) {
//app code
}
}
class CaptureData {
//Declare private variables
private String itemNumber;
private String itemName;
private String itemWeight;
private String itemPrice;
}//End captureData
class ProcessData {
//Declare private variables
private int size, index;
private ProcessData[] candy;
private StaugIO io;
//First Level of Refinement Methods
public void getContent(){
size = readInt("How many items do you want to enter?");
item = new ProcessData[size] // give the null array form, dimension
for(index = 0; index < size; ++index){
item[index] = new NameOfClass();
item[index].nameOfFirstSetMethod();
item[index].nameOfSecondSetMethod();
}
displayContent();
return
}
public void displayContent(){
//type a String object to store content of array
String stringObject = item[];
for(index = 0; index < size; index ++){
nameOfStringObject = "<HTML>" + "CANDY NO. " + (index + 1) + "<br><br>" + "ITEM NO: " + item[index].nameOfFirstGetMethod() + "<br>" + "WT: " + item[index].nameOfSecondGetMethod() + "<br>" + "</HTML>";
io.writeInfo(stringObject);//print String object
}
return
}
} //End ProcessData
excuse some of my pseudocode... ANY help is greatly appreciated
i need to create an array as a class data type. the 'candy' array will have 4 fields, id, item name, weight, and price (all strings). i want the user to specify the array size instead of hard-coding it and then all i want is to be able to output the 4 records, one item in the array at a time.
seems so easy, but im brain-farting on the syntax and how to setup the classes and methods inside them....
can someone PLEASSSE help get me pointed in the right direction? here is what i have so far:
import staugIO.StaugIO; //import StaugIO() class
public class Program {
StaugIO io = new StaugIO();
public static void main(String[] args) {
//app code
}
}
class CaptureData {
//Declare private variables
private String itemNumber;
private String itemName;
private String itemWeight;
private String itemPrice;
}//End captureData
class ProcessData {
//Declare private variables
private int size, index;
private ProcessData[] candy;
private StaugIO io;
//First Level of Refinement Methods
public void getContent(){
size = readInt("How many items do you want to enter?");
item = new ProcessData[size] // give the null array form, dimension
for(index = 0; index < size; ++index){
item[index] = new NameOfClass();
item[index].nameOfFirstSetMethod();
item[index].nameOfSecondSetMethod();
}
displayContent();
return
}
public void displayContent(){
//type a String object to store content of array
String stringObject = item[];
for(index = 0; index < size; index ++){
nameOfStringObject = "<HTML>" + "CANDY NO. " + (index + 1) + "<br><br>" + "ITEM NO: " + item[index].nameOfFirstGetMethod() + "<br>" + "WT: " + item[index].nameOfSecondGetMethod() + "<br>" + "</HTML>";
io.writeInfo(stringObject);//print String object
}
return
}
} //End ProcessData
excuse some of my pseudocode... ANY help is greatly appreciated