In this program that I need to write, can someone explain me the part that is ma
ID: 3598078 • Letter: I
Question
In this program that I need to write, can someone explain me the part that is marked darker,(I DON'T NEED THE CODE) ,I just want to know what to do on that part cause i dont really understand.
Consider an interface public interface NumberFormatter String format (int n); Provide four classes that implement this interface. A DefaultFormatter formats an integer in the usual way. A DecimalSeparatorFormatter formats an integer with decimal separators, for example, one million as 1,000,000. An AccountingFormatter formats negative numbers with arenthesis; for example, -1 as (1). A BaseFormatter formats the number as base n, where n is any number between 2 and 36 that is provided in the constructor. Write a method that takes an array of integers and a NumberFormatter object and prints each number on a separate line, formatted with the given formatter. The numbers should be right aligned. Provide a test class called FormatintsTest.,java that shows the program working with an array of numbers. Use the numbers 8, 100, -10, 45, 0 as your test values in the array. Show all four formatters working with the array. Use 20 for n for the BaseFormatter. Follow all directions in the COP3337 Class Rules for Submitting Programs Please use the file > export> to zip option in NetBeans. The zip file should be named FirstNameLast NameA4.zip.Explanation / Answer
Actually here the requirement is baseformatter i.e nothing but formats the number as base n.Here n value should between 2 and 36.
So here we have taken input array 8,100,-10,45,0 numbers.So our agenda to convert each and every number into base n.Again in our requirement they have said just take n value as 20.
So first take number 8 to convert
Number 8 (base 20) after converting into decimal form the result is 8.
Number 100 (base 20) is 400.
Number -10 (base 20) is 20.
Number 45 (base 20) is 85.
The above one is in decimal format that nothing but base 10.
If u want in base 2 i.e binary form then resultant output for binary form for each and every numbers
Number 8 (base 20) is in base 2: 1000
Number 100 (base 20) is in base 2: 110010000.
Number -10 (base 20) is in base 2: 10100.
Number 45 (base 20) is in base 2: 1010101.
So in this way we can format number as base n.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.