answer.
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]
2 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]2 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
Richard uses Microsoft outlook as his email client. He wants to check whether he has received any new mail. Identify which key R
Kazeer [188]
Refresh...... I mean, that is what I hit
4 0
2 years ago
Select the described workplace culture from the drop-down menu.
Vilka [71]

Answer:

  • Adaptive
  • Consistency-oriented
  • Achievement-based
  • Involvement-oriented

Explanation:

Adaptive Consistency-oriented workplace cultures emphasizes reacting quickly to change.

Consistency-oriented workplace cultures emphasizes everyone being in agreement.

Achievement-based Consistency-oriented workplace cultures emphasizes accomplishing goals.

Involvement-oriented Achievement-based workplace cultures emphasize development of new skills.

7 0
2 years ago
Read 2 more answers
10. There is repeated code in these onevent blocks. Choose the correct code for the updateScreen() function which would be calle
Lorico [155]

Answer:

front zise24

Explanation:

on event down botton

6 0
2 years ago
The area of a square is stored in a double variable named area. write an expression whose value is length of the diagonal of the
cestrela7 [59]

Answer:

The correct answer to the following question will be "Math.sqrt(area*2)".

Explanation:

  • The Math.sqrt( ) method in JavaScript is used to find the squares root of the given figure provided to the feature as a variable.
  • Syntax Math.sqrt(value) Variables: this function takes a single variable value that represents the amount whose square root is to be determined.
  • The area of the figure is the number of squares needed to cover it entirely, like the tiles on the ground.

Area of the square = side times of the side.

Because each side of the square will be the same, the width of the square will only be one side.

Therefore, it would be the right answer.

5 0
2 years ago
Emulated drivers provide enhanced drivers for the guest OS and improve performance and functionality for IDE and SCSI storage de
Vikki [24]

Answer:

The answer is "Option 2".

Explanation:

  • All the other drivers replicate even existing technical embedded devices. These systems have optimistic, and they are commonly accessible to inbox operators as most web browsers. It is an Imitated device, that performance problems because of all the emulator is the workload.
  • Integration Services  is a program package, which is created on a guest OS of a VM, that provides enhanced guest OS drivers and improves accuracy, functionality for IDE and SCSI storage systems, networking interfaces, and monitor and multimedia devices, that's why it is incorrect.

8 0
2 years ago
Other questions:
  • how do you make a circuit so 1 switch will turn on/off all the lights(3 lights) and a second switch will change the lights from
    14·2 answers
  • Which table style option is useful to display aggregated data when it is checked? total row filter button last column header row
    8·1 answer
  • The ________ method is based on simple arithmetic. The process involves dividing the bits of a frame into equal segments, adding
    11·1 answer
  • Lance is at a bus station. His friend is using the ATM machine to withdraw some money. Lance notices a stranger deceptively watc
    6·2 answers
  • Why can't you use Friedman's attack on block ciphers?
    12·1 answer
  • Describe two reasons to use the Internet responsibly. Explain what might happen if the Internet use policies were broken at your
    12·2 answers
  • Ken Olson, president of Digital Equipment Corp. in the late 1970's, Thomas J. Watson, chairman of IBM in the early 1940's, and T
    6·1 answer
  • E-mail is an efficient means of disseminating information quickly and inexpensively. However, HIPAA regulations affect e-mail us
    13·1 answer
  • Select the correct answer. Andy wants to become a multimedia producer. Which degree can help him achieve this goal? A. bachelor’
    5·1 answer
  • What is the value of the variable result after these lines of code are executed?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!