我有这个查询和光标有4个值。现在我想用这些值来计算一些东西。
我应该如何使用这个值来计算价格(需要获得价值price1,price2,price3,price4并乘以getResult())?
我应该创建新方法还是在此方法内计算(getParsedPrice)?
这是代码。
//calculate mass
public double getResult() {
double log_length, log_diameter, length, diameter, result;
log_length = Integer.parseInt(getLength().toString());
log_diameter = Integer.parseInt(getDiameter().toString());
length = log_length / 100;
diameter = log_diameter * log_diameter * 3.14159265;
result = length * diameter / 40000;
return result;
}
//get prices from Price
public void getParsedPrice() {
try {
Cursor cursor = db.query("Price", new String[]{"price_stump_kn", "price_stump_eur", "road_price_kn", "road_price_eur"}, "sort = ? AND grade = ? AND length = ? AND diameter BETWEEN diameter_dg AND diameter_gg",
new String[]{getSort_id(), getGrade(), getLength(), getDiameter()}, null, null, null);
System.out.print("result" + cursor.toString());
if (cursor.getCount() > 0) {
while (cursor.moveToNext()) {
double price1 = Double.parseDouble(cursor.getString(0));
double price2 = Double.parseDouble(cursor.getString(1));
double price3 = Double.parseDouble(cursor.getString(2));
double price4 = Double.parseDouble(cursor.getString(3));
}
}
}catch (Exception e) {
e.printStackTrace();
}
}
//Multiply getResult() with price
public double calculatePrice() {
double price, parsedPrice;
price = getResult() * getParsedPrice();
}