I seem to not understand the following,

Using appropriate format specifiers and horizontal tabs, DISPLAY one line for each

product, its quantity sold, its unit price and its total sales

ASSIGN the sum of product1Sales through product5Sales TO totalSalesAllProducts

Using appropriate format specifiers and horizontal tabs, DISPLAY the “Total Sales” line


here is my code

// MailOrder.Java
// This program is a Mail Order form that 
// takes input and produces a print report
// of the results from input data
// Proram by michael Statham
// last updated on sept. 30 2006
// imports the java Scanner
import java.util.Scanner;
public class MailOrder
{
 static Scanner input = new Scanner(System.in);
 // main method begins program execution
   public static void main(String[] args)
   {
      
      //  Defines the varibles
      int quantitySoldOfProduct1 = 0;
      int quantitySoldOfProduct2 = 0;
      int quantitySoldOfProduct3 = 0;
      int quantitySoldOfProduct4 = 0;                  
      int quantitySoldOfProduct5 = 0;
      int productId;
   int quantitySoldOfProduct;
      
   // Prints the Task ID and Programmer
      System.out.println("\nTask 07-02 Ch05   Programmed by Michael Statham");
   // Prints Program input line
   System.out.print("\nProgram input:\n");
      // display the intial Enter prompt
   System.out.print("\n\tEnter product number, or <ctrl>z to stop: ");
      do
      {
      // product Id next statement    
      productId = input.nextInt();
  
   // display quantity sold prompt
      System.out.printf("\t\t      Quantity sold for product%d: ",productId);
      quantitySoldOfProduct = input.nextInt();
          
    // start of switch statement, summarize quantity sold of product
          switch(productId)
          {
              
              case 1:                        quantitySoldOfProduct1 += quantitySoldOfProduct;
                                                  break;
              
              case 2:                        quantitySoldOfProduct2 += quantitySoldOfProduct;
                                                  break;
                                                  
              case 3:                        quantitySoldOfProduct3 += quantitySoldOfProduct;
                                                  break;
                                                  
              case 4:                        quantitySoldOfProduct4 += quantitySoldOfProduct;
                                                  break;
                                                  
              case 5:                        quantitySoldOfProduct5 += quantitySoldOfProduct;
                                                  break;
                                                  
              default:                    System.out.println("ERROR:  Invalid Product number enterd.");
                                                  break;                                                                                                                                                                                                                                                          
                                                  
      }//end switch
      // display the enter prompt again    
      System.out.print("\n\tEnter product number, or <ctrl>z to stop: ");
          
      }while(input.hasNext());
       
      PrintSalesReport(quantitySoldOfProduct1,quantitySoldOfProduct2,quantitySoldOfProduct3,
   quantitySoldOfProduct4,quantitySoldOfProduct5);
      // display end of program
      System.out.println("\nEnd of Program");
            
      }//end main
       
      public static void PrintSalesReport(int quantitySoldOfProduct1, int quantitySoldOfProduct2, 
      int quantitySoldOfProduct3, int quantitySoldOfProduct4, int quantitySoldOfProduct5)
      {
      // assign varibles for Print Sales Report
      int totalSalesAllProducts = 0;
      double unitPriceOfProduct1 = 2.98;
      double unitPriceOfProduct2 = 4.50;
      double unitPriceOfProduct3 = 9.98;
      double unitPriceOfProduct4 = 4.49;
      double unitPriceOfProduct5 = 6.87;
      
      double product1Sales = quantitySoldOfProduct1 * unitPriceOfProduct1;
      double product2Sales = quantitySoldOfProduct2 * unitPriceOfProduct2;
      double product3Sales = quantitySoldOfProduct3 * unitPriceOfProduct3;
      double product4Sales = quantitySoldOfProduct4 * unitPriceOfProduct4;
      double product5Sales = quantitySoldOfProduct5 * unitPriceOfProduct5;
      // display program output line
      System.out.print("\n\nProgram output:\n");
      // displays column heading line
      System.out.print("\n\tProduct\tQuantity\tUnit Price\tTotal Sales\n");
   System.out.println("\n\t   1" + "\t       1" + "\t$     2.98" + "\t$" + "      2.98");
   System.out.println("\t   2" + "\t      10" + "\t$     4.50" + "\t$" + "     45.00"); 
   System.out.println("\t   3" + "\t     100" + "\t$     9.98" + "\t$" + "    998.00"); 
   System.out.println("\t   4" + "\t    1000" + "\t$     4.49" + "\t$" + "  4,490.00"); 
   System.out.println("\t   5" + "\t   10000" + "\t$     6.87" + "\t$" + " 68,700.00"); 
   System.out.println("\n\tTotal Sales" + "\t\t\t\t$ 74,235.98");
   }//end PrintSalesReport
}//end class MailOrder

what exactly are you having problems with?

was having problem with the last few lines, but I figured out my ways of error, lol.

This is what the last part of the program should look like.

// Displays column heading line follow by a space
      System.out.printf("\n\t%s\t%8s\t%10s\t%11s","Product","Quantity","Unit Price","Total Sales\n");
   
   // displays one line each product, and it's quantity, and it's quantity sold ,  
   // it'sunit price, and its total price
   System.out.printf("\n\t   1\t%,8d\t$%9.2f\t$%,10.2f", quantitySoldOfProduct1,
   unitPriceOfProduct1, quantitySoldOfProduct1 * unitPriceOfProduct1);
   System.out.printf("\n\t   2\t%,8d\t$%9.2f\t$%,10.2f",   quantitySoldOfProduct2, 
   unitPriceOfProduct2, quantitySoldOfProduct2 * unitPriceOfProduct2);
      System.out.printf("\n\t   3\t%,8d\t$%9.2f\t$%,10.2f",   quantitySoldOfProduct3,
   unitPriceOfProduct3, quantitySoldOfProduct3 * unitPriceOfProduct3);
   System.out.printf("\n\t   4\t%,8d\t$%9.2f\t$%,10.2f",   quantitySoldOfProduct4,
   unitPriceOfProduct4, quantitySoldOfProduct4 * unitPriceOfProduct4);
   System.out.printf("\n\t   5\t%,8d\t$%9.2f\t$%,10.2f\n",   quantitySoldOfProduct5,
   unitPriceOfProduct5, quantitySoldOfProduct5 * unitPriceOfProduct5);
      //Assigns product sales 1 thur 5 to totalSalesAllProducts
   totalSalesAllProducts = product1Sales + product2Sales + product3Sales + 
   product4Sales + product5Sales;
   //displays Total Sales line, and the total amount for all sales
   System.out.printf("\n\tTotal sales \t\t\t\t$ %,.2f\n", totalSalesAllProducts);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.