0% found this document useful (0 votes)
47 views6 pages

Zscore and Min-Max Program

The document describes a Java program that calculates statistical metrics like average, standard deviation, z-scores, minimum and maximum values from data in an Excel spreadsheet. It connects to Excel using JDBC, executes SQL queries to retrieve the data, calculates the metrics using the data and common statistical formulas, and outputs the results.

Uploaded by

chirusagar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views6 pages

Zscore and Min-Max Program

The document describes a Java program that calculates statistical metrics like average, standard deviation, z-scores, minimum and maximum values from data in an Excel spreadsheet. It connects to Excel using JDBC, executes SQL queries to retrieve the data, calculates the metrics using the data and common statistical formulas, and outputs the results.

Uploaded by

chirusagar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

ZSCORE AND MIN-MAX PROGRAM

import java.sql.*;
import java.lang.Math.*;
import java.util.Scanner;
public class Excel {
static Scanner scanner = new Scanner(System.in);
double nmax,nmin;
nmax=1.0;
nmin=0.0;
public static void main(String[] args) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:excel");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("Select * from [Sheet1$]");
int SUM = 0, AVG, T = 0, i, columnValue, min, max;
double dev = 0, ZSCORE, MINMAX;
ResultSetMetaData rsmd = rs.getMetaData();
int no = rsmd.getColumnCount();
double DEV = 0;
while (rs.next()) {
for (i = 1; i <= no; i++) {
columnValue = rs.getInt(i);
SUM = SUM + columnValue;
T = T + 1;
}
}
AVG = SUM / T;
System.out.println("AVERAGE VALUE:" + AVG);
/**
* *************calculating deviation********************
*/
rs = st.executeQuery("Select * from [Sheet1$]");
rsmd = rs.getMetaData();
no = rsmd.getColumnCount();
while (rs.next()) {
for (i = 1; i <= no; i++) {
columnValue = rs.getInt(i);
dev = dev + Math.pow(columnValue - AVG, 2);
}

}
dev = Math.sqrt(dev / (T - 1));
System.out.println("DEVIATION:" + dev);
/**
* **********************calculating Z SCORE Values*************
*/
rs = st.executeQuery("Select * from [Sheet1$]");
rsmd = rs.getMetaData();
no = rsmd.getColumnCount();
System.out.println("ZSCORE VALUES");

while (rs.next()) {
for (i = 1; i <= no; i++) {
columnValue = rs.getInt(i);
ZSCORE = (columnValue - AVG) / dev;
System.out.println(ZSCORE);
}
}
/**
* *********************creating array in order to calculate min
* and max value***********
*/
int arr[] = new int[1000];
rs = st.executeQuery("Select * from [Sheet1$]");
rsmd = rs.getMetaData();
no = rs.getRow();
while (rs.next()) {
arr[0] = rs.getInt(1);
}
/**
* *******************calculating Min
* value****************************************
*/
min = arr[0];
rs = st.executeQuery("Select * from [Sheet1$]");
rsmd = rs.getMetaData();
no = rsmd.getColumnCount();
while (rs.next()) {
for (i = 1; i <= no; i++) {
columnValue = rs.getInt(i);
if (min >= columnValue) {
min = columnValue;
}

}
}
/**
* *******************************calculating MAx
* value***********************************
*/
max = arr[0];
rs = st.executeQuery("Select * from [Sheet1$]");
rsmd = rs.getMetaData();
no = rsmd.getColumnCount();
while (rs.next()) {
for (i = 1; i <= no; i++) {
columnValue = rs.getInt(i);
if (max < columnValue) {
max = columnValue;
}
}
}
/**
* ******************calculating MIN MAX
* values******************************************
*/
System.out.println("enter nmax value");
nmax=Integer.parseInt(scanner.next());
System.out.println("enter nmin value");
nmin=Integer.parseInt(scanner.next());
System.out.println("MIN MAX VALUES");
rs = st.executeQuery("Select * from [Sheet1$]");
rsmd = rs.getMetaData();
no = rsmd.getColumnCount();
while (rs.next()) {
for (i = 1; i <= no; i++) {
columnValue = rs.getInt(i);
MINMAX = (float)( (columnValue - min) / (max - min))*(nmax-nmin);
System.out.println(MINMAX);
}
}
st.close();
con.close();
} catch (Exception ex) {
System.err.print("Exception: ");
System.err.println(ex.getMessage());
}
}

EXCEL DATA

OUTPUT
c:\Program Files\Java>javac Excel.java
C:\Program Files\Java>java Excel
AVERAGE VALUE:55
DEVIATION:30.276503540974915
ZSCORE VALUES
-1.486301082920587
-1.1560119533826787
-0.8257228238447705
-0.4954336943068623
-0.1651445647689541
0.1651445647689541
0.4954336943068623
0.8257228238447705
1.1560119533826787
1.486301082920587
enter nmax value
1
enter nmin value
0
MIN MAX VALUES
0.0
0.1111111119389534

0.2222222238779068
0.3333333432674408
0.4444444477558136
0.5555555820465088
0.6666666865348816
0.7777777910232544
0.8888888955116272
1.0

You might also like