Develop an application for user defined package and also import that package in different program and show functionality .
Problem Statement :
Develop a
mathematical package for Statistical operations like Mean, Median, Average,
Standard deviation.
Create a sub package in the math package -convert. In “convert”
package provide classes to convert decimal to octal, binary, hex and vice-versa. Develop application program to use this package, and build executable jar file of it.
Introduction:
A java package is
a group of similar types of classes, interfaces and sub-packages. Package in
java can be categorized in two form, built-in package and user-defined package.
There are many built-in packages such as java, lang, awt, javax, swing, net,
io, util, sql etc.
Advantage of Java Package
1)
Java package is used to categorize the classes and interfaces so that they can
be easily maintained.
2) Java package provides
access protection.
3) Java package removes
naming collision.
Syntax to Compile
package program
javac -d . directory javafilename
Program
Package Creation Program
package mathematical;
import java.util.*;
import java.io.*;
public class math
{
int a,b,c;
float mean,median;
Scanner sc=new Scanner(System.in);
public void stat()
{
System.out.println("\nEnter the value for a=");
a=sc.nextInt();
System.out.println("\nEnter the value for b=");
b=sc.nextInt();
System.out.println("\nEnter the value for c=");
c=sc.nextInt();
}
public void cal()
{
mean=(a+b+c)/3;
median=(3+1)/2;
}
public void show()
{
System.out.println("\n Mean="+mean+"\n Median="+median);
}
}
Pakckage program:
import Mathematical.maths;import java.util.*;import java.io.*;class mathapp{public static void main(String args[]){int l,a[];a = new int[10];maths pm = new maths();Scanner in = new Scanner(System.in);System.out.println("\n\t Enter the length of array : ");l = in.nextInt();System.out.println("\n\t Enter the Array elements : ");for(int i=0;i<l;i++){a[i] = in.nextInt();}double m;m = pm.mean(a,l);System.out.println("\n\t Mean is : "+m);int md = pm.median(a,l);System.out.println("\n\t Median is : "+md);System.out.println("\n\t Enter the obtained Marks : ");int om = in.nextInt();System.out.println("\n\t Enter the Total Marks : ");int tm = in.nextInt();m = pm.avg(om,tm);System.out.println("\n\t Average is : "+m);}}