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

Please help. I need to write a tester class that contains a main method for test

ID: 3631463 • Letter: P

Question

Please help. I need to write a tester class that contains a main method for testing the methods of the DblOutput class (described below). The main method should include a loop that: prompts for and reads in a double value, writes out the value in specified formats, and checks to see if the user wants to run the program again.

***The DblOutput class contains methods that take a double value and output it in various formats. The methods include:

public static void writeDollar (double d) // writes out d as a US currency amount $x.xx

public static void writeFraction(double d) // writes d as a fraction

public static void writeDecFormat (double d, int places) // writes d as a decimal with specified number of decimal places

public static void writeSciFormat (double d, int places) // writes d in scientific format (using e notation)***

Thank you!

Explanation / Answer

import java.util.*;

import java.text.*;

public class Program1//EliminatingDuplicates

{

public static void main(String args[])

{

writeDollar(1234.56);

double d = 0.12345;

writeSciFormat (d,3);

writeDecFormat(d,4);

}

public static void writeDollar (double d)

{

NumberFormat nf = NumberFormat.getInstance(Locale.US);

System.out.println("Dollar format:$"+nf.format(d));

}

     public static void writeDecFormat (double d, int places)

     {

          String str="0.";

          for(int i=0;i<places;i++)

              str=str+"#";

               NumberFormat formatter = new DecimalFormat();

           formatter = new DecimalFormat(str);

           

          System.out.println(formatter.format(d));

     }

     public static void writeSciFormat (double d, int places)

     {

          String str="0.";

          for(int i=0;i<places-2;i++)

              str=str+"#";

              str=str+"E0";

           

             NumberFormat formatter = new DecimalFormat();

           formatter = new DecimalFormat(str);

           

          System.out.println(formatter.format(d));  

     }

}

Dollar format:$1,234.56

1.2E-1

0.1234