Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me write a JAVA code named makeDingDong ? The method will take three positive integer parameters a , b , and maxNumber

Can someone help me write a JAVA code namedmakeDingDong?

The method will take three positive integer parametersa,b, andmaxNumber. The method will iterate through all the integers between 1 andmaxNumberandreturn a Stringas shown in the print statement below. The rules are:

  1. If the number is divisible bya(and not byb), it is replaced by"ding"
  2. If the number is divisible byb(and not bya), it is replaced by"dong"
  3. If the number is divisible by bothaandb, it is replaced by"dingdong"

A few rules and error checking:

  • The integersaandbmust be between 2 and 15.
  • Bothaandbmust be stricly less thanmaxNumber.

If any one of the two errors condition above is present, the method should print, respectively andEXACTLY:

  • The first two inputs have to be between 2 and 15.
  • The first two inputs have to be smaller than the third.

If both error conditions occur, the second one (aandbless thanmaxNumber) takes precedence.

Note there is no requirement about the relationship betweenaandb, but their order as arguments matters (acontrols the dings, andbthe dongs)

Final rule: Do not leave any trailing spaces at the end of your output String.

Here in an example:

System.out.println(makeDingDong(3, 7, 24));

yields

1 2 ding 4 5 ding dong 8 ding 10 11 ding 13 dong ding 16 17 ding 19 20 dingdong 22 23 ding

public class DingDong {

// Your method here

// Some test cases in the main method

public static void main(String[] args) {

// System.out.println(makeDingDong(1, 6, 22));

// System.out.println(makeDingDong(3, 17, 20));

// System.out.println(makeDingDong(2, 7, 6));

// System.out.println(makeDingDong(3, 3, 9));

// System.out.println(makeDingDong(3, 7, 24));

// Output:

// The first two inputs have to be between 2 and 15.

// The first two inputs have to be between 2 and 15.

// The first two inputs have to be smaller than the third.

// 1 2 dingdong 4 5 dingdong 7 8 dingdong

// 1 2 ding 4 5 ding dong 8 ding 10 11 ding 13 dong ding 16 17 ding 19 20 dingdong 22 23 ding

}

}

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

Step: 3

blur-text-image

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

Basic Technical Mathematics

Authors: Allyn J. Washington, Richard Evans

12th Edition

0137529899, 9780137529896

More Books

Students also viewed these Programming questions

Question

Did the parties reach an agreement that both were satisfied with?

Answered: 1 week ago