Question: Complete the implementation of 4 public static methods. Add documentation at the class level (required) and at the method level (optional). Please include the name

Complete the implementation of 4 public static methods. Add documentation at the class level (required) and at the method level (optional). Please include the name of both people in your group. You should each submit the lab.

  1. favorite()
    1. int return type.
    2. No parameters.
    3. Evaluates and returns the value of the expression
    4. ( ( ( (16 * 65 ) + 12 ) * 72 ) / 68 ) 1
  2. isDateable()
    1. boolean return type.
    2. Two int parameters y1 and y2.
    3. Returns whether it is advisable for a person of age y1 to date a person of age y2. It is only advisable if age y2 is at least seven years older than than half of the age y1.
  3. piggyBank()
    1. int return type.
    2. Five int parameters named pennies, nickels, dimes, quarters, and halfDollars.
    3. Returns the worth in cents of the coins indicated by its five parameters.
  4. wasted()
    1. void return type.
    2. One double parameter and one int parameter named respectively r and d.
    3. Displays the number of gallons of water wasted over d days with the water dripping at r drips per minute.
    4. Note: The US Geological Survey defines the number of drips in a gallon as 15,140.

You may use Task.java as a starting point for completing the implementation of the methods. The methods can be tested by uncommenting statements from the method main() of program TaskTests.java. A run of the program could produce the following output. (Note that you need to save Task.java and TaskTests.java in the same directory.)

Trying favorite() favorite(): nbr1 = 1112 favorite(): nbr2 = 1112 Trying isDateable() Task.isDateable( 19, 14 ): false Invoke.isDateable( 20, 17 ): true Trying piggyBank() Task.piggyBank( 3, 1, 4, 1, 5 ): 323 Invoke.piggyBank( 4, 5, 6, 7, 8 ): 664 Trying wasted() wasted( 3.75, 30 ): 10 gallons wasted( 7.50, 5 ): 3 gallons

Challenge activities:

  • Add documentation to one or more of the methods following JavaDoc syntax (see zyBooks or resource in Unit Checklist)
  • Edit TaskTests.java to include more unit testing statements
  • Add error-checking to each method to handle invalid entries. For example, in a number of the methods, values that are negative would not be valid. What would error message could you give the user? What would be an appropriate return value in that case?

TASK.JAVA below

/**

* Write a description of class Task here.

*

* @author (your name)

* @version (a version number or a date)

*/

public class Task

{

/**

* method favorite(): returns ( ( ( (16 * 65 ) + 12 ) * 72 ) / 68 ) - 1

*

* @param

* @return

*/

public static int favorite() {

return 10; // change method body to produce correct answer

}

/**

* method isDateable(): returns whether the second age is dateable for

* a person of the first age

*/

public static boolean isDateable(int y1, int y2) {

return true; // change method body to product correct answer

}

// method piggyBank(): returns what the change is worth in cents

// write the method body and signature yourself

// method wasted(): prints line that is number of wasted gallons of water

// write the method body and signature yourself

}

TASK.TESTS.java below

/**

* Add your class documentation here

*/

public class TaskTests {

// method main(): program starting point

public static void main( String[] args ) {

System.out.println( " Trying favorite() " );

// uncomment next four after completing favorite()

// int nbr1 = Task.favorite();

// int nbr2 = Task.favorite();

// System.out.println( "favorite(): nbr1 = " + nbr1 );

// System.out.println( "favorite(): nbr2 = " + nbr2 );

System.out.println( " Trying isDateable() " );

int u1 = 19; int v1 = 14;

int u2 = 20; int v2 = 17;

// boolean b1 = Task.isDateable( u1, v1 );

// boolean b2 = Task.isDateable( u2, v2 );

// System.out.println( "Task.isDateable( " + u1 + ", " + v1 + " ): "

// + b1 );

// System.out.println( "Task.isDateable( " + u2 + ", " + v2 + " ): "

// + b2 );

System.out.println( " Trying piggyBank() " );

int p1 = 3; int p2 = 4;

int n1 = 1; int n2 = 5;

int d1 = 4; int d2 = 6;

int q1 = 1; int q2 = 7;

int h1 = 5; int h2 = 8;

// int c1 = Task.piggyBank( p1, n1, d1, q1, h1 );

// int c2 = Task.piggyBank( p2, n2, d2, q2, h2 );

// System.out.println( "Task.piggyBank( " + p1 + ", " + n1 + ", " + d1 + ", " + q1 + ", " + h1 + " ): " + c1 );

// System.out.println( "Task.piggyBank( " + p2 + ", " + n2 + ", " + d2 + ", " + q2 + ", " + h2 + " ): " + c2 );

System.out.println( " Trying wasted() " );

// uncomment next four lines after completing wasted()

// System.out.print( "wasted( 3.75, 30 ): " );

// Task.wasted( 3.75, 30 );

// System.out.print( "wasted( 7.50, 5 ): " );

// Task.wasted( 7.50, 5 );

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!