You are now going to write the printSign() method. Your method must: use the public access modifier
take a single formal argument of type double
return no value, i.e. have a void return type
use the divide() method to find the result of attempting to divide the argument by the current value of divisor and store the result in a suitable local variable called quotient
l using nested selection statements, print out to the Display Pane 'The quotient is zero', 'The quotient is positive', or 'The quotient is negative', depending on whether quotient is zero, greater than zero, or less than zero, , respectively.
Write the method printSign() as specified above. You should include an appropriate comment before the method header describing what the method does in terms of its argument and the output in the Display Pane.
1
Expert's answer
2016-12-06T14:32:07-0500
public class Main { public double currentValueOfDivisor;
/** * Method to find the result of attempting to divide * the argument by the current value of divisor and * store the result in a suitable local variable * called quotient * print out to the Display Pane 'The quotient is zero', * 'The quotient is positive', or 'The quotient is * negative', depending on whether quotient is zero, * greater than zero, or less than zero, respectively. * @param value dividend */ public void printSign(double value) { double quotient = divide(value, currentValueOfDivisor); if (quotient > 0) System.out.println("The quotient is positive"); else if (quotient < 0) System.out.println("The quotient is negative"); else System.out.println("The quotient is zero"); } }
Comments
Leave a comment