So what I'm trying to do is take input from user for two different products being bought. I need to have this data inputted into the table that I believe I'm creating correctly. However the scanner method is only keeping the information but not outputting them into the table. My question really is can you create sub variables for the previously declare variable such as p1 and p2 for the variable productName or qty1 and qty2 for quantity. I know why its not outputting data into the table because I incorrectly labeled the placeholders for example %f. I haven't found any information saying so and from everything I've found that is closely related would be creating an array for all the inputs needed. I'm not the best but I would appreciate any help. Thanks
import java.util.Scanner;
import java.text.NumberFormat;
public class Project2
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int quantity;
double unitPrice;
String productName;
System.out.println("Enter name for Product 1:");
productName = scan.nextLine();
System.out.println("Enter the amount desired for Product 1:");
quantity = scan.nextInt();
System.out.println("Please enter the price of Product 1:");
unitPrice = scan.nextDouble();
double total = unitPrice * quantity;
System.out.println("Enter name for Product 2:");
productName = scan.nextLine();
System.out.println("Enter the amount desired for Product 2:");
quantity = scan.nextInt();
System.out.println("Please enter the price of Product 1:");
unitPrice = scan.nextDouble();
System.out.println("--------------------------------------------");
System.out.println("| Product | Qty | Price | Total |");
System.out.println("--------------------------------------------");
System.out.printf("| %c | %f | %d | %.2f |\n",productName, quantity,unitPrice, total);
System.out.printf("| %c | %f | %d | %.2f |\n",productName, quantity, unitPrice, total);
System.out.println("-------------------------------------------- ");
}
}