Challenge: 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.
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.
Oplossing
Bedankt voor je feedback!
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Awesome!
Completion rate improved to 5.56
Challenge: Invoice Number Formatter
Veeg om het menu te tonen
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.
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.
Oplossing
Bedankt voor je feedback!
single