Question #4785

Write a method

int bumpMe(int price, int increase, Boolean updown)

That accepts a price in dollars and returns a new price rounded to the nearest dollar, after increasing /decreasing price by increase percent. If updown is true then you should increase the price ;otherwise, decrease the price. Write an appropriate main(…)method to test bumpMe(…)

int bumpMe(int price, int increase, Boolean updown)

That accepts a price in dollars and returns a new price rounded to the nearest dollar, after increasing /decreasing price by increase percent. If updown is true then you should increase the price ;otherwise, decrease the price. Write an appropriate main(…)method to test bumpMe(…)

Expert's answer

public class Test {

public static void main(String[] args)

{

Test myTest = new Test();

System.out.println(myTest.bumpMe(4, 25, true));

System.out.println(myTest.bumpMe(20, 10, false));

}

private

int bumpMe(int price, int increase, Boolean updown) {

if (updown)

{

return (int) Math.round(price + ((float) price * increase /

100));

} else {

return (int) Math.round(price -

((float) price * increase / 100));

}

}

}

public static void main(String[] args)

{

Test myTest = new Test();

System.out.println(myTest.bumpMe(4, 25, true));

System.out.println(myTest.bumpMe(20, 10, false));

}

private

int bumpMe(int price, int increase, Boolean updown) {

if (updown)

{

return (int) Math.round(price + ((float) price * increase /

100));

} else {

return (int) Math.round(price -

((float) price * increase / 100));

}

}

}

## Comments

## Leave a comment