TEXT   26
java2
Guest on 16th March 2023 06:39:31 AM


  1. import java.util.Scanner;
  2. import java.*;
  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. public class Products
  15. {
  16. public static void main(String[]args)
  17. {
  18. Scanner sc=new Scanner(System.in);
  19. System.out.print("Enter product code :");
  20. int pCode=sc.nextInt();
  21. System.out.print("\nEnter product name :");
  22. String pName=sc.next();
  23. System.out.print("\nEnter product 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,"Pencil",12);
  28. ps[2]= new Product(102,"Pen",10);
  29. int minprice=ps[0].price;
  30. System.out.print("\nCODE\tNAME\tPRICE");
  31. System.out.print("\n____________________");
  32. for(Product p:ps)
  33. {
  34. System.out.print("\n"+p.pCode+"\t"+p.pName+"\t"+p.price);
  35. if(minprice > p.price)
  36. {
  37. minprice=p.price;
  38. }
  39. }
  40. System.out.print("\n____________________");
  41. System.out.print("\nLowest Cost Product details");
  42. System.out.print("\n____________________");
  43. for(Product p:ps)
  44. {
  45. if(minprice==p.price)import java.util.Scanner;
  46. import java.*;
  47. class Product
  48. {
  49. int pCode,price;
  50. String pName;
  51. Product(int pCode,String pName,int price)
  52. {
  53. this.pCode=pCode;
  54. this.pName=pName;
  55. this.price=price;
  56. }
  57. }
  58. public class Products
  59. {
  60. public static void main(String[]args)
  61. {
  62. Scanner sc=new Scanner(System.in);
  63. System.out.print("Enter product code :");
  64. int pCode=sc.nextInt();
  65. System.out.print("\nEnter product name :");
  66. String pName=sc.next();
  67. System.out.print("\nEnter product price :");
  68. int price=sc.nextInt();
  69. Product[]ps=new Product[3];
  70. ps[0]= new Product(pCode,pName,price);
  71. ps[1]= new Product(101,"Pencil",12);
  72. ps[2]= new Product(102,"Pen",10);
  73. int minprice=ps[0].price;
  74. System.out.print("\nCODE\tNAME\tPRICE");
  75. System.out.print("\n____________________");
  76. for(Product p:ps)
  77. {
  78. System.out.print("\n"+p.pCode+"\t"+p.pName+"\t"+p.price);
  79. if(minprice > p.price)
  80. {
  81. minprice=p.price;
  82. }
  83. }
  84. System.out.print("\n____________________");
  85. System.out.print("\nLowest Cost Product details");
  86. System.out.print("\n____________________");
  87. for(Product p:ps)
  88. {
  89. if(minprice==p.price)
  90. {
  91. System.out.print("\nProduct Code :"+p.pCode);
  92. System.out.print("\nProduct Name :"+p.pName);
  93. System.out.print("\nProduct Price:"+p.price);
  94. }
  95. }
  96. }
  97. }
  98. {
  99. System.out.print("\nProduct Code :"+p.pCode);
  100. System.out.print("\nProduct Name :"+p.pName);
  101. System.out.print("\nProduct Price:"+p.price);
  102. }
  103. }
  104. }
  105. }

Raw Paste

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