Advertisement
Kulas_Code20

Products

Jul 13th, 2022
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Products {
  3.     public static void main(String[] args) {
  4.         Scanner scan = new Scanner(System.in);
  5.         int cntr = 0;
  6.         String[] name = new String[100];
  7.         String[] idNo = new String[100];
  8.         double[] profit = new double[100];
  9.        
  10.         System.out.print("Enter number of items: ");
  11.         int number = scan.nextInt();
  12.         System.out.println("");
  13.  
  14.         for (int i = 0; i < number; i++) {
  15.             System.out.println("Enter data of item " + (i+1) + ":");
  16.  
  17.             System.out.print("ID: ");
  18.             String id = scan.nextLine();
  19.  
  20.             scan.nextLine();
  21.  
  22.             System.out.print("Name: ");
  23.             String ProdName = scan.nextLine();
  24.  
  25.             System.out.print("Quantity: ");
  26.             int quantity = scan.nextInt();
  27.  
  28.             System.out.print("Price: ");
  29.             int price = scan.nextInt();
  30.             System.out.println(" ");
  31.  
  32.             int multipy = quantity * price;
  33.            
  34.             idNo[i] = id;
  35.             name[i] = ProdName;
  36.             profit[i] = multipy;
  37.         }
  38.        
  39.         System.out.println("------------------------------------------------ ");
  40.         System.out.println("Summary of items");
  41.         System.out.println("------------------------------------------------ ");
  42.         System.out.println("No." + "ID" + "Names" + "                        " + "Expected Profit");
  43.         for(int i=0; i<100; i++){
  44.             System.out.println((i+1) + "       " + idNo[i] + "        " + name[i] + "             " + profit[i]);
  45.             cntr++;
  46.             if(cntr == number){
  47.                 break;
  48.             }
  49.         }
  50.     }
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement