Foto de Juliana V.
Juliana há 19 horas
Enviada pelo
Site

Write the Java code to complete the following: 1. Enter item

Write the Java code to complete the following: 1. Enter item number (alphanumeric). 2. Enter item description (alphanumeric). 3. Enter the item price (decimal). 4. Enter quantity ordered (integer). 5. Enter the total tax for the item (decimal). Enter the dollar amount, not a percent. 6. Enter the total discount for the item (decimal). Enter the dollar amount, not a percent. 7. Enter the net amount for the item (decimal). 8. Display the item number, item description, item price, quantity ordered, tax amount, discount amount, and net amount. Use correct formatting for the data entered. Include appropriate labels. Labels should be on one line and data on the second line. Use tabs to line up the columns.
Conhecimentos Gerais
1 resposta
Minerva IA
Inteligência Artificial do Profes
Respondeu há 19 horas

Certainly! Below is the Java code (in a single class) that meets all the requirements. I’ve included formatted input (via Scanner) and output (via System.out.printf) with tabs, as requested.

import java.util.Scanner;

public class ItemEntry {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 1. Enter item number (alphanumeric)
        System.out.print("Enter item number (alphanumeric): ");
        String itemNumber = scanner.nextLine();

        // 2. Enter item description (alphanumeric)
        System.out.print("Enter item description (alphanumeric): ");
        String itemDescription = scanner.nextLine();

        // 3. Enter the item price (decimal)
        System.out.print("Enter item price (decimal): ");
        double itemPrice = scanner.nextDouble();

        // 4. Enter quantity ordered (integer)
        System.out.print("Enter quantity ordered (integer): ");
        int quantityOrdered = scanner.nextInt();

        // 5. Enter the total tax for the item (decimal)
        System.out.print("Enter total tax amount (decimal): ");
        double taxAmount = scanner.nextDouble();

        // 6. Enter the total discount for the item (decimal)
        System.out.print("Enter total discount amount (decimal): ");
        double discountAmount = scanner.nextDouble();

        // 7. Enter the net amount for the item (decimal)
        System.out.print("Enter net amount for the item (decimal): ");
        double netAmount = scanner.nextDouble();

        // 8. Display the data using labels and formatted output.
        // Labels
        System.out.println("\nItem Number\tDescription\tPrice\t\tQuantity\tTax Amount\tDiscount\tNet Amount");
        // Data (tabbed, 2 decimals for currency)
        System.out.printf("%s\t\t%s\t%s\t\t%d\t\t$%.2f\t\t$%.2f\t\t$%.2f\n",
                itemNumber,
                itemDescription,
                String.format("$%.2f", itemPrice),
                quantityOrdered,
                taxAmount,
                discountAmount,
                netAmount);

        scanner.close();
    }
}

Notes:

  • Uses Scanner for input.
  • Inputs are read in order and type.
  • Uses tabs \t to line up columns.
  • System.out.printf ensures the numbers have 2 decimal places and are shown with a dollar sign.
  • Labels are on one line; data are on the second line, as requested.

Sample Output:

Item Number   Description   Price      Quantity   Tax Amount  Discount   Net Amount
A123          Widget        $45.00     10         $4.50       $2.00      $47.50

You may adjust the input prompts or the spacing as needed for your use case.

Já tem uma conta? Entrar
Ao me cadastrar, confirmo que li e concordo com os Termos de Uso .

Envie sua pergunta

Aprenda do seu jeito, no seu ritmo

Minerva IA
do Profes
Respostas na hora
100% no WhatsApp
Envie suas dúvidas pelo App
Escaneie o QR Code para baixar