Hey guys,
I'm writing some code for a school assignment and I'm almost done except that I'm now getting this error that I can't quite figure out. I'm sure it's pretty beginner stuff, but I'm really new to this whole java thing, so if someone could possibly explain to me why it's occuring, I could work on fixing it! I would like to understand why it's happening though, not just the answer code. Thanks!
Basically I'm creating two methods. One of them adds flowers and quantities to an order. That's the addOrder() method. The other should print the total of the order, that's the printTotal() method.
I'm getting this error: "cannot find symbol - variable newFlower" at this line (near the bottom in the printTotal() method):
CODE
oldTotal = newFlower[i].quantity * newFlower[i].price;
I kind of get why it's happening (but could use some clarifying), but how would I go about making this method print the total of the additions to the order made by the method before it?
Here's my code so far. Thanks for any help!

CODE
public class FlowerCounterArrays {
private String flowerName;
private double price;
private int quantity;
public double getPrice() {
return price;
}
public void setPrice(double p) {
price = p;
}
public String getFlowerName() {
return flowerName;
}
public void setFlowerName(String name) {
flowerName = name;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int q) {
quantity = q;
}
public String toString() {
return flowerName;
}
public void addOrder(String flowerName, int quant) {
FlowerCounterArrays[] newFlower = new FlowerCounterArrays[5];
newFlower[0] = new FlowerCounterArrays();
newFlower[1] = new FlowerCounterArrays();
newFlower[2] = new FlowerCounterArrays();
newFlower[3] = new FlowerCounterArrays();
newFlower[4] = new FlowerCounterArrays();
newFlower[0].setFlowerName("petunia");
newFlower[1].setFlowerName("pansy");
newFlower[2].setFlowerName("rose");
newFlower[3].setFlowerName("violet");
newFlower[4].setFlowerName("carnation");
newFlower[0].setPrice(0.50);
newFlower[1].setPrice(0.75);
newFlower[2].setPrice(1.50);
newFlower[3].setPrice(0.50);
newFlower[4].setPrice(0.80);
int x = 0;
for (FlowerCounterArrays flower : newFlower) {
if (flower.toString().equals(flowerName)) {
newFlower[x].setQuantity(quant);
System.out.println("You have added " + newFlower[x].quantity + " " + newFlower[x].flowerName + "(s) to your order. These flowers are priced at $" + newFlower[x].price + " per stem. Thank you for your business!");
break;
}
else {
x++;
}
}
}
public void printTotal() {
int i = 0;
double oldTotal = 0;
double newTotal = 0;
double total = 0;
while (i < 5) {
oldTotal = newFlower[i].quantity * newFlower[i].price;
total = newTotal + oldTotal;
newTotal = total;
i++;
}
System.out.println("The total for your order is $" + total);
}
}
This post has been edited by he4dhuntr: 15 Oct, 2008 - 07:31 AM