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();
}
}
Scanner for input.\t to line up columns.System.out.printf ensures the numbers have 2 decimal places and are shown with a dollar sign.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.