Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Invoice Number Formatter | Controlling Numeric Output with DecimalFormat
Formatting & Parsing in Java

bookChallenge: Invoice Number Formatter

In this challenge, you will apply what you have learned about the DecimalFormat class to format both invoice numbers and monetary amounts for a list of invoices. Your goal is to produce output where each invoice appears as "Invoice #XXXX: $X,XXX.XX", with the invoice number zero-padded to four digits and the amount formatted with grouping separators and exactly two decimal places. This task will help you practice combining number formatting patterns for both integers and floating-point values, and reinforce your understanding of grouping, padding, and currency display.

Tarea

Swipe to start coding

Implement the formatInvoices method to return a list of formatted invoice strings. Each string should display the invoice number as a four-digit, zero-padded integer, and the amount as a currency with grouping and two decimal places.

  • Format each invoice number with leading zeros to ensure four digits.
  • Format each amount as currency, with grouping separators and two decimal digits.
  • Combine the formatted invoice number and amount in the format: "Invoice #XXXX: $X,XXX.XX".
  • Return a list of all formatted invoice strings.

Solución

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 6
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Suggested prompts:

Can you show me an example of how the formatted output should look?

What is the sample input data for the invoices?

Can you explain how to use the DecimalFormat class for this task?

close

bookChallenge: Invoice Number Formatter

Desliza para mostrar el menú

In this challenge, you will apply what you have learned about the DecimalFormat class to format both invoice numbers and monetary amounts for a list of invoices. Your goal is to produce output where each invoice appears as "Invoice #XXXX: $X,XXX.XX", with the invoice number zero-padded to four digits and the amount formatted with grouping separators and exactly two decimal places. This task will help you practice combining number formatting patterns for both integers and floating-point values, and reinforce your understanding of grouping, padding, and currency display.

Tarea

Swipe to start coding

Implement the formatInvoices method to return a list of formatted invoice strings. Each string should display the invoice number as a four-digit, zero-padded integer, and the amount as a currency with grouping and two decimal places.

  • Format each invoice number with leading zeros to ensure four digits.
  • Format each amount as currency, with grouping separators and two decimal digits.
  • Combine the formatted invoice number and amount in the format: "Invoice #XXXX: $X,XXX.XX".
  • Return a list of all formatted invoice strings.

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 6
single

single

some-alt