- import java.util.*;
- import java.util.Scanner;
- class Product
- {
- int pCode,Price;
- String pName;
- Product(int pCode,String pName,int Price)
- {
- this.pCode=pCode;
- this.pName=pName;
- this.Price=Price;
- }
- }
- class Products
- {
- public static void main(String[]args)
- {
- Scanner sc=new Scanner(System.in);
- System.out.println("Enter the product name:");
- String pName=sc.next();
- System.out.println("Enter the code:");
- int pCode=sc.nextInt();
- System.out.println("Enter the price:");
- int Price=sc.nextInt();
- Product[]ps= new Product[3];
- ps[0]= new Product(pCode,pName,Price);
- ps[1]= new Product(101,"lipstick",450);
- ps[2]= new Product(102,"sunscreen",550);
- int minPrice=ps[0].Price;
- System.out.println("\n Code\t Name\t Price");
- System.out.println("\n----------------------------------");
- for(Product p:ps)
- {
- System.out.println(p.pCode+"\t"+p.pName+"\t"+p.Price);
- if(minPrice > p.Price)
- {
- minPrice=p.Price;
- }
- }
- System.out.println("\n-------------------------");
- System.out.println("Lowest cost of product:");
- System.out.println("\n---------------------------------");
- for(Product p:ps)
- {
- if(minPrice==p.Price)
- {
- System.out.println("product code"+p.pCode);
- System.out.println("Product name"+p.pName);
- System.out.println("product price"+p.Price);
- }
- }
- }
- }
Raw Paste