methods, classes, arrays.. oh my!
wow. so im normally pretty quick about pickin' up a new programming language, but it's been a while since i've done it and i'm struggling with a java homework assignment. here is the code I have so far:
import staugIO.StaugIO; //import StaugIO() class
class GetInfo{
//Declare private variables
String itemNumber;
String itemName;
String itemWeight;
String itemPrice;
StaugIO io = new StaugIO();
//Second Level of Refinement Methods
public void setNumber(){
itemNumber = io.readString("Please enter the item's number: ");
}
public void setName(){
itemNumber = io.readString("Please enter the item's name: ");
}
public void setWeight(){
itemNumber = io.readString("Please enter the item's weight: ");
}
public void setPrice(){
itemNumber = io.readString("Please enter the item's price: ");
}
}//End Candy
public class MainProgram {
StaugIO io = new StaugIO();
public static void main(String[] args) {
}
}
[/CODE]
Here is what the program SHOULD do:
Code a program that will store candy information. Each candy's data will be stored in an array as an object. To do so the array will use a class as a data type. Let the user determine the size of the array. Prompt the user to enter the item number, item name, weight, and price. Once the array has been populated with candy information, display the contents of the array one at a time in separate GUI windows.
seems pretty simple, i just cannot for the life of me get my head around the classes, methods, and how to call each one.. the public/private/static/void has got me so confused it's not even funny...
can someone help me get the structure correct so that i can start coding this thing? apparently it's supposed to have a main class, a class to set/get the info, a class to create teh array and display the info and then the main method... what goes where?
to guess at what Fubarable means...
I think fubarable means that your Candy class should have a constructor in it, such as
Code:
public Candy(string name, double weight, double cost, int IDNumber){
}
you could then call this constructor in another class that accepts input to set the variables.
Fubarable, correct me if the doubles should be something else, not too familiar with them.
You may also want additionally methods to set the name, weight, cost, and IDNumber after using the constructor, but leave those for later.