unit_3_9.java

import java.util.*; class super_class { public int i,Efi=0,Efixi=0; public double X12; public int xi[]; //declaring array. public int fi[]; //declaring array. public int fixi[]; //declaring array. //find_X12 means (X12=Efixi/Efi) <-- this is maths arithmetic mean. public void find_X12(int xi_length,int fi_length,Scanner sc) { xi=new int[xi_length]; //initialize array. fi=new int[fi_length]; //initialize array. fixi=new int[xi_length]; //initialize array System.out.println("Enter XI VALUES"); for(i=0;i<xi_length;i++) { xi[i]=sc.nextInt(); //stores xi values in array. } System.out.println("Enter FI VALUES"); for(i=0;i<fi_length;i++) { fi[i]=sc.nextInt(); //stores fi values in array. Efi=Efi+fi[i]; //total of fi like in maths. fixi[i]=(fi[i]*xi[i]); //find fixi like in maths. Efixi=Efixi+fixi[i]; //total of fixi like in maths. } //now we have Efixi and Efi like in our formula (X12=Efixi/Efi). X12=((double)Efixi/(double)Efi); //I just made explicit typecast of value for accurate result. System.out.println("Arithmetic mean is "+X12); } } public class child_class extends super_class { public double x_minus_X12[]; //just declaring array. public double x_minus_X12_square[]; //just declaring array. public double Ex_minus_X12_square=0,SD; public void find_sd(int xi_length) { x_minus_X12=new double[xi_length]; //initialize array. x_minus_X12_square=new double[xi_length]; //initialize array. for(i=0;i<xi_length;i++) { x_minus_X12[i]=(xi[i]-X12); // store all |xi-X12| values. x_minus_X12_square[i]=(x_minus_X12[i]*x_minus_X12[i]); //square the x_minus_X12 like in formula ((xi-X12)^2). Ex_minus_X12_square=(Ex_minus_X12_square+x_minus_X12_square[i]); //store total. } //now we have all things which are used to find S.D. SD=Math.sqrt((Ex_minus_X12_square/(xi_length-1))); //store standard deviation value. System.out.println(" standard deviation is "+SD); } public static void main(String...args) { int xi_length,fi_length; Scanner sc=new Scanner(System.in); System.out.println("Enter a size of xi"); xi_length=sc.nextInt(); //get the xi_length from user. System.out.println("Enter a size of fi"); fi_length=sc.nextInt(); //get the fi_length from user. child_class obj=new child_class(); //create a child_class object. obj.find_X12(xi_length,fi_length,sc); //just call the find_X12 function to find arithmetic mean and pass Scanner object. obj.find_sd(xi_length); //just call the find_sd function to find standard deviation. } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.