Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Directions: Given the following problem descriptions, write appropriate method c

ID: 3817451 • Letter: D

Question

Directions: Given the following problem descriptions, write appropriate method call and method definitions for each problem(In Java language).

A) Write a method call and a method definition for a method named showValue that will print out the value of an integer variable named amount. The amount variable will be a local variable declared in the calling method.

B) Write a method call and a method definition for a method named showProduct that will print out the result of the multiplication of two double values. The product should be printed out with 2 decimal positions. The two double values will be defined in the calling method as two variables, nbr1 and nbr2.

C) Write a method call and a method definition for a method named showValues that will print out the values of the following three variables that are declared in the calling method. The float value should be printed out with 2 decimal positions.

char answer = ‘Y’;

double amount = 36.546312;

int count = 5;

Explanation / Answer

/*Program to write appropriate method call

and method definitions to print the values
*/

import java.math.*;
import java.text.DecimalFormat;


public class Test
{
  
   public static void main(String [] args)
   {
       int amount1=10;
       double nbr1=2.6171, nbr2=3.424;
       char answer = 'Y';
       double amount2 = 36.546312;
       int count = 5;
       showValue(amount1);
       showProduct(nbr1,nbr2);
       showValues(answer,amount2,count);
   }
  
   //method to show value of amount
   static void showValue(int amount)
   {
       System.out.println("Amount "+amount);
   }
  
   /*method to print the product of two double values
   upto two decimal places*/
   static void showProduct(double nbr1, double nbr2)
   {
       double product,result;
       result = nbr1 * nbr2;

       DecimalFormat df2 = new DecimalFormat(".##");
       System.out.println("Product " + df2.format(result));
  
   }
  
   //method to print three values
   static void showValues(char answer, double amount2,int count)
   {
       System.out.println("Answer "+answer);
       System.out.println("Amount "+amount2);
       System.out.println("Count "+count);
   }
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote