You are on page 1of 78

# JAVA

PRACTICAL
FILE

## Submitted By :Unnati Srivastava

Indraprastha College for Women

## M.Sc. Operational Research

Semester II

Section B
INDEX
S.No Practical T. Signature

1 WAP to determine the roots of quadratic equations by taking inputs from the
user.
2 Find roots of a quadratic equation through Command Line Arguments.
5 Print Fibonacci series recursively.
6 Program to display tower of Hanoi on the output screen.
7 Program to reverse the digits of number and sum of digits using string
functions.
8 To sort data of employeeson employee name, code, age.
9 Program to fit a linear line on list of observations. Also compute the mean
spuare error of fitting in each case.
10 Implement matrix class, Use methods for addition, subtraction, multiplication
and transpose.
11 Implement a menu driven Statistical calculator for the following
 Mean
 Harmonic Mean
 Geometric Mean
 Variance
 Covariance
 Regression coefficient
12 Program to fit poisson distribution and find the mean square error of fitting.
13 Write a menu driven program for 4 EOQ models using inheritance. Model 1
should be the base class.
14 Write a menu driven program to implement M|M|1 , M|M|C and M|M|
infinity queuing models.
/*

## College : Indraprastha College for Women

Section : B

*/

//Program 1 : WAP to determine the roots of quadratic equations by taking inputs from the user.
import java.util.Scanner;

## public static void main(String args[])

double D,r,x1,x2;

## System.out.println("Enter value of a : ");

double a=sc.nextDouble();

## System.out.println("Enter value of b : ");

double b=sc.nextDouble();

## System.out.println("Enter value of c : ");

double c=sc.nextDouble();

D=Math.pow(b,2)-4*a*c;

if (D>0)

r=Math.sqrt(D);

System.out.println("Roots of given equation are " + ((-b+r)/2) + " and " + ((-b-r)/2));

else if (D<0)

r=Math.sqrt(-D);

System.out.println("Roots of given equation are " + (-b/2)+ "+" +(r/2)+"i" + " and " + (-b/2) + (-
r/2)+"i");

else

System.out.println("Roots of given equation are " + (-b/2) + " and " + (-b/2));

}
}

//Output :

/*

Enter value of a :

Enter value of b :

-6

Enter value of c :

*/

Section : B

*/

## //Program 2 :Find roots of a quadratic equation through Command Line Arguments.

import java.util.Scanner;

## public static void main(String args[])

double D,r,x1,x2;

double a = Integer.parseInt(args[0]);

double b = Integer.parseInt(args[1]);

double c = Integer.parseInt(args[2]);

D=Math.pow(b,2)-4*a*c;

if (D>0)

r=Math.sqrt(D);

System.out.println("Roots of given equation are " + ((-b+r)/2) + " and " + ((r)/2));

else if (D<0)

r=Math.sqrt(-D);

System.out.println("Roots of given equation are " + (-b/2)+ "+" +(r/2)+"i" + " and
" + (-b/2) + (-r/2)+"i");

else

System.out.println("Roots of given equation are " + (-b/2) + " and " + (-b/2));

//Output :

/*
C:\Users\User\Desktop\Sem II>javac java2.java

*/

/*

Section : B */

## //Program 3 : WAP for showing the concept of method overloading.

import java.util.*;

## public class java3

int area(int a)

return a*a;

double area(double a)

return 3.14*a*a;

return a*b;

## double area(double a, double b, double c)

double s=(a+b+c)/2;

return Math.sqrt(s*(s-a)*(s-b)*(s-c));

## Scanner sc = new Scanner(System.in);

int y=1;

while(y==1)

{
System.out.print("\nEnter : \n1 : Area of Square\n2 : Area of Rectangle\n3 : Area of Triangle\n4 : Area of

switch(sc.nextInt())

case 1 :

break;

case 2 :

break;

case 3 :

## System.out.println("\nArea of Triangle is : " + obj.area(sc.nextDouble(), sc.nextDouble(),

sc.nextDouble()));

break;

case 4 :

break;

default :

}

## System.out.print("\nIf you want to continue then press 1 : ");

y=sc.nextInt();

