Code :
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class MinMaxNormalization
{
public static void main(String[] args)
{
Student[] st = new Student[8];
st[0] = new Student('A',9.1);
st[1] = new Student('C',4.0);
st[2] = new Student('E',5.4);
st[3] = new Student('G',7.2);
st[4] = new Student('B',3.7);
st[5] = new Student('D',2.1);
st[6] = new Student('F',3.8);
st[7] = new Student('H',3.1);
for(int i=0;i<4;i++)
{
st[i].gen = minmax(0.0,10.0,0.0,100.0,st[i].uni);
st[i+4].gen = minmax(0.0,4.0,0.0,100.0,st[i+4].uni);
}
Arrays.sort(st);
System.out.println("Name | Norm result | University Result ");
for(int i=7;i>=0;i--)
System.out.println(st[i].name+" | "+st[i].gen+" | "+st[i].uni);
}
public static double minmax(double min,double max,double nmin,double
nmax,double val)
{
return ((val-min)*(nmax-nmin)/(max-min))+nmin;
}
}
Student.java
public class Student implements Comparable<Student>
{
public double uni,gen;
public char name;
public Student(char n,double u)
{
uni = u;
name = n;
}
public int compareTo(Student compare)
{
double comp = compare.gen;
return Double.compare(this.gen, comp);
}
}
import java.util.Arrays;
import java.util.Collections;
public class MinMaxNormalization
{
public static void main(String[] args)
{
Student[] st = new Student[8];
st[0] = new Student('A',9.1);
st[1] = new Student('C',4.0);
st[2] = new Student('E',5.4);
st[3] = new Student('G',7.2);
st[4] = new Student('B',3.7);
st[5] = new Student('D',2.1);
st[6] = new Student('F',3.8);
st[7] = new Student('H',3.1);
for(int i=0;i<4;i++)
{
st[i].gen = minmax(0.0,10.0,0.0,100.0,st[i].uni);
st[i+4].gen = minmax(0.0,4.0,0.0,100.0,st[i+4].uni);
}
Arrays.sort(st);
System.out.println("Name | Norm result | University Result ");
for(int i=7;i>=0;i--)
System.out.println(st[i].name+" | "+st[i].gen+" | "+st[i].uni);
}
public static double minmax(double min,double max,double nmin,double
nmax,double val)
{
return ((val-min)*(nmax-nmin)/(max-min))+nmin;
}
}
Student.java
public class Student implements Comparable<Student>
{
public double uni,gen;
public char name;
public Student(char n,double u)
{
uni = u;
name = n;
}
public int compareTo(Student compare)
{
double comp = compare.gen;
return Double.compare(this.gen, comp);
}
}
SAP PS Training In Noida
ReplyDelete