Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

An understanding of the following concepts and techniques: Software requirements (K) Combining branching and looping (A) Command-line arguments and basic input/output (C) Using arrays to

An understanding of the following concepts and techniques:

  • Software requirements (K)
  • Combining branching and looping (A)
  • Command-line arguments and basic input/output (C)
  • Using arrays to store and retrieve data (A)
  • Writing testable code and automated testing (A)

Functional requirements

Develop a FizzBuzz program with the following behavior:

  • It expects a natural number (positive integer), n, as its first command-line argument. The default argument, in case none is provided explicitly, is 100. You can provide a specific non-default argument in the runtime configuration (Run > Run... > Edit Configurations > Program Arguments). You can use the following technique to parse the argument, which is coming in as a string, to a number:

    int max = MAX; if (args.length == 1) { try { max = Integer.parseInt(args[0]); } catch (final NumberFormatException ex) { System.err.println("argument should be a positive integer"); System.exit(4); } }

  • If the argument n is invalid, i.e., zero or less, the main method should also print a suitable error message and exit with error code, say, 2.
  • It determines and prints the fizz buzz sequence up to n, one number per line, on the standard output. For example, for n = 17, the program would produce the following output:

    1 2 fizz 4 buzz fizz 7 8 fizz buzz 11 fizz 13 14 fizz buzz 16 17

  • Language and development environment

  • Java required
  • IntelliJ IDEA recommended
  • Other environments are acceptable as long as you state in your README file how to compile and run your program from the command line (terminal).
  • Code quality

  • Generally keep your code as clear and simple as possible.
  • Follow the Google Java Style Guide.
  • In addition, follow the Lufer final-correctness rule: Declare every (local or instance) variable as final unless it has to be modified after its initialization.
  • Testability

    Implement your program in such a way that the main method, contained in the class Main, is responsible for argument validation and parsing (conversion to a number), invoking the fizz buzz functionality, and outputting the results. The actual fizz buzz functionality should be provided separately in its own FizzBuzz class and in such a way that it is parametric in the max count for the desired fizz buzz sequence. For example:

    /** * Creates a FizzBuzz instance up to the specified max. * @param max the (positive) max count * @throws IllegalArgumentException if max is not positive */ public FizzBuzz(final int max) { /* validate arg and assign to instance variable (field) */ }

    /** * Produces the FizzBuzz sequence from one up to the specified max. * @return the resulting FizzBuzz sequence */ public String[] run() { /* ... */ }

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

Essential Data Protection For Estate Agencies In Singapore 2024

Authors: Yang Yen Thaw Yt

1st Edition

B0CQK79WD3, 979-8872095392

More Books

Students also viewed these Databases questions

Question

4. Label problematic uses of language and their remedies

Answered: 1 week ago