/* Output :

Enter :

1 : Area of Square

2 : Area of Rectangle

3 : Area of Triangle

4 : Area of Circle

## Enter side of Square : 6

Area of Square is : 36

## If you want to continue then press 1 : 1

Enter :

1 : Area of Square

2 : Area of Rectangle

3 : Area of Triangle

4 : Area of Circle

## If you want to continue then press 1 : 1

Enter :

1 : Area of Square
2 : Area of Rectangle

3 : Area of Triangle

4 : Area of Circle

## If you want to continue then press 1 : 1

Enter :

1 : Area of Square

2 : Area of Rectangle

3 : Area of Triangle

4 : Area of Circle

*/

/*

## College : Indraprastha College for Women

Section : B */

class StudentData

stuID = 100;

stuAge = 18;

stuID = num1;

stuName = str;

stuAge = num2;

return stuID;

## public void setStuID(int stuID)

this.stuID = stuID;
}

return stuName;

## public void setStuName(String stuName)

this.stuName = stuName;

return stuAge;

## public void setStuAge(int stuAge)

this.stuAge = stuAge;

public static void main(String args[]) //This object creation would call the default constructor

## System.out.println("Student ID is: "+myobj.getStuID());

/*This object creation would call the parameterized constructor StudentData(int, String, int)*/

## System.out.println("Student Age is: "+myobj2.getStuAge());

System.out.println("Student ID is: "+myobj2.getStuID());

/*

Output :

*/

/*

## College : Indraprastha College for Women

Section : B */
//Program 5 :Print Fibonacci series recursively.

import java.util.Scanner;

## System.out.println("How many terms you want to see? ");

int n = sc.nextInt();

int a=0,b=1,c=1;

## System.out.print(a + " " );

for(int i=1;i<n;i++)

## System.out.print(c + " ");

c=a+b;

a=b;

b=c;

System.out.println("\n");

/*

Output :

0 1 1 2 3 5 8 */

/*

Section : B */

## //Program 6 :Program to display tower of Hanoi on the output screen.

import java.util.*;

## System.out.println("Enter the block number : ");

int n = sc.nextInt();

## for(int j=0 ; j<n-i ; j++)

System.out.print(" ");

## for(int k=i ; k<2*i+1 ; k++)

System.out.print("||");

System.out.println("");

/*

Output :

**
****

******

*********

*/

/*

## Name :Unnati Srivastava

College : Indraprastha College for Women

Section : B */

//Program 7 :Program to reverse the digits of number and sum of digits using string functions.

import java.util.Scanner;

str = sc.next();

st.append(str);

int sum = 0;

## System.out.println("Reverse : " + st.reverse() );

System.out.println("Sum of digits:"+(sum));

/*
Output :

## Enter any number:2345678

Reverse : 8765432

Sum of digits:35

*/

/*

## Name :Unnati Srivastava

College : Indraprastha College for Women

Section : B */

## //Program 8 :To sort data of employees on employee name, code, age.

import java.io.*;

import java.util.*;

class Emp

String name;

int age,code;

name = name1;

code = age1;

age = code1;

## public static void update (Emp emp1[], int n) throws IOException

int s = emp1.length;

## for (int i = s-n ;i< s; i++)

System.out.println();

## int age1 = scanner.nextInt();

System.out.println();

## System.out.println ("Age " + emp1[i].age);

System.out.println();

## String empN2 = emp2.name.toUpperCase();

return empN1.compareTo(empN2);

};

## if (emp1.age < emp2.age)

return (-1);
else if (emp1.age > emp2.age)

return (1);

else

return (0);

};

return (-1);

return (1);

else

return (0);

};

## public static Emp[] sort (Emp emp1[]) throws IOException

System.out.println ();

## System.out.println ("Welcome to the Sorting Wizard ");

System.out.println ("How would you like to Sort the data (\n1 for Name\n2 for Age\n3
for Code)");

int choice;

choice = scanner.nextInt();

if (choice == 1)

Arrays.sort(emp1, Emp.SortName);
}

else if (choice == 2)

Arrays.sort(emp1, Emp.SortAge);

else if (choice == 3)

Arrays.sort(emp1, Emp.SortCode);

return emp1;

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

System.out.println
("/**********************************************************************/");

## System.out.println ("\tWelcome to the fictitious company's Emp Database ");

System.out.println
("/**********************************************************************/");

System.out.println ();

int choice,choice1;

int n, m = 0;

do

## System.out.println ("2.Diplay the Database");

System.out.println ("3.Exit");

choice = scanner.nextInt();

switch (choice)
{

case 1:

System.out.print ("Enter the number of Emps you you wish to enter the data for: ");

n = scanner.nextInt();

m = m + n;

emp = Arrays.copyOf(emp, m );

update(emp, n);

break;

case 2:

display (emp);

System.out.println();

System.out.print("Do you wish to sort the data as well? (yes-1 or no-0) ");

choice1 = scanner.nextInt();

if(choice1==1)

sort(emp);

## System.out.println ("Database has been sorted .. To view press 2");

else

System.out.println();

break;

default:

break;

}}

/*
Output :

## C:\Users\User\Desktop\Sem II>java Emp

/**********************************************************************/

## Welcome to the fictitious company's Emp Database

/**********************************************************************/

3.Exit

1 for Name

2 for Age

3 for Code

3.Exit

## 2.Diplay the Database

3.Exit

2
Do you wish to sort the data as well? (yes-1 or no-0) 1

1 for Name

2 for Age

3 for Code)

3.Exit

1 for Name

2 for Age

3 for Code)

## 2.Diplay the Database

3.Exit

Enter the number of Emps you you wish to enter the data for: 2

## Enter the Name Amit Kumar

Enter the unique code 557

3.Exit

*/

/*

## Name :Unnati Srivastava

College : Indraprastha College for Women

Section : B */

//Program 9 :Program to fit a linear line on list of observations. Also compute the mean spuare error of
fitting in each case.

import java.io.*;

import java.math.*;

class Linear

## public double mean(double x[], int n) throws IOException

double sum=0.0;

for(int i=0;i<n;i++)

sum=sum+x[i];

double mean=sum/n;

return (mean);

## public double mean(int x[], int n) throws IOException

double sum=0.0;

for(int i=0;i<n;i++)

sum=sum+x[i];

double mean=sum/n;

return (mean);

## double var=0.0, z=0.0, sum=0.0;

for(int i=0;i<n;i++)

sum=sum+(x[i]*x[i]);
var=((sum/n)-(mean(x,n)*mean(x,n)));

return (var);

## double var=0.0, sum=0.0;

for(int i=0;i<n;i++)

sum=sum+x[i]*y[i];

double cov=(sum/n)-(mean(x,n)*mean(y,n));

return (cov);

## public void line_eqn(int x[], double y[], int n) throws IOException

slope=cov(x,y,n)/var(x,n);

intercept=mean(y,n)-slope*mean(x,n);

## System.out.println(" Equation of the line is \n"+"Y = "+intercept+"+"+slope+"x");

public void mse(int x[], double y[], double y_est[], int n) throws IOException

## double mse, sum=0.0;

slope=cov(x,y,n)/var(x,n);

intercept=mean(y,n)-slope*mean(x,n);

for(int i=0;i<n;i++)

y_est[i]=intercept+slope*x[i];

System.out.println("\n");

## System.out.println("\n X\tY \tY^");

for(int i=0;i<n;i++)

