11. Make the class Cartesian Point, belong to a package called edu. gtu....
download link:http://www.megaupload.com/?d=1CUR491F
12. Update the classes Triangle and Rectangle, to throw an exception...
Shared By : Your Name (College - Place ) Show/Hide Program
Share this program...
Send it to gtumca@gmail.com
with your Name - College name..
and share what you want ... at same mail id...
Thanx in advance...
Be connected...
D_i_Z
13. Define a class called Polygon Manager, which manages a...
import java.io.*;
interface input
{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
}
abstract class polygon_manager implements input
{
int x[];
int i;
int size;
int y[];
polygon_manager()
{
}
polygon_manager(int xy)
{
x=new int[xy];
y=new int[xy];
size=xy;
i=0;
}
abstract void display();
}
class triangle extends polygon_manager
{
triangle()
{
}
triangle(int xy)
{
super(xy);
}
void add()throws IOException
{
System.out.println("\nEnter the Three Co-Ordinates :");
for(i=0;i<3;i++)
{
System.out.println("Enter the x"+(i+1)+" And Y"+(i+1)+"=->");
x[i]=Integer.parseInt(br.readLine());
y[i]=Integer.parseInt(br.readLine());
}
}
void display()
{
System.out.print("\n\tTriangle :- {");
for(i=0;i<3;i++)
{
System.out.print("("+x[i]+","+y[i]+")");
}
System.out.print("}");
}
}
class rectangle extends polygon_manager
{
rectangle()
{
}
rectangle(int xy)
{
super(xy);
}
void add()throws IOException
{
System.out.println("\nEnter the four Co-Ordinates :");
for(i=0;i<4;i++)
{
System.out.println("Enter the x"+(i+1)+" And Y"+(i+1)+"=->");
x[i]=Integer.parseInt(br.readLine());
y[i]=Integer.parseInt(br.readLine());
}
}
void display()
{
System.out.print("\n\tRectangle :- {");
for(i=0;i<4;i++)
{
System.out.print("("+x[i]+","+y[i]+")");
}
System.out.print("}");
}
}
class pantagon extends polygon_manager
{
pantagon()
{
}
pantagon(int xy)
{
super(xy);
}
void add()throws IOException
{
System.out.println("\nEnter the five Co-Ordinates :");
for(i=0;i<5;i++)
{
System.out.println("Enter the x"+(i+1)+" And Y"+(i+1)+"=->");
x[i]=Integer.parseInt(br.readLine());
y[i]=Integer.parseInt(br.readLine());
}
}
void display()
{
System.out.print("\n\tPantagon :- {");
for(i=0;i<5;i++)
{
System.out.print("("+x[i]+","+y[i]+")");
}
System.out.print("}");
}
}
class hexagon extends polygon_manager
{
hexagon()
{
}
hexagon(int xy)
{
super(xy);
}
void add()throws IOException
{
System.out.println("\nEnter the six Co-Ordinates :");
for(i=0;i<6;i++)
{
System.out.println("Enter the x"+(i+1)+" And Y"+(i+1)+"=->");
x[i]=Integer.parseInt(br.readLine());
y[i]=Integer.parseInt(br.readLine());
}
}
void display()
{
System.out.print("\n\tHexagon :- {");
for(i=0;i<6;i++)
{
System.out.print("("+x[i]+","+y[i]+")");
}
System.out.print("}");
}
}
class octagon extends polygon_manager
{
octagon()
{
}
octagon(int xy)
{
super(xy);
}
void add()throws IOException
{
System.out.println("\nEnter the Eight Co-Ordinates :");
for(i=0;i<8;i++)
{
System.out.println("Enter the x"+(i+1)+" And Y"+(i+1)+"=->");
x[i]=Integer.parseInt(br.readLine());
System.out.println();
y[i]=Integer.parseInt(br.readLine());
}
}
void display()
{
System.out.print("\n\tOctagon :- {");
for(i=0;i<8;i++)
{
System.out.print("("+x[i]+","+y[i]+")");
}
System.out.print("}");
}
}
class polygon implements input
{
public static void main(String arg[])throws IOException
{
int ch,len=0,j=0,pos;
polygon_manager p[]=new polygon_manager[100];
while(true)
{
System.out.println("\nFunction Of Polygon...........");
System.out.println("1.Add");
System.out.println("2.Remove");
System.out.println("3.Display");
System.out.println("4.Exit");
System.out.println("Enter Your Choice =->");
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
menuformat();
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
triangle t=new triangle(3);
t.add();
p[len]=t;
len++;
break;
case 2:
rectangle r=new rectangle(4);
r.add();
p[len]=r;
len++;
break;
case 3:
pantagon pa=new pantagon(5);
pa.add();
p[len]=pa;
len++;
break;
case 4:
hexagon h=new hexagon(6);
h.add();
p[len]=h;
len++;
break;
case 5:
octagon o=new octagon(8);
o.add();
p[len]=o;
len++;
break;
case 6:
break;
default :
System.out.println("\nPlz Enter 1 To 6 .................");
break;
}
break;
case 2 :
if(len<1)
{
System.out.println("\nPolygon does not exists............");
break;
}
System.out.println("\nList Of Polygon Is ..............");
for(j=0;j<len;j++)
{
p[j].display();
}
menuformat();
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
System.out.println("\nEnter The Position =->");
pos=Integer.parseInt(br.readLine());
if(pos<len)
{
if(p[pos-1].size==3)
{
p[j]=null;
}
else
{
System.out.println("\nInvalid Selection................");
}
}
else
{
System.out.println("\nInvalid Position................");
}
break;
case 2:
System.out.println("\nEnter The Position =->");
pos=Integer.parseInt(br.readLine());
if(pos<len)
{
if(p[pos-1].size==4)
{
p[j]=null;
}
else
{
System.out.println("\nInvalid Selection................");
}
}
else
{
System.out.println("\nInvalid Position................");
}
break;
case 3:
System.out.println("\nEnter The Position =->");
pos=Integer.parseInt(br.readLine());
if(pos<len)
{
if(p[pos-1].size==5)
{
p[j]=null;
}
else
{
System.out.println("\nInvalid Selection................");
}
}
else
{
System.out.println("\nInvalid Position................");
}
break;
case 4:
System.out.println("\nEnter The Position =->");
pos=Integer.parseInt(br.readLine());
if(pos<len)
{
if(p[pos-1].size==6)
{
p[j]=null;
}
else
{
System.out.println("\nInvalid Selection................");
}
}
else
{
System.out.println("\nInvalid Position................");
}
break;
case 5:
System.out.println("\nEnter The Position =->");
pos=Integer.parseInt(br.readLine());
if(pos<len)
{
if(p[pos-1].size==8)
{
p[j]=null;
}
else
{
System.out.println("\nInvalid Selection................");
}
}
else
{
System.out.println("\nInvalid Position................");
}
break;
case 6:
break;
default :
System.out.println("\nPlz Enter 1 To 6 .................");
break;
}
break;
case 3 :
System.out.println("\nList Of Polygon Is ..............");
for(j=0;j<len;j++)
{
p[j].display();
}
break;
case 4 :
return ;
}
}
}
public static void menuformat()
{
System.out.println("\n\nSelect Any Polygon..................");
System.out.println("1.Tringle");
System.out.println("2.Rectangle");
System.out.println("3.Pantagon");
System.out.println("4.Hexagon");
System.out.println("5.Octagon");
System.out.println("6.Back To Main Menu...........");
System.out.println("Enter Your Choice =->");
}
}
14. Define a class called Statistical Data which manages...
Shared By : Jani Anand (SRIMCA-Bardoli) Show/Hide Program
Download link: http://www.megaupload.com/?d=Q6F6X7XZ
Shared By : Sonam Patel(SRIMCA-Tarsadi ) Show/Hide Program
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
class StatisticalData
{
int v[],N;
String vname;
public StatisticalData()
{
N=0;
vname="";
}
public void setData()
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i;
System.out.printf("How many values You want to Enter? ");
try{
N=Integer.parseInt(br.readLine());
}
catch(IOException e)
{
System.out.println("Error while Reading from console");
}
v=new int[N];
System.out.printf("Enter variable Name and its values: ");
try{
vname = br.readLine();
for(i=0;i<N;i++)
{
v[i]=Integer.parseInt(br.readLine());
}
}
catch(IOException e)
{
System.out.println("Error while Reading from console");
}
System.out.println("Variable Name: " + vname);
System.out.print("Your Data are: ");
for(i=0;i<N;i++)
{
System.out.print(" " + v[i]);
}
System.out.println();
}
public double Mean()
{
double m=0;
int i;
for(i=0;i<N;i++)
{
m=m+v[i];
}
m=m/N;
return m;
}
public double Median()
{
double m=0;
int temp[]=new int[N];
int i,j,x,n=N-1;
for(i=0;i<N;i++)
{
temp[i]=v[i];
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(temp[j] > temp[j+1])
{
x=temp[j];
temp[j]=temp[j+1];
temp[j+1]=x;
}
}
}
if(N%2 == 0)
{
x=N/2;
m=temp[x];
x--;
m=m+temp[x];
m=m/2;
}
else
{
x=N/2;
System.out.println("IND: " + x);
m=temp[x];
}
return m;
}
public double Mode()
{ double M,x,m;
M=Median();
x=Mean();
m=3*M-2*x;
return m;
}
public double Variance()
{
double var=0,m;
int i;
m=Mean();
for(i=0;i<N;i++)
{
var=var+(v[i]-m)*(v[i]-m);
}
var=var/(N-1);
return var;
}
public double StdDev()
{
double sd;
int i;
sd=Variance();
sd=Math.sqrt(sd);
return sd;
}
public double Percentile(int p)
{
if(p==0)
return 0.0;
double P,n;
int temp[]=new int[N];
int i,j,x;
for(i=0;i<N;i++)
{
temp[i]=v[i];
}
for(i=0;i<N-1;i++)
{
for(j=0;j<N-i-1;j++)
{
if(temp[j] > temp[j+1])
{
x=temp[j];
temp[j]=temp[j+1];
temp[j+1]=x;
}
}
}
if(p==100)
return temp[N-1];
else
{
P=p;
n=N;
n=P*n/100;
P=Math.ceil(n);
if(P-n > 0)
{
i=(int)P;
P=temp[i-1];
}
else
{
i=(int)P;
P=temp[i]+temp[i-1];
P=P/2;
}
return P;
}
}
}
class P14
{
public static void main(String args[])
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StatisticalData s=new StatisticalData();
int ch=10,ch1=1,p=-1;
double result,Q3;
s.setData();
do
{
do
{
System.out.println("1. Set Data");
System.out.println("2. Mean");
System.out.println("3. Median");
System.out.println("4. Mode");
System.out.println("5. Variance");
System.out.println("6. Standard Deviation");
System.out.println("7. Percentile (between 0 - 100)");
System.out.println("8. Quartile (between 1 - 3)");
System.out.println("9. Interquartile Range");
System.out.println("10. Exit");
System.out.print("Enter Your Choice: ");
try{
ch=Integer.parseInt(br.readLine());
}
catch(IOException e)
{
System.out.println("Error while Reading from console");
}
}while(ch<1 || ch>10);
switch(ch)
{
case 1:
s.setData();
break;
case 2:
result=s.Mean();
System.out.println("Mean: " + result);
break;
case 3:
result=s.Median();
System.out.println("Median: " + result);
break;
case 4:
result=s.Mode();
System.out.println("Mode: " + result);
break;
case 5:
result=s.Variance();
System.out.println("Variance: " + result);
break;
case 6:
result=s.StdDev();
System.out.println("Standard Deviation: " + result);
break;
case 7:
do
{
System.out.print("Which Percentile you want to calculate? ");
try{
p=Integer.parseInt(br.readLine());
}
catch(IOException e)
{
System.out.println("Error while Reading from console");
}
}while(p<0 || p>100);
result=s.Percentile(p);
System.out.println("Percentile: " + result);
break;
case 8:
do
{
System.out.println("1. First ");
System.out.println("2. Second ");
System.out.println("3. Third ");
System.out.print("Enter Your Choice: ");
try{
ch1=Integer.parseInt(br.readLine());
}
catch(IOException e)
{
System.out.println("Error while Reading from console");
}
}while(ch1<1 || ch1>3);
switch(ch1)
{
case 1:
result=s.Percentile(25);
System.out.println("First Quartile: " + result);
break;
case 2:
result=s.Percentile(50);
System.out.println("Second Quartile: " + result);
break;
case 3:
result=s.Percentile(75);
System.out.println("Third Quartile: " + result);
}
break;
case 9:
Q3=s.Percentile(75);
result=s.Percentile(25);
result=Q3-result;
System.out.println("Inter Quartile Range: " + result);
}
}while(ch != 10);
}
}
Shared By : Hardikgiri Goswami (Indus Institute of Technology ) Show/Hide Program
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication4;
import java.io.*;
class p14
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StatisticalData s=new StatisticalData();
int ch=1;
while(ch!=0)
{
/*float f1=2234.34534427f;
System.out.format("%1$.2f",f1);*/
System.out.println("\n\n\n\n\n\nMain Menu");
System.out.println("1. Insert Mark");
System.out.println("2. Mean");
System.out.println("3. Median");
System.out.println("4. Mode");
System.out.println("5. Variance");
System.out.println("6. Standard Deviation");
System.out.println("7. Specified Percentile");
System.out.println("8. Specified Quarlite");
System.out.println("9. Interquartile Range");
System.out.println("0. Exit");
System.out.print("Enter your choice :");
try
{
ch=Integer.parseInt(br.readLine());
}
catch(NumberFormatException nfx)
{
System.out.println("You can not enter the string.... OR can not leave it blank.....");
ch=13;
}
if(s.get_size()==0 && ch!=1)
{
if(ch>10)
{
System.out.println("System can't recognize your choice, re-enter your selection....");
}
else if( ch != 0)
{
System.out.println("Enter the mark of student first.....");
}
}
else
{
switch(ch)
{
case 1:
String ch1="Y";
while(ch1.compareToIgnoreCase("N")!=0)
{
if(ch1.equalsIgnoreCase("Y") || ch1.equalsIgnoreCase("N"))
{
s.add();
}
else
{
System.out.println("Enter Y (for Yes) \nEnter N (for No)... Otherwise System can't recognize....");
}
System.out.print("Want to add more ? (Y/N) :");
ch1=br.readLine();
}
break;
case 2:
System.out.println("Mean : "+s.mean());
break;
case 3:
System.out.println("Median : "+s.median());
break;
case 4:
System.out.println("Mode : "+s.mode());
break;
case 5:
System.out.println("Variance : "+s.variance());
break;
case 6:
System.out.println("Standard Deviation : "+s.standard_deviation());
break;
case 7:
System.out.println("Enter value for Specified Percentile (0-100) :");
int p=Integer.parseInt(br.readLine());
if( p > 100 || p < 0 )
{
System.out.println("Enter between 0 - 100 .....");
}
else
{
System.out.println("Specified Percentile for intput " + p + " is : "+s.specified_percentile(p));
}
break;
case 8:
System.out.println("Enter Value for Specified Quarlite (1-3) :");
int q=Integer.parseInt(br.readLine());
if( q > 3 || q < 1)
{
System.out.println("Enter between 1 - 3 ......");
}
else
{
System.out.println("Specified Quarlite for input " + q + " is : "+s.specified_quertile(q));
}
break;
case 9:
System.out.println("Interquartile Range : "+ s.interquarlite_rang());
break;
case 10:
s.display();
break;
case 13:
break;
case 0:
break;
default:
System.out.println("System can't recognize your choice, re-enter your selection....");
break;
}
}
}
}
}
class StatisticalData
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int marks[];
int n;
StatisticalData()
{
marks=new int[60];
n=0;
}
void add() throws IOException
{
if(n==60)
{
System.out.println("There is 60 student in the class...");
System.out.println("You can't enter any more marks.....");
}
else
{
System.out.print("Enter Mark of Student : "+(n+1)+" : ");
try
{
int temp=Integer.parseInt(br.readLine());
if(temp>100 || temp<0)
{
System.out.println("Marks should be in range between 0 - 100...");
add();
}
else
{
marks[n]=temp;
n++;
}
}
catch(NumberFormatException nfe)
{
System.out.println("Marks can't be the String..... OR can not leave it blank.....");
add();
}
}
}
float mean()
{
float sum=0;
for(int i=0;i<n;i++)
{
sum+=marks[i];
}
return (sum/(n*1.0f));
}
float median()
{
sort();
float med=0;
int tmp=(n+1)/2;
if(n%2==0)
{
med=(marks[tmp-1]+marks[tmp])/2.0f;
}
else
{
med=marks[tmp];
}
return med;
}
int mode()
{
int m=0;
int count[]=new int[n];
for(int i=0;i<n;i++)
{
count[i]=0;
for(int j=0;j<n;j++)
{
if(i!=j)
{
if(marks[i]==marks[j])
{
count[i]++;
}
}
}
}
int temp=count[0];
int temp1=-1;
for(int k=0;k<n;k++)
{
if(count[k]>temp)
{
temp=count[k];
temp1=k;
System.out.println(temp1);
}
}
if(temp1==-1)
{
//f m=(2*median())+(3*mean());
}
else
{
m=marks[temp1];
}
return m;
}
float variance()
{
float mean=mean();
float sum=0;
for(int i=0;i<n;i++)
{
System.out.println((marks[i]-mean)+" "+((marks[i]-mean)*(marks[i]-mean)));
sum+=(marks[i]-mean)*(marks[i]-mean);
}
return (sum/((n-1)*1.0f));
}
float standard_deviation()
{
float variance = variance();
return ((float)(Math.sqrt(variance)));
}
int specified_percentile(int nth)
{
sort();
int i=(int)Math.ceil(((nth*n)/100.0f));
return marks[i-1];
}
int specified_quertile(int nth)
{
int i=(int)Math.ceil(((nth*(n+1))/4.0f));
return marks[i-1];
}
int interquarlite_rang()
{
return (specified_quertile(3)-specified_quertile(1));
}
void sort()
{
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(marks[i]>marks[j])
{
int temp=marks[i];
marks[i]=marks[j];
marks[j]=temp;
}
}
}
}
void display()
{
for(int i=0;i<n;i++)
{
System.out.println("Student "+(i+1)+" : "+marks[i]);
}
}
int get_size()
{
return n;
}
}
15. Update the class Statistical Data, and define a method...
Shared By : Prof.Swati Patel (SSIT Gandhinagar) Show/Hide Program
import java.util.*;
import java.io.*;
class StatisticalData
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int marks[];
int n;
StatisticalData(){
marks=new int[60];
n=0;
}
void add()throws IOException{
if(n==60) {
System.out.println("There is 60 student in the class...");
System.out.println("You can't enter any more marks.....");
}
else{
System.out.print("Enter Mark of Student : "+(n+1)+" : ");
try{
int temp=Integer.parseInt(br.readLine());
if(temp>100 || temp<0) {
System.out.println("Marks should be in range between 0 - 100...");
add();
}
else{
marks[n]=temp;
n++;
}
}
catch(NumberFormatException nfe) {
System.out.println("Marks can't be the String..... OR can not leave it blank.....");
add();
}
}
}
float mean() {
display();
float sum=0;
for(int i=0;i<n;i++){
sum+=marks[i];
}
return (sum/(n*1.0f));
}
float median(){
sort();
display();
float med=0;
int tmp=(n+1)/2;
if(n%2==0) {
med=(marks[tmp-1]+marks[tmp])/2.0f;
}
else {
med=marks[tmp-1];
}
return med;
}
void mode(){
display();
float m=0.0f;
int count[]=new int[n];
for(int i=0;i<n;i++){
count[i]=1;
for(int j=i+1;j<n;j++){
if(marks[i]==marks[j]) {
count[i]++;
}
}
}
int temp=1;
int temp1=-1;
for(int k=0;k<n;k++){
if(count[k]>temp) {
temp=count[k];
temp1=k;
}
}
System.out.println("Mode is/are .....");
if(temp1==-1) {
m=(3.0f*median())-(2.0f*mean());
System.out.println(m);
}
else{
for(int i=0;i<n;i++){
if(count[i]==temp) {
System.out.println(marks[i]);
}
}
}
}
float variance(){
float mean=mean();
float sum=0;
System.out.println("\n\n (X-Xbar) | (X-Xbar)^2 \n");
for(int i=0;i<n;i++){
System.out.println((marks[i]-mean)+" | "+((marks[i]-mean)*(marks[i]-mean)));
sum+=(marks[i]-mean)*(marks[i]-mean);
}
return (sum/((n-1)*1.0f));
}
float standard_deviation(){
float variance = variance();
return ((float)(Math.sqrt(variance)));
}
int specified_percentile(int nth) {
sort();
display();
int i=(int)Math.ceil(((nth*(n))/100.0f));
return (marks[i-1]);
}
float specified_quertile(int nth) {
sort();
display();
float sq=0.0f ;
float temp=((nth*(n+1))/4.0f);
int t=(int)(temp);
float k=temp%t;
if(k==0.0f) {
sq=marks[t-1];
}
else{
int i=(int)Math.ceil(temp);
sq=((marks[i-1]+marks[i-2])/2.0f);
}
return sq;
}
float interquarlite_rang(){
return (specified_quertile(3)-specified_quertile(1));
}
void load_from_csv(File f) throws IOException{
FileInputStream fis=new FileInputStream(f);
Vector v=new Vector();
v.add(fis);
loading_process(v,1);
}
void load_from_csv(InputStream istr) throws IOException{
Vector v1=new Vector();
v1.add(istr);
loading_process(v1,0);
}
void loading_process(Vector v,int ch1) throws IOException{
InputStream istr=null;
FileInputStream fis=null;
if(ch1==0){
istr=(InputStream)v.get(0);
}
else{
fis=(FileInputStream)v.get(0);
}
int asc=0,i=0;
int m[]=new int[60];
char[] str=new char[1];
String temp2="";
System.out.println("Your Data is as Bellow ....");
while(asc!=-1) {
if(ch1==0) {
asc=istr.read();
}
else{
asc=fis.read();
}
if(asc==44 || asc==13) {
int t=Integer.parseInt(temp2);
if(t>100 || t<0) {
System.out.println(t+" is not valid Mark...., is not Accepted");
}
else{
System.out.println(t+" is Accepted....");
m[i]=t;
i++;
}
temp2="";
}
else{
if(asc>=48 && asc<=57) {
str[0]=(char)asc;
String temp3=new String(str);
temp2=temp2.concat(temp3);
}
}
}
System.out.println("Your meaningfull data from CSV file found as follow....");
for (int j=0;j<i;j++){
System.out.println(m[j]);
}
int k=0;
while(k==0) {
System.out.print("\nSure you want to import this data ? (Y/N) :");
String ch=br.readLine();
if(ch.equalsIgnoreCase("Y") || ch.equalsIgnoreCase("N")){
if(ch.equalsIgnoreCase("Y")){
marks=new int[60];
n=i;
marks=m;
System.out.println("\n"+n+" Student's Mark imported....");
System.out.println("\nYour Data is Successfully imported....");
}
else if(ch.equalsIgnoreCase("N")){
System.out.println("\nYour previous data is as it is......\n Importation of data has been cancelled....");
}
k=1;
}
else{
System.out.println("Enter Y (for Yes) \nEnter N (for No)... \nOtherwise System can't recognize....");
}
}
}
void sort(){
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(marks[i]>marks[j]) {
int temp=marks[i];
marks[i]=marks[j];
marks[j]=temp;
}
}
}
}
void display(){
System.out.println("\n Your Data is .....\n");
for(int i=0;i<n;i++){
System.out.print(marks[i]+" ");
}
System.out.println("");
}
int get_size(){
return n;
}
}
class p15{
public static void main(String args[]) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StatisticalData s=new StatisticalData();
int ch=1;
while(ch!=0){
System.out.println("\nMain Menu");
System.out.println("01. Insert Mark");
System.out.println("02. Mean");
System.out.println("03. Median");
System.out.println("04. Mode");
System.out.println("05. Variance");
System.out.println("06. Standard Deviation");
System.out.println("07. Specified Percentile");
System.out.println("08. Specified Quarlite");
System.out.println("09. Interquartile Range");
System.out.println("10. Load Data from CSV file ( using Input Stream )");
System.out.println("11. Load Data from CSV file ( using File )");
System.out.println("0. Exit");
System.out.print("Enter your choice :");
try{
ch=Integer.parseInt(br.readLine());
}
catch(NumberFormatException nfx) {
System.out.println("You can not enter the string.... OR can not leave it blank.....");
ch=13;
}
if(s.get_size()==0 && ch!=1 && ch!=10 && ch!=11) {
if(ch>11) {
System.out.println("System can't recognize your choice,re-enter your selection....");
}
else if( ch != 0 ) {
System.out.println("Enter the mark of student first.....");
}
}
else{
switch(ch) {
case 1:
String ch1="Y";
while(ch1.compareToIgnoreCase("N")!=0){
if(ch1.equalsIgnoreCase("Y") || ch1.equalsIgnoreCase("N")){
s.add();
}
else{
System.out.println("Enter Y (for Yes) \nEnter N (for No)... Otherwise System can't recognize....");
}
System.out.print("Want to add more ? (Y/N) :");
ch1=br.readLine();
}
break;
case 2:
System.out.println("Mean : "+s.mean());
break;
case 3:
System.out.println("Median : "+s.median());
break;
case 4:
s.mode();
break;
case 5:
System.out.println("Variance : "+s.variance());
break;
case 6:
System.out.println("Standard Deviation : "+s.standard_deviation());
break;
case 7:
int flag=0;
while(flag==0) {
try{
System.out.print("Enter value for Specified Percentile (0-100) :");
int p=Integer.parseInt(br.readLine());
if( p > 100 || p < 1 ) {
System.out.println("Enter between 1 - 100 .....");
}
else{
System.out.println("Specified Percentile for intput " + p + " is : "+s.specified_percentile(p));
flag=1;
}
}
catch(NumberFormatException e) {
System.out.println("Enter between 1 - 100 .....");
}
}
break;
case 8:
flag=0;
while(flag==0) {
try{
System.out.print("Enter Value for Specified Quarlite (1-3) :");
int q=Integer.parseInt(br.readLine());
if( q > 3 || q < 1) {
System.out.println("Enter between 1 - 3 ......");
}
else{
System.out.println("Specified Quarlite for input " + q + " is : "+s.specified_quertile(q));
flag=1;
}
}
catch(NumberFormatException e){
System.out.println("Enter between 1 - 3 ......");
}
}
break;
case 9:
System.out.print("Interquartile Range : "+ s.interquarlite_rang());
break;
case 10:
flag=0;
String path="";
while(flag==0) {
try{
System.out.print("Enter the Path for csv file :");
path=br.readLine();
String ext=path.substring(path.length()-4);
if(ext.equalsIgnoreCase(".csv")){
InputStream istr=new FileInputStream(path);
s.load_from_csv(istr);
istr.close();
flag=1;
}
else{
System.out.println("System can't recognize your input....");
System.out.println("System can support only .CSV file....");
}
}
catch(FileNotFoundException e) {
System.out.println("System can't find your inputed path....");
}
catch(StringIndexOutOfBoundsException e){
System.out.println("Can't leave it blank...");
}
}
break;
case 11:
flag=0;
path="";
while(flag==0) {
String ext="";
try{
System.out.print("Enter the Path for csv file :");
path=br.readLine();
ext=path.substring(path.length()-4);
}
catch(StringIndexOutOfBoundsException e){
System.out.println("Cannot be Blank");
}
if(ext.equalsIgnoreCase(".csv")) {
try{
File f=new File(path);
s.load_from_csv(f);
flag=1;
}
catch(FileNotFoundException e) {
System.out.println("System can't find your inputed path....");
}
}
else{
System.out.println("System can't recognize your input....");
System.out.println("System can support only .CSV file....");
}
}
break;
case 12:
s.display();
break;
case 0:
break;
default:
System.out.println("System can't recognize your choice, re-enter your selection....");
break;
}
}
}
}
}
import java.util.*;
import java.io.*;
class p15{
public static void main(String args[]) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StatisticalData s=new StatisticalData();
int ch=1;
while(ch!=0){
System.out.println("\n\n\n\n\n\nMain Menu");
System.out.println("01. Insert Mark");
System.out.println("02. Mean");
System.out.println("03. Median");
System.out.println("04. Mode");
System.out.println("05. Variance");
System.out.println("06. Standard Deviation");
System.out.println("07. Specified Percentile");
System.out.println("08. Specified Quarlite");
System.out.println("09. Interquartile Range");
System.out.println("10. Load Data from CSV file ( using Input Stream )");
System.out.println("11. Load Data from CSV file ( using File )");
System.out.println("0. Exit");
System.out.print("Enter your choice :");
try{
ch=Integer.parseInt(br.readLine());
}
catch(NumberFormatException nfx) {
System.out.println("You can not enter the string.... OR can not leave it blank.....");
ch=13;
}
if(s.get_size()==0 && ch!=1 && ch!=10 && ch!=11) {
if(ch>11) {
System.out.println("System can't recognize your choice,re-enter your selection....");
}
else if( ch != 0 ) {
System.out.println("Enter the mark of student first.....");
}
}
else{
switch(ch) {
case 1:
String ch1="Y";
while(ch1.compareToIgnoreCase("N")!=0){
if(ch1.equalsIgnoreCase("Y") || ch1.equalsIgnoreCase("N")){
s.add();
}
else{
System.out.println("Enter Y (for Yes) \nEnter N (for No)... Otherwise System can't recognize....");
}
System.out.print("Want to add more ? (Y/N) :");
ch1=br.readLine();
}
break;
case 2:
System.out.println("Mean : "+s.mean());
break;
case 3:
System.out.println("Median : "+s.median());
break;
case 4:
s.mode();
break;
case 5:
System.out.println("Variance : "+s.variance());
break;
case 6:
System.out.println("Standard Deviation : "+s.standard_deviation());
break;
case 7:
int flag=0;
while(flag==0) {
try{
System.out.print("Enter value for Specified Percentile (0-100) :");
int p=Integer.parseInt(br.readLine());
if( p > 100 || p < 1 ) {
System.out.println("Enter between 1 - 100 .....");
}
else{
System.out.println("Specified Percentile for intput " + p + " is : "+s.specified_percentile(p));
flag=1;
}
}
catch(NumberFormatException e) {
System.out.println("Enter between 1 - 100 .....");
}
}
break;
case 8:
flag=0;
while(flag==0) {
try{
System.out.print("Enter Value for Specified Quarlite (1-3) :");
int q=Integer.parseInt(br.readLine());
if( q > 3 || q < 1) {
System.out.println("Enter between 1 - 3 ......");
}
else{
System.out.println("Specified Quarlite for input " + q + " is : "+s.specified_quertile(q));
flag=1;
}
}
catch(NumberFormatException e){
System.out.println("Enter between 1 - 3 ......");
}
}
break;
case 9:
System.out.print("Interquartile Range : "+ s.interquarlite_rang());
break;
case 10:
flag=0;
String path="";
while(flag==0) {
try{
System.out.print("Enter the Path for csv file :");
path=br.readLine();
String ext=path.substring(path.length()-4);
if(ext.equalsIgnoreCase(".csv")){
inputStream istr=new FileInputStream(path);
s.load_from_csv(istr);
istr.close();
flag=1;
}
else{
System.out.println("System can't recognize your input....");
System.out.println("System can support only .CSV file....");
}
}
catch(FileNotFoundException e) {
System.out.println("System can't find your inputed path....");
}
catch(StringIndexOutOfBoundsException e){
System.out.println("Can't leave it blank...");
}
}
break;
case 11:
flag=0;
path="";
while(flag==0) {
String ext="";
try{
System.out.print("Enter the Path for csv file :");
path=br.readLine();
ext=path.substring(path.length()-4);
}
catch(StringIndexOutOfBoundsException e){
System.out.println("Cannot be Blank");
}
if(ext.equalsIgnoreCase(".csv")) {
try{
File f=new File(path);
s.load_from_csv(f);
flag=1;
}
catch(FileNotFoundException e) {
System.out.println("System can't find your inputed path....");
}
}
else{
System.out.println("System can't recognize your input....");
System.out.println("System can support only .CSV file....");
}
}
break;
case 12:
s.display();
break;
case 0:
break;
default:
System.out.println("System can't recognize your choice, re-enter your selection....");
break;
}
}
}
}
}
class StatisticalData{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int marks[];
int n;
StatisticalData(){
marks=new int[60];
n=0;
}
void add(){
if(n==60) {
System.out.println("There is 60 student in the class...");
System.out.println("You can't enter any more marks.....");
}
else{
System.out.print("Enter Mark of Student : "+(n+1)+" : ");
try{
int temp=Integer.parseInt(br.readLine());
if(temp>100 || temp<0) {
System.out.println("Marks should be in range between 0 - 100...");
add();
}
else{
marks[n]=temp;
n++;
}
}
catch(NumberFormatException nfe) {
System.out.println("Marks can't be the String..... OR can not leave it blank.....");
add();
}
}
}
float mean() {
display();
float sum=0;
for(int i=0;i<n;i++){
sum+=marks[i];
}
return (sum/(n*1.0f));
}
float median(){
sort();
display();
float med=0;
int tmp=(n+1)/2;
if(n%2==0) {
med=(marks[tmp-1]+marks[tmp])/2.0f;
}
else {
med=marks[tmp-1];
}
return med;
}
void mode(){
display();
float m=0.0f;
int count[]=new int[n];
for(int i=0;i<n;i++){
count[i]=1;
for(int j=i+1;j<n;j++){
if(marks[i]==marks[j]) {
count[i]++;
}
}
}
int temp=1;
int temp1=-1;
for(int k=0;k<n;k++){
if(count[k]>temp) {
temp=count[k];
temp1=k;
}
}
System.out.println("Mode is/are .....");
if(temp1==-1) {
m=(3.0f*median())-(2.0f*mean());
System.out.println(m);
}
else{
for(int i=0;i<n;i++){
if(count[i]==temp) {
System.out.println(marks[i]);
}
}
}
}
float variance(){
float mean=mean();
float sum=0;
System.out.println("\n\n (X-Xbar) | (X-Xbar)^2 \n");
for(int i=0;i<n;i++){
System.out.println((marks[i]-mean)+" | "+((marks[i]-mean)*(marks[i]-mean)));
sum+=(marks[i]-mean)*(marks[i]-mean);
}
return (sum/((n-1)*1.0f));
}
float standard_deviation(){
float variance = variance();
return ((float)(Math.sqrt(variance)));
}
int specified_percentile(int nth) {
sort();
display();
int i=(int)Math.ceil(((nth*(n))/100.0f));
return (marks[i-1]);
}
float specified_quertile(int nth) {
sort();
display();
float sq=0.0f ;
float temp=((nth*(n+1))/4.0f);
int t=(int)(temp);
float k=temp%t;
if(k==0.0f) {
sq=marks[t-1];
}
else{
int i=(int)Math.ceil(temp);
sq=((marks[i-1]+marks[i-2])/2.0f);
}
return sq;
}
float interquarlite_rang(){
return (specified_quertile(3)-specified_quertile(1));
}
void load_from_csv(File f) throws IOException{
FileInputStream fis=new FileInputStream(f);
Vector v=new Vector();
v.add(fis);
loading_process(v,1);
}
void load_from_csv(InputStream istr) throws IOException{
Vector v1=new Vector();
v1.add(istr);
loading_process(v1,0);
}
void loading_process(Vector v,int ch1) throws IOException{
InputStream istr=null;
FileInputStream fis=null;
if(ch1==0){
istr=(InputStream)v.get(0);
}
else{
fis=(FileInputStream)v.get(0);
}
int asc=0,i=0;
int m[]=new int[60];
char[] str=new char[1];
String temp2="";
System.out.println("Your Data is as Bellow ....");
while(asc!=-1) {
if(ch1==0) {
asc=istr.read();
}
else{
asc=fis.read();
}
if(asc==44 || asc==13) {
int t=Integer.parseInt(temp2);
if(t>100 || t<0) {
System.out.println(t+" is not valid Mark...., is not Accepted");
}
else{
System.out.println(t+" is Accepted....");
m[i]=t;
i++;
}
temp2="";
}
else{
if(asc>=48 && asc<=57) {
str[0]=(char)asc;
String temp3=new String(str);
temp2=temp2.concat(temp3);
}
}
}
System.out.println("Your meaningfull data from CSV file found as follow....");
for (int j=0;j<i;j++){
System.out.println(m[j]);
}
int k=0;
while(k==0) {
System.out.print("\nSure you want to import this data ? (Y/N) :");
String ch=br.readLine();
if(ch.equalsIgnoreCase("Y") || ch.equalsIgnoreCase("N")){
if(ch.equalsIgnoreCase("Y")){
marks=new int[60];
n=i;
marks=m;
System.out.println("\n"+n+" Student's Mark imported....");
System.out.println("\nYour Data is Successfully imported....");
}
else if(ch.equalsIgnoreCase("N")){
System.out.println("\nYour previous data is as it is......\n Importation of data has been cancelled....");
}
k=1;
}
else{
System.out.println("Enter Y (for Yes) \nEnter N (for No)... \nOtherwise System can't recognize....");
}
}
}
void sort(){
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(marks[i]>marks[j]) {
int temp=marks[i];
marks[i]=marks[j];
marks[j]=temp;
}
}
}
}
void display(){
System.out.println("\n Your Data is .....\n");
for(int i=0;i<n;i++){
System.out.print(marks[i]+" ");
}
System.out.println("");
}
int get_size(){
return n;
}
}
16. A college maintains the information about the marks of...
Shared By : Your Name (College - Place ) Show/Hide Program
Share this program...
Send it to gtumca@gmail.com
with your Name - College name..
and share what you want ... at same mail id...
Thanx in advance...
Be connected...
D_i_Z
17. In the above exercise, use multithreading, to compute the...
Shared By : Your Name (College - Place ) Show/Hide Program
Share this program...
Send it to gtumca@gmail.com
with your Name - College name..
and share what you want ... at same mail id...
Thanx in advance...
Be connected...
D_i_Z
18. In the class Statistics defined earlier add method to find the...
Shared By : Your Name (College - Place ) Show/Hide Program
Share this program...
Send it to gtumca@gmail.com
with your Name - College name..
and share what you want ... at same mail id...
Thanx in advance...
Be connected...
D_i_Z
19. A Frequency Distribution is a tabular summary of data showing...
Shared By : Your Name (College - Place ) Show/Hide Program
Share this program...
Send it to gtumca@gmail.com
with your Name - College name..
and share what you want ... at same mail id...
Thanx in advance...
Be connected...
D_i_Z
20. Create subclass of the Frequency Distribution class called...
Shared By : Your Name (College - Place ) Show/Hide Program
Share this program...
Send it to gtumca@gmail.com
with your Name - College name..
and share what you want ... at same mail id...
Thanx in advance...
Be connected...
D_i_Z