Friday 15 August 2014

Chaining returns through methods in Java -



Chaining returns through methods in Java -

first off, i'm positive easy answer, , apologize.

i'm trying figure out if can chain returned value through methods in same class, using overloaded methods. in code below, computebill(double bookprice, int quantity) portion i'm stuck on.

what want do, passed cost of book, , quantity. (main has input section passes outputs these methods; part works fine). pass moneyconversion(), math, converts bigdecimal, , returns result variable bookpricedisp. want computebill() homecoming same value main display.

i'm getting cannot find symbol in class billing. need create new object in each method?

public class billing { public static bigdecimal computebill(double bookprice) { bigdecimal bookpricetaxed = new bigdecimal(bookpriceinput*1.08); homecoming bookpricetaxed; } public static bigdecimal computebill(double bookprice, int quantity) { moneyconversion(bookprice, quantity); homecoming bookpricedisp; } public static void computebill(double bookprice, int quantity, double coupon) { system.out.println("please come in percentage of coupon: "); double couponinput = keyboard.nextdouble(); system.out.println("you entered " + couponinput + "%"); moneyconversion(bookprice, quantity); bigdecimal couponsavings = new bigdecimal(bookprice * quantity * couponinput); system.out.println("your books cost $" + ((bookpricedisp - couponsavings)*1.08)); system.out.println("your coupon saved $" + couponsavings); } public static bigdecimal moneyconversion(double bookprice, int quantity) { //using bigdecimal right dollars/cents. bigdecimal bookpricedisp = new bigdecimal(bookprice * quantity); bookpricedisp = bookpricedisp.setscale(2, bigdecimal.round_half_up); homecoming bookpricedisp; }

thank you,

-stephan

bookpricedisp local variable of moneyconversion(). local variable, name indicates, local, , not visible/usable outside of block (i.e. moneyconversion() method) it's defined.

what want homecoming same value of moneyconversion() method returns, so:

// assign result of moneyconversion() local variable result bigdecimal result = moneyconversion(bookprice, quantity); // homecoming local variable homecoming result;

or simply:

// homecoming value returned moneyconversion() homecoming moneyconversion(bookprice, quantity);

java chaining

No comments:

Post a Comment