{
System.out.println();

System.out.print(x[i]+"\t"+y[i]+"\t"+y_est[i]);

for(int i=0;i<n;i++)

sum=sum+((y[i]-y_est[i])*(y[i]-y_est[i]));

mse=sum/(n-1);

System.out.println("\nmse="+mse);

System.out.println();

class Line

## Linear obj=new Linear();

int n,per,x[];

double y[],y_est[];

String str,ch;

do

## System.out.println(" Enter the number of periods: ");

n=Integer.parseInt(str);

x=new int[n];

y=new double[n];

y_est=new double[n];
System.out.println("Enter the value of the first period: ");

x[0]=Integer.parseInt(str);

## System.out.println("Enter the interval between the two periods :");

x[0]=Integer.parseInt(str);

per=Integer.parseInt(str);

for(int i = 1;i<n;i++ )

x[i]=x[i-1]+per;

## System.out.println("Enter the observed values of time series data Y:");

for(int i=0;i<n;i++ )

y[i]=Double.parseDouble(str);

## System.out.println("Equation of the line to fit: y=ax+b, where x gives trend

values and \n y the respective forecasted values");

obj.line_eqn(x,y,n);

obj.mse(x,y,y_est,n);

## System.out.println("Do you wish to continue (Y/N)");

while(ch.equals("Y")||ch.equals("y"));

/*
Output :

## Enter the observed values of time series data Y:

10

Equation of the line to fit: y=ax+b, where x gives trend values and

## Equation of the line is

Y = 10.08+-0.18x

X Y Y^

6 10.0 9.0

11 7.0 8.1

16 8.0 7.2

21 4.0 6.300000000000001
26 7.0 5.4

mse=2.6750000000000003

*/

/*

## Name :Unnati Srivastava

College : Indraprastha College for Women

Section : B */

//Program 10 :Implement matrix class, Use methods for addition, subtraction, multiplication and
transpose.

import java.util.*;

int y = 1;

do

## System.out.println("Enter :\n1 : Addition\n2 : Subtraction\n3 : Multiplication\n4 :

int ch = sc.nextInt();

switch(ch)

case 1:

## System.out.print("\nEnter row size of matrix 1 :");

r1 = sc.nextInt();
System.out.print("\nEnter column size of matrix 1 :");

c1 = sc.nextInt();

## System.out.print("\nEnter row size of matrix 2 :");

r2 = sc.nextInt();

## System.out.print("\nEnter column size of matrix 2 :");

c2 = sc.nextInt();

## for ( j = 0 ; j < c1 ; j++ )

m1[i][j] = sc.nextInt();

## for ( j = 0 ; j < c2 ; j++ )

m2[i][j] = sc.nextInt();

## for ( j = 0 ; j <Math.max(c1,c2) ; j++ )

System.out.print(sum[i][j]+"\t");

System.out.println();

else

break;

case 2:

//SUBTRACTION

## System.out.print("\nEnter row size of matrix 1 :");

r1 = sc.nextInt();

## System.out.print("\nEnter column size of matrix 1 :");

c1 = sc.nextInt();

## System.out.print("\nEnter row size of matrix 2 :");

r2 = sc.nextInt();

## System.out.print("\nEnter column size of matrix 2 :");

c2 = sc.nextInt();

## for ( j = 0 ; j < c1 ; j++ )

m1[i][j] = sc.nextInt();

## System.out.println("Enter the elements of second matrix");

for ( i = 0 ; i< r2 ; i++ )

## for ( j = 0 ; j < c2 ; j++ )

m2[i][j] = sc.nextInt();

## for ( j = 0 ; j <Math.max(c1,c2) ; j++ )

System.out.print(sub[i][j]+"\t");

System.out.println();

else

break;

case 3:

//MULTIPLICATION

## System.out.print("\nEnter row size of matrix 1 :");

r1 = sc.nextInt();

## System.out.print("\nEnter column size of matrix 1 :");

c1 = sc.nextInt();
System.out.print("\nEnter row size of matrix 2 :");

r2 = sc.nextInt();

## System.out.print("\nEnter column size of matrix 2 :");

c2 = sc.nextInt();

## for ( j = 0 ; j < c1 ; j++ )

m1[i][j] = sc.nextInt();

## for ( j = 0 ; j < c2 ; j++ )

m2[i][j] = sc.nextInt();

if ( c1==r2 )

m2[k][j];

## for ( i = 0 ; i<Math.max(r1,r2) ; i++ )

{
for ( j = 0 ; j <Math.max(c1,c2) ; j++ )

System.out.print(mul[i][j]+"\t");

System.out.println();

else

break;

case 4:

## System.out.print("\nEnter row size of matrix :");

r1 = sc.nextInt();

## System.out.print("\nEnter column size of matrix :");

c1 = sc.nextInt();

## for ( j = 0 ; j < c1 ; j++ )

m1[i][j] = sc.nextInt();

System.out.println("Transpose of matrix:-");

## for ( j = 0 ; j < c1 ; j++ )

trans[j][i] = m1[i][j];

## for ( j = 0 ; j < r1 ; j++ )

System.out.print(trans[i][j]+"\t");
System.out.println();

break;

default :

## System.out.println("\nyou want to continue then press (1) : ");

y=sc.nextInt();

while(y==1);

/*

Output :

Enter :

2 : Subtraction

3 : Multiplication

4 : Transpose

## Enter column size of matrix 1 :3

Enter row size of matrix 2 :3

## C:\Users\User\Desktop\Sem II>java java10

Enter :

2 : Subtraction

3 : Multiplication

4 : Transpose

234

526
481

121

552

344

3 5 5

10 7 8

7 12 5

## you want to continue then press (1) :

Enter :

2 : Subtraction

3 : Multiplication

4 : Transpose

35
64

28

03

1 -3

6 1

## you want to continue then press (1) :

Enter :

2 : Subtraction

3 : Multiplication

4 : Transpose

## Enter the elements of first matrix

325

352

162
Enter the elements of second matrix

634

247

312

37 22 36

34 31 51

24 29 50

## you want to continue then press (1) :

Enter :

2 : Subtraction

3 : Multiplication

4 : Transpose

## Enter the elements of matrix

123

456

789

Transpose of matrix:-

1 4 7

2 5 8
3 6 9

*/

/*

## Name :Unnati Srivastava

College : Indraprastha College for Women

Section : B */

/*

## Program 11 :Implement a menu driven Statistical calculator for the following

• Mean

• Harmonic Mean

• Geometric Mean

• Variance

• Covariance

• Regression coefficient

*/

import java.util.*;

class java11

int n ,i ;

double mul = 1;

int y = 1;

while(y == 1)
{

## System.out.println("Enter : \n1 : Mean\n2 : Harmonic Mean\n3 : Geometrical Mean\n4 : Variance\n5 :

Co-Variance\n6 : Regression Coefficient\nEnter your choice : ");

int ch = sc.nextInt();

switch (ch)

case 1 :

System.out.println("Enter : \n1 : For Individual Data Series\n2 : For Discrete Data Series\n3 : For
Continuous Data Series\nEnter your choice : ");

switch (ch1)

case 1 :

## System.out.println("Enter no. of elements : ");

n = sc.nextInt();

## for(i = 0 ; i< n ; i++)

series[i] = sc.nextInt();

break;

case 2 :

## System.out.println("How many values the series have : ");

n = sc.nextInt();

## for(i = 0 ; i< n ; i++)

{
series[i] = sc.nextInt();

## for(i = 0 ; i< n ; i++)

freq[i] = sc.nextInt();

break;

case 3 :

## System.out.println("How many values the series have : ");

n = sc.nextInt();

## for(i = 0 ; i< n ; i++)

CI[i] = sc.next();

mp[i] = (0.5)*(Integer.parseInt(CI[i].substring(0,1)) +
Integer.parseInt(CI[i].substring(2)));

## for(i = 0 ; i< n ; i++)

freq[i] = sc.nextInt();

}
for(i = 0 ; i< n ; i++)

break;

break;

case 2 :

## System.out.println("Enter no. of elements : ");

n = sc.nextInt();

## for(i = 0 ; i< n ; i++)

series[i] = sc.nextInt();

break;

case 3 :

## System.out.println("Enter no. of elements : ");

n = sc.nextInt();

## for(i = 0 ; i< n ; i++)

series[i] = sc.nextInt();

mul = mul*series[i];

break;

case 4 :

## System.out.println("Enter no. of elements : ");

n = sc.nextInt();

## for(i = 0 ; i< n ; i++)

series[i] = sc.nextInt();

break;

case 5 :

## System.out.println("Enter no. of elements : ");

n = sc.nextInt();

## for(i = 0 ; i< n ; i++)

series[i] = sc.nextInt();

## for(i = 0 ; i< n ; i++)

series1[i] = sc.nextInt();
sum1 = sum1 + series1[i];

(n-1) );

break;

case 6 :

## System.out.println("Enter no. of elements : ");

n = sc.nextInt();

## for(i = 0 ; i< n ; i++)

series[i] = sc.nextInt();

## for(i = 0 ; i< n ; i++)

series1[i] = sc.nextInt();

}

## System.out.println("Regression Co-Efficient = " + (n*sum2 - sum*sum1)/(Math.pow((n*sqsum -

Math.pow(sum,2))*(n*sqsum1 - Math.pow(sum1,2)),0.5)) );

break;

default :

## System.out.println("Do you want to try again, press(y/n) : ");

y = sc.nextInt();

/*

Output :

## C:\Users\User\Desktop\Sem II>java java11

Enter :

1 : Mean

2 : Harmonic Mean

3 : Geometrical Mean

4 : Variance

5 : Co-Variance

6 : Regression Coefficient

1
Enter :

23726

Mean = 4.0

## To try again, press(1) :

Enter :

1 : Mean

2 : Harmonic Mean

3 : Geometrical Mean

4 : Variance

5 : Co-Variance

6 : Regression Coefficient

Enter :

4

2691

8216

Mean = 15.75

## To try again, press(1) :

Enter :

1 : Mean

2 : Harmonic Mean

3 : Geometrical Mean

4 : Variance

5 : Co-Variance

6 : Regression Coefficient

Enter :

5
8

Mean = -10.0

## To try again, press(1) :

Enter :

1 : Mean

2 : Harmonic Mean

3 : Geometrical Mean

4 : Variance

5 : Co-Variance

6 : Regression Coefficient

2 5 7 9 11

## To try again, press(1) :

Enter :

1 : Mean

2 : Harmonic Mean

3 : Geometrical Mean

4 : Variance

5 : Co-Variance

6 : Regression Coefficient

3

2345

## To try again, press(1) :

Enter :

1 : Mean

2 : Harmonic Mean

3 : Geometrical Mean

4 : Variance

5 : Co-Variance

6 : Regression Coefficient

3687

Variance = 59.75

## To try again, press(1) :

Enter :

1 : Mean

2 : Harmonic Mean

3 : Geometrical Mean

4 : Variance
5 : Co-Variance

6 : Regression Coefficient

3456

6243

## To try again, press(1) :

Enter :

1 : Mean

2 : Harmonic Mean

3 : Geometrical Mean

4 : Variance

5 : Co-Variance

6 : Regression Coefficient

3456

## Enter the values of Y :

6243
Regression Co-Efficient = NaN

## To try again, press(1) :

Enter :

1 : Mean

2 : Harmonic Mean

3 : Geometrical Mean

4 : Variance

5 : Co-Variance

6 : Regression Coefficient

*/

/*

## Name :Unnati Srivastava

College : Indraprastha College for Women

Section : B */

//Program 12 :Program to fit poisson distribution and find the mean square error of fitting.

import java.io.*;

import java.math.*;

class Calculate

double total;

total =0.0;

## double sum =0.0;

double mean;

for(int i=0;i<n;i++)

## sum = sum +(i*x[i]);

total = total+x[i];

## System.out.println("The total is "+total);

mean = (sum/total);

return mean;

## double sum = 0.0;

int temp;

double diff;
double sse= 0.0, error, mse = 0.0;

int p = 1;

p=1;

## for(int j=1; j<i+1; j++)

p = p*j;

poi[i] = (Math.exp(-mean)*(Math.pow(mean,i)))/p;

ef[i] = total*poi[i];

for(int i=0;i<n-1;i++)

temp = (int)(ef[i]);

diff = (ef[i]-temp);

ef[i] = temp+1;

else

ef[i] = temp;

## sum =sum + ef[i];

System.out.println(i+"\t\t\t"+x[i]+"\t\t\t"+ef[i]);

## ef[n-1] = total - sum;

System.out.println(n-1+"\t\t\t"+x[n-1]+"\t\t\t"+ef[n-1]);

## error = ef[i] - x[i];

sse = sse + Math.pow(error,2);

mse = sse/n;

class Poi

String str,ch;

int n;

double mean;

int x[];

do

## Calculate calc = new Calculate();

System.out.println("/*********************************************/");

## System.out.println("\t\tThe Poisson Distribution:");

System.out.println("/*********************************************/");
System.out.println(" Large no. of occurence of an event\n\t\t\t with
avery low probability of occurence");

## System.out.println("\nEnter the total number of occurences of an event");

n = Integer.parseInt(str);

x = new int[n+1];

## System.out.println(" Enter the frequency of the respective occurences");

for(int i=0; i<n+1; i++)

x[i] = Integer.parseInt(str);

mean = calc.mean(x,n+1);

## System.out.println(" Fitting of the poisson data");

calc.fitting(x,n+1,mean);

## System.out.println(" Type Yes or No");

while(ch.equals("Yes")||ch.equals("yes"));

System.out.println(" bbye");

/*

Output :

## C:\Users\User\Desktop\Sem II>java Poi

/*******************************************************/

## The Poisson Distribution:

/*******************************************************/

5

0 4 2.0

1 3 5.0

2 4 6.0

3 6 5.0

4 2 3.0

5 5 3.0

Type Yes or No

No

*/

/*

## Name :Unnati Srivastava

College : Indraprastha College for Women

Section : B */

//Program 13 :Write a menu driven program for 4 EOQ models using inheritance. Model 1 should be the
base class.

import java.util.*;

import java.io.*;

import java.lang.*;

int choice;

String ch;

## Epqs o4=new Epqs();

do

System.out.println("\n\t\t\tInventory System\n");

allowed");

## System.out.println("4.Generalised Lot size model\n");

choice=scanner.nextInt();

switch(choice)

case 1:
o1.input();

o1.calq();

o1.display();

break;

case 2:

o2.input();

o2.input2();

o2.calepq();

o2.display();

break;

case 3:

o3.input();

o3.input3();

o3.caleoqs();

o3.display();

break;

case 4:

o4.input();

o4.input4();

o4.calepqs();

o4.display();

break;

default:

## System.out.println("\nType Yes or No");

ch=scanner1.nextLine();

}
while(ch.equals("Yes")||ch.equals("yes"));

class Eoq

## System.out.println("Enter Ordering cost per order:");

a=in.nextDouble();

## System.out.println("Enter inventory carrying charge per unit per unit time:");

ic=in.nextDouble();

## System.out.println("Enter annual demand:");

l=in.nextDouble();

q=(2*a*l)/(ic);

q=Math.sqrt(q);

## class Epq extends Eoq

