1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
prohojiy [21]
3 years ago
15

Consider an interface p ublic interface NumberFormatter { String format (in n); } Provide four classes that implement this inter

face. 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 AccountingFor matter formats negative numbers with parenthesis; 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 th at shows the program working with an array of numbers.
Computers and Technology
1 answer:
sesenic [268]3 years ago
3 0

Answer and Explanation:

Here is the code for the question with output.

public interface NumberFormatter {

  public String format(int n);

}

class DefaultFormatter implements NumberFormatter

{

  public String format(int n)

  {

      return String.valueOf(n);

  }

}

class DecimalFormatter implements NumberFormatter

{

  public String format(int n)

  {

      return String.format("%,d",n); //formats the number by putting comma for 3 digits

  }

}

class AccountingFormatter implements NumberFormatter

{

  public String format(int n)

  {

      return String.format("(%d)",n);

  }

}

class BaseFormatter implements NumberFormatter

{

  int base;

 

  public BaseFormatter(int b)

  {

         

      base = b;

      if(base < 2 || base > 36) //if values out of range 2-36 inclusive are given, set default to 2

          base = 2;

  }

  public String format(int n)

  {

      return Integer.toString(n, base);      

  }

  int getBase()

  {

      return base;

  }

}

public class TestNumberFormatter {

  private static void print(int n, NumberFormatter formatter)

  {

      String s = String.format("%15s",formatter.format(n));

      System.out.print(s);

  }

  public static void main(String[] args) {

      int numbers[]= {100,55555,1000000,35,5};

      DefaultFormatter defFmt = new DefaultFormatter();

      DecimalFormatter deciFmt = new DecimalFormatter();

      AccountingFormatter accFmt = new AccountingFormatter();

      BaseFormatter baseFmt=new BaseFormatter(16) ; //base 16

      String s;

     

      System.out.println("\tDefault \t Decimal \tAccounting \t Base("+baseFmt.getBase()+")");

      for(int i = 0; i < numbers.length; i++)

      {

          print(numbers[i], defFmt);

          print(numbers[i], deciFmt);

          print(numbers[i], accFmt);

          print(numbers[i], baseFmt);

          System.out.println();//new line

      }

     

  }

}

output

  Default    Decimal    Accounting    Base(16)

100 100 (100) 64

55555 55,555 (55555) d903

1000000 1,000,000 (1000000) f4240

  35 35 (35) 23

5 5 (5) 5

You might be interested in
What types of standards are developed by the Electronics Industries Alliance (EIA)?
vladimir1956 [14]

Answer:

It comprises individual organisation that together have agreed on certain data transmissions standards such as EIA/TIA -232 formerly known as RS- 232

5 0
3 years ago
Read 2 more answers
How do you chose a profile pic on brainly?
pogonyaev

Answer:

Go to the profile page and click on the profile image

6 0
3 years ago
I need help! Please please
Scorpion4ik [409]

The correct answers are given as:

  1. Turning the lens dial clockwise
  2. Manual settings
  3. Tone
  4. File format
  5. JPEG or RAW

The given questions had to do with taking photos, photography, and the likes and how lenses are used to capture images, and file formats are used to select the size and quality of images.

<h3>What is Photography?</h3>

This refers to the art of taking pictures in a background in a bid to make still images.

Hence, we can see that The correct answers are given:

  1. Turning the lens dial clockwise
  2. Manual settings
  3. Tone
  4. File format
  5. JPEG or RAW

The given questions had to do with taking photos, photography, and the likes and how lenses are used to capture images, and file formats are used to select the size and quality of images.

Read more about photography here:

brainly.com/question/13600227

#SPJ1

6 0
1 year ago
Why is it important to stand clear and not touch the person while the AED is analyzing or defibrillating?
galben [10]

Answer:

Because you could also receive shock

Explanation:

Automatic external defibrillators can help save lives during sudden cardiac arrest.

Do not touch the person while the AED is analyzing; touching or moving the person can affect the analysis. You or another person could be injured by shock. And you could prevent the AED from analyzing your heart rate correctly.

5 0
3 years ago
Drag the system component on the left to the device or program that fits with the system component.
Strike441 [17]

Answer:

A. Back up software - Utility software

B. Printer - Device drivers

C. Camera - Firmware

D. Television - Firmware

E. Games console - Firmware

F. Antivirus software - Utility software

G. Disk Cleaner - Utility software

H. Video Card - Device drivers

Explanation:

Computer system components are the physical or hardware and software parts of the device. It is a combination of system software like utility software, device drivers and firmware, application software, and the hardware components and kernel.

4 0
3 years ago
Other questions:
  • Consider a set of mobile computing clients in a certain town who each
    13·1 answer
  • Which mitigation technique would prevent rogue servers from providing false ip configuration parameters to clients?
    5·2 answers
  • Help me!!!!! This is the last question! HELP ME! I REPEAT: HELP ME!!!! I AM SO IN NEED!!!
    12·2 answers
  • Bitlocker uses the computer's __________ chip to store encryption keys and does not rely on individual user credentials. securit
    10·1 answer
  • Boardman College maintains two files—one for Sociology majors and another for Anthropology majors. Each file contains students'
    5·1 answer
  • How do I make sure I have full access to this app where do I put in payment information
    8·1 answer
  • The Publisher-Subscriber design pattern is used to create __________________ communication between software objects and is used
    13·1 answer
  • How are hyperlinks created and used within a presentation? Check all that apply. Hyperlinks are set to open another source file.
    7·2 answers
  • Josh is learning about hackers know for finding loopholes in systems, without notifying the company or organization beforehand.
    13·1 answer
  • // This pseudocode segment is intended to compute the number
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!