New paste Repaste Download
Question Title:
Supplier Management, Militant Search
Problem Statement:
You are given three different programming tasks based on common scenarios. Write solutions to meet the requirements of the tasks below.
---
Task 1: Supplier Management System
A company maintains a list of suppliers and the products they provide. You need to:
1. Store the details of suppliers and their products.
2. Find suppliers based on a product ID.
3. Find the number of products with a specific supplier based on their ID and name.
Input Format:
First, an integer n representing the number of suppliers.
For each supplier:
An integer id (Supplier ID).
A string name (Supplier Name).
A long mobile (Supplier Mobile Number).
An integer numProd (Number of products the supplier provides).
For each product:
An integer prodId (Product ID).
A string prodName (Product Name).
A double prodPrice (Product Price).
An integer productId for which you need to find suppliers.
An integer supplierId and a string supplierName to count products with that supplier.
Output Format:
Print the details of suppliers providing the given product ID.
Print the number of products with the supplier of the given ID and name.
---
Task 2: Militant Search System
A list of militants is maintained for security operations. You need to:
1. Search for a militant based on their ID.
2. List militants with less than 2 years of experience.
Input Format:
An integer n representing the number of militants.
For each militant:
An integer id (Militant ID).
A string name (Militant Name).
A string category (Militant Category).
A double experience (Militant's years of experience).
An integer searchId representing the ID of the militant to search for.
Output Format:
Print the details of the militant with the given ID or a message if not found.
Print the details of militants with less than 2 years of experience or a message if no such militants exist.
---
Constraints:
All IDs are unique.
Supplier names are case-insensitive for equality checks.
1 ≤ n ≤ 100 for each task.
0 ≤ prodPrice ≤ 10^6
0 ≤ experience ≤ 50
1 ≤ t ≤ 100
---
Sample Input 1 (Task 1):
2  
1  
Supplier1  
9876543210  
2  
101  
Product1  
100.50  
102  
Product2  
200.75  
2  
Supplier2  
9876543211  
1  
103  
Product3  
150.00  
102  
1  
Supplier1
Sample Output 1 (Task 1):
Supplier name: Supplier1  
Supplier mobile: 9876543210  
The number of products with mentioned supplier is :2
---
Sample Input 2 (Task 2):
3  
1  
John  
Sniper  
1.5  
2  
Alice  
Scout  
2.5  
3  
Bob  
Medic  
0.8  
1
Sample Output 2 (Task 2):
1  
John  
Sniper  
1.5  
3  
Bob  
Medic  
0.8
---
Notes:
Ensure all inputs and outputs follow the formats precisely.
Optimize the solutions for efficiency.
Use the provided class structure to solve the tasks effectively.
**********************************************************************************************************************************
Code
**********************************************************************************************************************************
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
    public static void main(String args[]) throws Exception {
        
       Scanner sc = new Scanner(System.in);
       int num = sc.nextInt(); sc.nextLine();
       List<Supplier> sup = new ArrayList<>();
       
       for(int i = 0; i < num; i++){
        
        int id = sc.nextInt(); sc.nextLine();
        String name = sc.nextLine();
        long mobile = sc.nextLong(); sc.nextLine();
        int numProd = sc.nextInt(); sc.nextLine();
        List<Product>productList = new ArrayList<>();
        
        for(int j = 0; j < numProd; j++){
            int prodId = sc.nextInt(); sc.nextLine();
            String prodName = sc.nextLine();
            double prodPrice = sc.nextDouble(); sc.nextLine();
            
            Product newProd = new Product(prodId, prodName, prodPrice);
            productList.add(newProd);
            
            
        }  
         
        Supplier sup1 = new Supplier(id, name, mobile, productList);
        sup.add(sup1);
    
       }
        int newProdId = sc.nextInt(); //sc.nextLine();
        List<Supplier> s = getSupplierBasedOnProduct(sup, newProdId);
        if(!s.isEmpty()){
            for (Supplier supplier : s) {
                System.out.println("Supplier name: "+supplier.name);
                System.out.println("Supplier mobile: "+supplier.mobile);
            }
        }else{
            System.out.println("No supplier available for the product.");
        }
        
        int newSupId = sc.nextInt();sc.nextLine();
        String newSupName = sc.nextLine();
        int suppCount = productsWithTheSupplier(sup, newSupId, newSupName);
        if(suppCount == 0){
            System.out.println("No supplier found");
        }else{
            System.out.println("The number of products with mentioned supplier is :"+suppCount);
        }
    }
    public static List<Supplier> getSupplierBasedOnProduct(List<Supplier> sup, int id){
        List<Supplier> resSup = new ArrayList<>();
        for(Supplier it : sup){
            for(Product p : it.productList){
                if(p.prodId == id)
                resSup.add(it);
            }
        }
        return resSup;
    }
    
    public static int productsWithTheSupplier(List<Supplier> sup, int id, String name){
       int count = 0;
       for(Supplier it : sup){
        if(it.id == id && it.name.equalsIgnoreCase(name)){
          count = it.productList.size();
        }
       }
       return count;
    }
}
// ----------------------- Product - Supplier ---------------------------
class Supplier{
    int id;
    String name;
    long mobile;
    List<Product>productList;
    
    public Supplier(int id, String name, long mobile, List<Product>productList){
        this.id = id;
        this.name = name;
        this.mobile = mobile;
        this.productList = productList;
    }
}
class Product{
    int prodId;
    String prodName;
    double prodPrice;
    
    public Product(int a, String b, double c){
        this.prodId = a;
        this.prodName = b;
        this.prodPrice = c;
    }
}
Question Title:
Supplier Management,
Problem Statement:
You are given three different programming tasks based on common scenarios. Write solutions to meet the requirements of the tasks below.
---
Task 1: Supplier Management System
A company maintains a list of suppliers and the products they provide. You need to:
1. Store the details of suppliers and their products.
2. Find suppliers based on a product ID.
3. Find the number of products with a specific supplier based on their ID and name.
Input Format:
First, an integer n representing the number of suppliers.
For each supplier:
An integer id (Supplier ID).
A string name (Supplier Name).
A long mobile (Supplier Mobile Number).
An integer numProd (Number of products the supplier provides).
For each product:
An integer prodId (Product ID).
A string prodName (Product Name).
A double prodPrice (Product Price).
An integer productId for which you need to find suppliers.
An integer supplierId and a string supplierName to count products with that supplier.
Output Format:
Print the details of suppliers providing the given product ID.
Print the number of products with the supplier of the given ID and name.
Filename: None. Size: 8kb. View raw, , hex, or download this file.

This paste expires on 2025-01-15 11:18:16.127396. Pasted through web.