TEXT   17
ppppp
Guest on 16th March 2023 07:07:13 AM


  1. import java.util.*;
  2. import java.util.Scanner;
  3. class Product
  4. {
  5. int pCode,Price;
  6. String pName;
  7. Product(int pCode,String pName,int Price)
  8. {
  9. this.pCode=pCode;
  10. this.pName=pName;
  11. this.Price=Price;
  12. }
  13. }
  14. class Products
  15. {
  16. public static void main(String[]args)
  17. {
  18. Scanner sc=new Scanner(System.in);
  19. System.out.println("Enter the product name:");
  20. String pName=sc.next();
  21. System.out.println("Enter the code:");
  22. int pCode=sc.nextInt();
  23. System.out.println("Enter the price:");
  24. int Price=sc.nextInt();
  25. Product[]ps= new Product[3];
  26. ps[0]= new Product(pCode,pName,Price);
  27. ps[1]= new Product(101,"lipstick",450);
  28. ps[2]= new Product(102,"sunscreen",550);
  29. int minPrice=ps[0].Price;
  30. System.out.println("\n Code\t Name\t Price");
  31. System.out.println("\n----------------------------------");
  32. for(Product p:ps)
  33. {
  34. System.out.println(p.pCode+"\t"+p.pName+"\t"+p.Price);
  35. if(minPrice > p.Price)
  36. {
  37. minPrice=p.Price;
  38. }
  39. }
  40. System.out.println("\n-------------------------");
  41. System.out.println("Lowest cost of product:");
  42. System.out.println("\n---------------------------------");
  43. for(Product p:ps)
  44. {
  45. if(minPrice==p.Price)
  46. {
  47. System.out.println("product code"+p.pCode);
  48. System.out.println("Product name"+p.pName);
  49. System.out.println("product price"+p.Price);
  50. }
  51. }
  52. }
  53. }

Raw Paste

Login or Register to edit or fork this paste. It's free.