You are on page 1of 8

/*

Program: To compute Economic Order Quantity


Name : Shivam Gupta
Roll No : 424
M.Sc OR Sem 2

*/

import java.io.*;

/* interface eoq containing a method compute */


interface eoq {
double compute();
void show_parameters();
}

/* class to implement the 'EOQ with no shortages' model */


class Model_1 implements eoq {
protected double Q, ic, oc, uc, dr;

/* get the various parameters such as Inventory carrying charge,


ordering cost, unit cost and demand rate */

void read_data (double ic, double oc, double uc, double dr) {
this.ic = ic; // Inventory carrying charge
this.oc = oc; // Ordering cost
this.uc = uc; // Unit cost
this.dr = dr; // Demand rate
}

/* display the parameters for this model */


public void show_parameters() {
System.out.println("\n\tThe parameters for this model are: \n\n");

System.out.print("\tInventory carrying charge (fraction of Re. per unit per


year): ");
System.out.println(ic);

System.out.print("\tOrdering Cost (Rs per order)


: ");
System.out.println(oc);

System.out.print("\tUnit Cost (Rs per unit)


: ");
System.out.println(uc);

System.out.print("\tDemand Rate (units per year)


: ");
System.out.println(dr);
}

/* compute the EOQ for Model 1 */


public double compute() {
Q = Math.sqrt((2*oc*dr)/(ic*uc)) ;
return Q;
}
}

/* class to implement the 'EOQ with planned shortages' model */


class Model_2 extends Model_1 implements eoq {
protected double sc, x;

/* get the various parameters such as Inventory carrying charge,


ordering cost, unit cost, demand rate and shortages cost */

void read_data(double ic, double oc, double uc, double dr, double sc) {
super.read_data(ic, oc, uc, dr); // call the super class method
this.sc = sc; // shortages cost
}

/* display the parameters for this model */


public void show_parameters() {
super.show_parameters();
System.out.print("\tShortages Cost (Rs. per unit per year)
: ");
System.out.println(sc);
}

/* compute the EOQ for Model 2 */


public double compute() {
super.compute();

/* compute Inventory carrying cost by multiplying


Inventory carrying charge with the unit cost */
double IC = ic*uc;

x = Math.sqrt((IC + sc)/(sc));
return Q*x;
}
}

/* class to implement the 'EOQ with finite replenishment, no shortages' model */


class Model_3 extends Model_1 implements eoq {
protected double sr;

/* get the various parameters such as Inventory carrying charge,


ordering cost, unit cost, demand rate and supply rate */

void read_data(double ic, double oc, double uc, double dr, double sr) {
super.read_data(ic, oc, uc, dr); // call the super class method
this.sr = sr; // supply rate
}

/* display the parameters for this model */


public void show_parameters() {
super.show_parameters();
System.out.print("\tSupply(Production) Rate (units per year)
: ");
System.out.println(sr);
}

/* compute the EOQ for Model 3 */


public double compute() {
super.compute();
double x1 = Math.sqrt(sr/(sr-dr));
return Q*x1;
}
}
/* class to implement the 'EOQ with finite replenishment, planned shortages' model
*/
class Model_4 extends Model_2 implements eoq {
protected double sr;

/* get the various parameters such as Inventory carrying charge,


ordering cost, unit cost, demand rate, shortages cost and supply rate */

void read_data(double ic, double oc, double uc, double dr, double sc, double
sr) {
super.read_data(ic, oc, uc, dr, sc); // call the super class method
this.sr = sr; // supply rate
}

/* display the parameters for this model */


public void show_parameters() {
super.show_parameters();
System.out.print("\tSupply(Production) Rate (units per year)
: ");
System.out.println(sr);
}

/* compute the EOQ for Model 4 */


public double compute() {
super.compute();
double x1 = Math.sqrt(sr/(sr-dr));
return Q*x*x1;
}
}

class Inventory {
static double inventory_charge , ordering_cost , unit_cost , demand_rate ,
shortage_cost , supply_rate;

static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

/* constructor function which gets the various parameters as input from the user
*/
Inventory() throws IOException {
System.out.println("\tPlease enter the folowing: \n");

System.out.print("\tInventory carrying charge (fraction of Re. per unit per


year): ");
inventory_charge = Double.parseDouble(in.readLine());

System.out.print("\tOrdering Cost (Rs per order)


: ");
ordering_cost = Double.parseDouble(in.readLine());

System.out.print("\tUnit Cost (Rs per unit)


: ");
unit_cost = Double.parseDouble(in.readLine());

System.out.print("\tDemand Rate (units per year)


: ");
demand_rate = Double.parseDouble(in.readLine());
System.out.print("\tShortages Cost (Rs. per unit per year)
: ");
shortage_cost = Double.parseDouble(in.readLine());

System.out.print("\tSupply(Production) Rate (units per year)


: ");
supply_rate = Double.parseDouble(in.readLine());

/* inventory carrying charge should be less than 1 */


while(inventory_charge > 1) {
System.out.println("\n\tThe Inventory Carrying Charge should be fraction of
a Re., ");
System.out.println("\ti.e., it should be less than 1.\n");
System.out.print("\tPlease re-enter the value of Inventory Carrying Charge
: ");
inventory_charge = Double.parseDouble(in.readLine());
}

/*supply rate should be greater than the demand rate*/


while(supply_rate < demand_rate) {
System.out.println("\n\tThe supply rate can not be less than the demand
rate.");
System.out.println("\tPlease re-enter the values: ");

System.out.print("\tDemand Rate (units per year)


: ");
demand_rate = Double.parseDouble(in.readLine());

System.out.print("\tSupply(Production) Rate (units per year)


: ");
supply_rate = Double.parseDouble(in.readLine());
}
}

/* main function begins */


public static void main(String[] args) throws IOException {

final String CHOICES = "1234Q"; // string of the options available (1 for


Model1, 2 for Model2, etc.)

/* string NAMES contains the names of the options available with a space of
7 alloted to each option */
final String NAMES = "Model 1Model 2Model 3Model 4";

int y = 0; // your choice

System.out.println("\n\n");
System.out.println("\t\t\tEconomic Order Quantity");
System.out.println("\t\t\t***********************\n\n");

new Inventory(); // activate the constructor function

/* display the options corresponding to the various models */


System.out.println("\n");
System.out.println("\tPlease select the model with which to compute EOQ:");

System.out.println("\t--------------------------------------------------\n");
System.out.println("\tModel 1: EOQ with no shortages
-> Press 1");
System.out.println("\tModel 2: EOQ with planned shortages
-> Press 2");
System.out.println("\tModel 3: EOQ with finite replenishment, no shortages
-> Press 3");
System.out.println("\tModel 4: EOQ with finite replenishment, planned
shortages-> Press 4");
System.out.println("");
System.out.println("\tQuit
-> Press Q");

do {
System.out.print("\n\tPlease enter your choice (1/2/3/4/Q): ");

/* convert the choice entered as a string to a digit */


y = CHOICES.indexOf(in.readLine().toUpperCase().charAt(0));

if (y < 0) { // invalid choice


System.out.println("\n\tYou must enter either '1', '2', '3', '4' or
'Q'");
continue;
}

if (y > 3) { // choice to Quit


break;
}

System.out.println("\n\t" + NAMES.substring(7*y,7*y+7)) ; // display the


model corresponding to the choice
System.out.println("\t" + "-------");

switch(y) {
case 0: Model_1 m1 = new Model_1();
m1.read_data(inventory_charge, ordering_cost, unit_cost,
demand_rate);
m1.show_parameters();
System.out.println("\n\tEOQ = " + m1.compute());
break;

case 1: Model_2 m2 = new Model_2();


m2.read_data(inventory_charge, ordering_cost, unit_cost,
demand_rate, shortage_cost);
m2.show_parameters();
System.out.println("\n\tEOQ = " + m2.compute());
break;

case 2: Model_3 m3 = new Model_3();


m3.read_data(inventory_charge, ordering_cost, unit_cost,
demand_rate, supply_rate);
m3.show_parameters();
System.out.println("\n\tEOQ = " + m3.compute());
break;

case 3: Model_4 m4 = new Model_4();


m4.read_data(inventory_charge, ordering_cost, unit_cost,
demand_rate, shortage_cost, supply_rate);
m4.show_parameters();
System.out.println("\n\tEOQ = " + m4.compute());
break;
}
} while(true);

}
}

/*
OUTPUT

Economic Order Quantity


***********************

Please enter the folowing:

Inventory carrying charge (fraction of Re. per unit per year): 2


Ordering Cost (Rs per order) : 50
Unit Cost (Rs per unit) : 60
Demand Rate (units per year) : 100
Shortages Cost (Rs. per unit per year) : 150
Supply(Production) Rate (units per year) : 80

The Inventory Carrying Charge should be fraction of a Re.,


i.e., it should be less than 1.

Please re-enter the value of Inventory Carrying Charge : 0.2

The supply rate can not be less than the demand rate.
Please re-enter the values:
Demand Rate (units per year) : 150
Supply(Production) Rate (units per year) : 200

Please select the model with which to compute EOQ:


--------------------------------------------------

Model 1: EOQ with no shortages -> Press 1


Model 2: EOQ with planned shortages -> Press 2
Model 3: EOQ with finite replenishment, no shortages -> Press 3
Model 4: EOQ with finite replenishment, planned shortages-> Press 4

Quit -> Press Q

Please enter your choice (1/2/3/4/Q): 1

Model 1
-------

The parameters for this model are:

Inventory carrying charge (fraction of Re. per unit per year): 0.2
Ordering Cost (Rs per order) : 50.0
Unit Cost (Rs per unit) : 60.0
Demand Rate (units per year) : 150.0
EOQ = 35.35533905932738

Please enter your choice (1/2/3/4/Q): 2

Model 2
-------

The parameters for this model are:

Inventory carrying charge (fraction of Re. per unit per year): 0.2
Ordering Cost (Rs per order) : 50.0
Unit Cost (Rs per unit) : 60.0
Demand Rate (units per year) : 150.0
Shortages Cost (Rs. per unit per year) : 150.0

EOQ = 36.742346141747674

Please enter your choice (1/2/3/4/Q): 3

Model 3
-------

The parameters for this model are:

Inventory carrying charge (fraction of Re. per unit per year): 0.2
Ordering Cost (Rs per order) : 50.0
Unit Cost (Rs per unit) : 60.0
Demand Rate (units per year) : 150.0
Supply(Production) Rate (units per year) : 200.0

EOQ = 70.71067811865476

Please enter your choice (1/2/3/4/Q): 4

Model 4
-------

The parameters for this model are:

Inventory carrying charge (fraction of Re. per unit per year): 0.2
Ordering Cost (Rs per order) : 50.0
Unit Cost (Rs per unit) : 60.0
Demand Rate (units per year) : 150.0
Shortages Cost (Rs. per unit per year) : 150.0
Supply(Production) Rate (units per year) : 200.0

EOQ = 73.48469228349535

Please enter your choice (1/2/3/4/Q): e

You must enter either '1', '2', '3', '4' or 'Q'

Please enter your choice (1/2/3/4/Q): q


C:\Program Files\Java\jdk\bin>
*/

You might also like