Write a program to implement the company policy. Initialize stock quantity variable with 1000 and credit variable with 500.The program must prompt the customer to enter quantity and their credit.

Questions & AnswersCategory: Programming LanguageWrite a program to implement the company policy. Initialize stock quantity variable with 1000 and credit variable with 500.The program must prompt the customer to enter quantity and their credit.
violet asked 1 year ago

The policy followed by company to process customer orders is given by the following rules:

  1. If a customer ordered quantity is less than or equal to that in stock and his credit is OK then supply his requirement.
  2. If his credit is not OK do not supply. Send him warning.
  3. If his credit is OK but the item in stock is less than his order, supply what is in stock. Send to him the date on which the balance will be shipped.

Write a program to implement the company policy. Initialize stock quantity variable with 1000 and credit variable with 500.The program must prompt the customer to enter quantity and their credit.

1 Answers
Lokesh Kumar Staff answered 1 year ago
import java.util.Scanner; 
public class Main {
    public static void main(String[] args) {
        int stock_qty = 100;
        int cust_credit = 500;
        int user_stock = 0;
        boolean order_placed = false;

    
        Scanner sc= new Scanner(System.in);    //System.in is a standard input stream  
        System.out.print("Enter Stock Quantity: ");  
        user_stock = sc.nextInt(); 
    
    
        if (user_stock <= cust_credit) {
            if (user_stock <= stock_qty){ order_placed = true; System.out.println("Order Placed Successfully!"); System.out.println("Stock: " + user_stock + "units"+ "\nRemaining Credit: " + (cust_credit-user_stock)); } else { if (user_stock>0){
                    order_placed = true;
                    System.out.println("Partial Order Placed Successfully!");
                    System.out.println("Stock: " + stock_qty + " units"+ "\nRemaining Credit: " + (cust_credit-stock_qty));
                }
            }
        }
        else {
            System.out.println("Warning! You don't have enough credit in your wallet.");  
        }
    
    
        if (order_placed){
            System.out.println("Balance will be shipped within 48 hours."); 
        }

    }
}