I was able to revise my code. now have it working. thank you for your assistance on this posting.
beatonl 0 Newbie Poster
Sorry I forgot .. I now have (CODE) before and after each of the 4 classes.
Again any assiatance would be greatly appreciated,
Hi ..
I will try to explain what I am trying to do.... but before I start... I will say I was able to successfully return the concatenated String variable back to the calling class. I verified this by entering a print statement after the call to the get method in ComputerPart.
What I am trying to do is generate test data. I need to create an order (this works) and create a product that is associated with the order. You can have multi. orders with multi products associated with the individual order #.
Here is the error message I am getting.
OrderGenerator.java:37: addProduct(net.allenwhite.order.Product) in net.allenwhi
te.order.GenericOrder cannot be applied to (java.lang.String)
genericorder.addProduct(product);
^
thank you any assistance would be appreciated. I know something is not compatible....
here is a sample of my code...
the calling class can be referred to as OrderGenerator
the getmethod is located in ComputerPart class
also included is code for Product.java & GenericOrder.java (these are referenced in the OrderGenerator class. )
1 of 4
public class OrderGenerator {
private Random rand = new Random();
public GenericOrder generateOrder() { //create an order
System.out.println("[ORDER GENERATOR] starting ...");
GenericOrder genericorder = null;
int orderType = rand.nextInt(1);
switch (orderType) {
case 0: genericorder = new ComputerOrder();
break;
}
int numberOfProducts = rand.nextInt(6);
numberOfProducts++; // We always want at least …
beatonl 0 Newbie Poster
I meant to include in previous entry the following error message:
OrderGenerator.java:37: addProduct(net.allenwhite.order.Product) in net.allenwhi
te.order.GenericOrder cannot be applied to (java.lang.String)
genericorder.addProduct(product);
^
thank you any assistance would be appreciated. I know something is not compatible....
^
beatonl 0 Newbie Poster
Hi ..
I will try to explain what I am trying to do.... but before I start... I will say I was able to successfully return the concatenated String variable back to the calling class. I verified this by entering a print statement after the call to the get method in ComputerPart.
What I am trying to do is generate test data. I need to create an order (this works) and create a product that is assoicated with the order. You can have multi. orders with multi products associated with the individual order #.
here is a sample of my code...
the calling class can be referred to as OrderGenerator
the getmethod is located in ComputerPart class
also included is code for Product.java & GenericOrder.java (these are referenced in the OrderGenerator class. )
1 of 4
public class OrderGenerator {
private Random rand = new Random();
public GenericOrder generateOrder() { //create an order
System.out.println("[ORDER GENERATOR] starting ...");
GenericOrder genericorder = null;
int orderType = rand.nextInt(1);
switch (orderType) {
case 0: genericorder = new ComputerOrder();
break;
}
int numberOfProducts = rand.nextInt(6);
numberOfProducts++; // We always want at least one egg.
for (int counter=0; counter<numberOfProducts; counter++) {
// Determine the type of egg to add.
String product = null;
ComputerPart compart = new ComputerPart();
int productType = rand.nextInt(1);
switch (productType) {
case 0:
product = compart.getComputerPart();
System.out.println("[back in calling class - Class A] " + product);
break;
}
// Add the product to order
genericorder.addProduct(product);
}
return …
beatonl 0 Newbie Poster
I tried changing the getmethod to return an Integer instead of ClassB and revised the returm line (See bold code below).
public [B]Integer [/B] getComputerPart() {
String floatToString=Float.toString(instPrice);
String conString = instDesc+instMfg+floatToString;
[B]return Integer.parseInt(conString);[/B]
}
the calling class (Class A) has prod defined as Product prod = null;
where Product is a class with subclasses.
Product prod = null;
ComputerPart compart = new ComputerPart();
prod = compart.getComputerPart();
System.out.println("[ordergenerator back ] " + prod);
The following is the new error I am receiving. I am thinking that the type returning from the getComputerPart() is not being accepted by the prod variable. it may help if I understood what
type is "Product prod = null".
ERROR
OrderGenerator.java:33: incompatible types
found : java.lang.Integer
required: net.lois.order.Product
prod = compart.getComputerPart();
^
beatonl 0 Newbie Poster
Hi,
I am new to the java world.
I am getting the following error.
ClassB.java:62: incompatible types
found : int
required: order.ClassB
return Integer.parseInt(conString);
This what I am trying to do..
I have two classes. Class A and Class B. Class A calls a method located in Class B (refer to code below).
Class A
Product prod = null;
ComputerPart compart = new ComputerPart();
prod = compart.getComputerPart();
Class B
I have three local variables (xdesc,xmfg,xprice) and I have three instance variables defined (instDesc,instMfg,instPrice). instDesc and instMfg are String variables and instPrice is a float variable. the local variables are assigned to the instance variables.
Then I converted the float variable instPrice to String and concentated call three variable into a Sting variable called conString. then try to return conString back the variable called prod in the calling class (Class A).
public Class B getComputerPart() {
.
.
.
instDesc = xdesc;
instMfg = xmfg;
instPrice = xprice;
String floatToString=Float.toString(instPrice);
String conString = instDesc+instMfg+floatToString;
return Integer.parseInt(conString);
}
any assistance on what I can do to convert the string variable conString to a type that is accepted by the prod variable in Class A. in addition, I believe it may have something to do with the following line of code in ClassA "Product prod = null". prod will not accept conString.