{
Scanner in2 = new Scanner(System.in);

double s;

## System.out.print("\nEnter annual supply:");

s=in2.nextDouble();

## public void calepq()

q=((2*a*l/ic)*(s/(s-l)));

q=Math.sqrt(q);

double sc;

## System.out.print("\nEnter stock cost per unit per unit time:");

sc=in3.nextDouble();

## public void caleoqs()

q=((2*a*l/ic)*((ic+sc)/sc));

q=Math.sqrt(q);

{

double sc,s;

## System.out.print("\nEnter annual supply:");

s=in4.nextDouble();

## System.out.print("\nEnter stock cost per unit per unit time:");

sc=in4.nextDouble();

## public void calepqs()

q=((2*a*l/ic)*(s/(s-l))*((ic+sc)/sc));

q=Math.sqrt(q);

/*

Output :

## C:\Users\User\Desktop\Sem II>java Eoqinh

Inventory System

Select a command:

1.EOQ

2.EPQ

## 4.Generalised Lot size model

1
Enter Ordering cost per order:

500

1000

## Do you want to continue

Type Yes or No

yes

Inventory System

Select a command:

1.EOQ

2.EPQ

100

5000

## Do you want to continue

Type Yes or No

yes
Inventory System

Select a command:

1.EOQ

2.EPQ

1000

10000

## Do you want to continue

Type Yes or No

yes

Inventory System

Select a command:

1.EOQ

2.EPQ

90

6

780

Type Yes or No

No

*/

/*

## Name :Unnati Srivastava

College : Indraprastha College for Women

Section : B */

//Program 14 :Write a menu driven program to implement M|M|1 , M|M|C and M|M|infinity queuing
models

import java.io.*;

import java.util.*;

class design

float po,pn,r,l,lq,w,wq,t,c,r1=0,r2=0;

int n;

design()

n=0;

void input()

## System.out.println("enter the number of states:");

n=scanner.nextInt();

float fact(int x)

if(x<=1)

return (1);

else

return (x*(fact(x-1)));

## void MM1(float a,float s)

{
r=a/s;

System.out.println("r="+r);

po=1-r;

System.out.println("system is idle:"+po);

## if(r<1 && n>=1)

pn=(float) (po*Math.pow(r,n));

System.out.println("\nqueuelength:="+pn);

else

System.out.println("cannot compute:");

System.out.println("measure of effectivess:");

l= r/(1-r);

lq=(float) (Math.pow(r,2)/(1-r));

w=r/(a*(1-r));

wq=(float) (Math.pow(r,2)/(a*(1-r)));

System.out.println("\nl="+l+"\nlq="+lq+"\nw="+w+"\nwq="+wq);

## System.out.println("enter the number of coustomers:");

c=g.nextInt();

r=a/s;

System.out.println("r="+r);

t=r/c;

System.out.println("cu="+t);
if(t<1)

for(int i=0;i<=c-1;i++)

r1=(float)(r1+Math.pow(r,i)/fact(i));

System.out.println("r1="+r1);

r2=(float)(Math.pow(r,c)/(fact((int) c)*(1-(r/c))));

System.out.println("r2="+r2);

po=1/(r1+r2);

System.out.println("System is idle="+po);

if(n<c)

else if(n>=c)

## pn=(float) (Math.pow(r,n)*po/(fact((int) c)*Math.pow(c,n-c)));

else

System.out.println("cannot compute:");

System.out.println("queue length="+pn);

System.out.println("measure of effectivness:");

## w=(float) ((1/s)+Math.pow(r,c)*po/(fact((int) c)*Math.pow((1-t),2)*(c*s)));

wq=(float) (Math.pow(r,c)*po/(fact((int) c)*Math.pow((1-t),2)*(c*s)));

System.out.println("\nl="+l+"\nlq="+lq+"\nw="+w+"\nwq="+wq);

## void MM(float a,float s)

r=a/s;

System.out.println("\nr="+r);

if(n>=0)

po=(float) (Math.exp(-r));

System.out.println("\nSystem is idle="+po);

## pn=(float) (Math.pow(r,n)*po/fact((int) n));

System.out.println("\nqueue length="+pn);

System.out.println("measure of effectivness:");

l=a/s;

lq=l-r;

w=1/s;

wq=lq/a;

System.out.println("\nl="+l+"\nlq="+lq+"\nw="+w+"\nwq="+wq);

class Queue

## public static void main(String [] args)

design d;

d = new design();

int ch;

String check;
float a,s;

a=k.nextFloat();

s=k.nextFloat();

d.input();

do

## System.out.println("enter 3.model MM0 ");

ch= in.nextInt();

switch(ch)

case 1:

d.MM1(a,s);

break;

case 2:

d.MMC(a,s);

break;

}
case 3:

d.MM(a,s);

break;

default:

## System.out.println("do u want to continue(yes/no)");

check=ins.nextLine();

while(check.equals("yes")||check.equals("Yes"));

/*

Output :

.5

.6

## enter 3.model MM0

r=0.8333333
System is idle=0.4345982

queue length=2.0214728E-4

measure of effectivness:

l=0.8333333

lq=0.0

w=1.6666666

wq=0.0

do u want to continue(yes/no)

yes

## enter 3.model MM0

r=0.8333333

system is idle:0.16666669

queue length:=0.055816326

measure of effectivess:

l=4.9999995

lq=4.166666

w=9.999999

wq=8.333332

do u want to continue(yes/no)

yes

## enter the number of coustomers:

r=0.8333333

cu=0.27777776

r1=2.1805553

r2=0.13354701

System is idle=0.432133

queue length=8.933361E-4

measure of effectivness:

l=0.8555295

lq=0.022196177

w=1.711059

wq=0.04439236

do u want to continue(yes/no)

no

*/