Question
public interface NumberFormatter String format(int n); } Consider three classes that implement this interface. A DecimalSeparatorFormatter formats an integer with decimal separators; for example, one
public interface NumberFormatter String format(int n); }
Consider three classes that implement this interface. A DecimalSeparatorFormatter formats an integer with decimal separators; for example, one million as 1,000,000. An AccountingFormatter formats negative numbers with parentheses; for example, 1 as (1). A BaseFormatter formats the number in base n, where n is any number between 2 and 36 that is provided in the constructor (i.e, the constructor in the BaseFormatter class takes one integer parameter that specifies the base to be used for conversion). Write a test class called NumberFormatterTests that includes test cases for the above-mentioned three classes. Sample expected output is given below:
DecimalSeparatorFormatter 38756 -> 38,756 956432 -> 956,432
AccountingFormatter -987654321 -> (987654321) -287 -> (287
BaseFormatter 100 -> 100 [Base 10] 21 -> 10101 [Base 2] 1194684 -> 123ABC [Base 16]
Write test cases for valid and invalid input. You are NOT expected to write the corresponding classes.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started