Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Copy the program DigitPlay.java and implement the TBI (To Be Implemented) method named play(Result r) . Your program cannot contain any import statements. Your play(Result

Copy the program DigitPlay.java and implement the TBI (To Be Implemented) method named play(Result r).

Your program cannot contain any import statements.

Your play(Result r) method cannot call any other methods.

The output of your program must match the following.

number: 5 # of digits: 1 smallest digit: 5 largest digit: 5 digit range: 0 digit sum: 5 digit average: 5.0 digit product: 5 number: 42 # of digits: 2 smallest digit: 2 largest digit: 4 digit range: 2 digit sum: 6 digit average: 3.0 digit product: 8 number: 127 # of digits: 3 smallest digit: 1 largest digit: 7 digit range: 6 digit sum: 10 digit average: 3.3333333333333335 digit product: 14 number: 1024 # of digits: 4 smallest digit: 0 largest digit: 4 digit range: 4 digit sum: 7 digit average: 1.75 digit product: 8 (no multiply by 0) number: 32767 # of digits: 5 smallest digit: 2 largest digit: 7 digit range: 5 digit sum: 25 digit average: 5.0 digit product: 1764 number: 2147483647 # of digits: 10 smallest digit: 1 largest digit: 8 digit range: 7 digit sum: 46 digit average: 4.6 digit product: 903168 number: 9223372036854775807 # of digits: 19 smallest digit: 0 largest digit: 9 digit range: 9 digit sum: 88 digit average: 4.631578947368421 digit product: 179233689600 (no multiply by 0)

--------------------------------------------------------------------------------------------------------------------------------------

Digitplay program:

/* * This Java program takes a positive integer of type long * and prints the following about its digits: * * + the number of digits * + the smallest digit * + the largest digit * + the range of the digits * + the sum of the digits * + the average of the digits (digit 0 is included) * + the product of the digits (digit 0 is excluded) */ public class DigitPlay { public static final String INDENT = " "; public static void main(String[] argv) { long[] data = { 5, 42, Byte.MAX_VALUE, 1024, Short.MAX_VALUE, Integer.MAX_VALUE, Long.MAX_VALUE }; for (int i = 0; i < data.length; i++) print(play(new Result(data[i]))); } public static void print(Result r) { System.out.print("number: " + r.number + INDENT + " # of digits: " + r.ndigits + INDENT + "smallest digit: " + r.min + INDENT + " largest digit: " + r.max + INDENT + " digit range: " + r.range + INDENT + " digit sum: " + r.sum + INDENT + " digit average: " + r.avg + INDENT + " digit product: " + r.product); if (r.has0) System.out.print(" (no multiply by 0)"); System.out.println(" "); } static class Result { public long number; public int ndigits; public int min = 10; public int max = -1; public int range; public int sum; public long product = 1; public double avg; public boolean has0; public Result(long n) { number = n; } } /** * TBI (To Be Implemented)... * * Using a number stored a Result object, this method fills in * the following information about the digits of the number: * # of digits; smallest digit; largest digit; digit range; * digit sum; digit average; flag if number contains a 0; * digit product that excludes multiplying by 0 digits * * @param Result object r to fill in for r.number * @return the filled in Result object r */ public static Result play(Result r) { return r; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions

Question

Determine miller indices of plane A Z a/2 X a/2 a/2 Y

Answered: 1 week ago