------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
A college maintains the information about the marks of the students of a class in a text file with fixed record length. Each line in the file contains data of one student. The first 15 characters have the name of the student, next 12 characters have marks in the four subjects, and each subject has 3 characters. Create a class called StudentMarks, which has student Name, and marks for four subjects. Provide appropriate getter methods and constructors, for this class. Write an application class to load the file into an array of Student Marks. Use the StatisticalData class to compute the statistics mean, median for each of the subjects in the class.------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
NAME : SAHIN NISAR RAJ
ENROLL : 105200693009
COLLEGE : LAXMI INSTITUTE OF COMPUTER APPLICATIONS
ENROLL : 105200693009
COLLEGE : LAXMI INSTITUTE OF COMPUTER APPLICATIONS
Thanks Sir For Helping
Manjoor Hussain Kapoor
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
Main.java
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
package filehandling;import java.util.ArrayList;
public class Main
{
public static void main(String[] args)
{
ArrayList<String> MyArr;
ArrayList<String> Name;
ArrayList<String> Java;
ArrayList<String> OS;
ArrayList<String> SS;
ArrayList<String> SM;
ArrayList<Float> Mean;
ArrayList<Float> Median;
new WriteFile("FileHandling.txt").WriteToFile();
MyArr = new ReadFile("FileHandling.txt").ReadFromFile();
Name = new ArrayList<String>();
Java = new ArrayList<String>();
OS = new ArrayList<String>();
SS = new ArrayList<String>();
SM = new ArrayList<String>();
Mean = new ArrayList<Float>();
Median = new ArrayList<Float>();
for(int i=0;i<MyArr.size();i++)
{
Name.add(MyArr.get(i).substring(0,15));
Java.add(MyArr.get(i).substring(15,18));
OS.add(MyArr.get(i).substring(18,21));
SS.add(MyArr.get(i).substring(21,24));
SM.add(MyArr.get(i).substring(24));
}
Mean.add(mean(Java));
Mean.add(mean(OS));
Mean.add(mean(SS));
Mean.add(mean(SM));
Median.add(median(Java));
Median.add(median(OS));
Median.add(median(SS));
Median.add(median(SM));
DisplayMean(Mean);
DisplayMedian(Median);
}
public static float mean(ArrayList<String> sub)
{
float mean,total = 0;
for(int i=0;i<sub.size();i++)
{
total = total + Integer.parseInt(sub.get(i).trim());
}
mean = total/sub.size();
return mean;
}
public static float median(ArrayList<String> sub)
{
float median = 0;
int tmp=((sub.size()+1)/2);
if(sub.size()%2==0)
{
median= (Float.parseFloat(sub.get(tmp-1)) + Float.parseFloat(sub.get(tmp)))/2;
}
else
{
median=Float.parseFloat(sub.get(tmp));
}
return median;
}
public static void DisplayMean(ArrayList<Float> Mean)
{
System.out.println("Mean Of All Subject");
System.out.println("JAVA "+Mean.get(0));
System.out.println("OS "+Mean.get(1));
System.out.println("SS "+Mean.get(2));
System.out.println("SM "+Mean.get(3));
}
public static void DisplayMedian(ArrayList<Float> Median)
{
System.out.println("Median Of All Subject");
System.out.println("JAVA "+Median.get(0));
System.out.println("OS "+Median.get(1));
System.out.println("SS "+Median.get(2));
System.out.println("SM "+Median.get(3));
}
}
public class Main
{
public static void main(String[] args)
{
ArrayList<String> MyArr;
ArrayList<String> Name;
ArrayList<String> Java;
ArrayList<String> OS;
ArrayList<String> SS;
ArrayList<String> SM;
ArrayList<Float> Mean;
ArrayList<Float> Median;
new WriteFile("FileHandling.txt").WriteToFile();
MyArr = new ReadFile("FileHandling.txt").ReadFromFile();
Name = new ArrayList<String>();
Java = new ArrayList<String>();
OS = new ArrayList<String>();
SS = new ArrayList<String>();
SM = new ArrayList<String>();
Mean = new ArrayList<Float>();
Median = new ArrayList<Float>();
for(int i=0;i<MyArr.size();i++)
{
Name.add(MyArr.get(i).substring(0,15));
Java.add(MyArr.get(i).substring(15,18));
OS.add(MyArr.get(i).substring(18,21));
SS.add(MyArr.get(i).substring(21,24));
SM.add(MyArr.get(i).substring(24));
}
Mean.add(mean(Java));
Mean.add(mean(OS));
Mean.add(mean(SS));
Mean.add(mean(SM));
Median.add(median(Java));
Median.add(median(OS));
Median.add(median(SS));
Median.add(median(SM));
DisplayMean(Mean);
DisplayMedian(Median);
}
public static float mean(ArrayList<String> sub)
{
float mean,total = 0;
for(int i=0;i<sub.size();i++)
{
total = total + Integer.parseInt(sub.get(i).trim());
}
mean = total/sub.size();
return mean;
}
public static float median(ArrayList<String> sub)
{
float median = 0;
int tmp=((sub.size()+1)/2);
if(sub.size()%2==0)
{
median= (Float.parseFloat(sub.get(tmp-1)) + Float.parseFloat(sub.get(tmp)))/2;
}
else
{
median=Float.parseFloat(sub.get(tmp));
}
return median;
}
public static void DisplayMean(ArrayList<Float> Mean)
{
System.out.println("Mean Of All Subject");
System.out.println("JAVA "+Mean.get(0));
System.out.println("OS "+Mean.get(1));
System.out.println("SS "+Mean.get(2));
System.out.println("SM "+Mean.get(3));
}
public static void DisplayMedian(ArrayList<Float> Median)
{
System.out.println("Median Of All Subject");
System.out.println("JAVA "+Median.get(0));
System.out.println("OS "+Median.get(1));
System.out.println("SS "+Median.get(2));
System.out.println("SM "+Median.get(3));
}
}
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
ReadFile.java
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
package filehandling;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Scanner;
public class ReadFile
{
FileInputStream fip;
Scanner sc;
String FileName;
ArrayList<String> MyArr;
int i=0;
ReadFile(String FileName)
{
this.FileName = FileName;
}
public ArrayList ReadFromFile()
{
try
{
fip = new FileInputStream(FileName);
sc = new Scanner(fip);
MyArr = new ArrayList<String>();
while(sc.hasNextLine())
{
String Str = sc.nextLine();
MyArr.add(Str);
Str = null;
}
} catch (Exception ex)
{
System.out.println("Exception in ReadFromFile : " + ex.getMessage());
}
return MyArr;
}
}
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Scanner;
public class ReadFile
{
FileInputStream fip;
Scanner sc;
String FileName;
ArrayList<String> MyArr;
int i=0;
ReadFile(String FileName)
{
this.FileName = FileName;
}
public ArrayList ReadFromFile()
{
try
{
fip = new FileInputStream(FileName);
sc = new Scanner(fip);
MyArr = new ArrayList<String>();
while(sc.hasNextLine())
{
String Str = sc.nextLine();
MyArr.add(Str);
Str = null;
}
} catch (Exception ex)
{
System.out.println("Exception in ReadFromFile : " + ex.getMessage());
}
return MyArr;
}
}
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
WriteFile.java
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
package filehandling;import java.io.FileOutputStream;
public class WriteFile
{
FileOutputStream fop;
String FileName;
WriteFile(String FileName)
{
this.FileName = FileName;
}
public void WriteToFile()
{
try
{
fop = new FileOutputStream(FileName);
fop.write("SAHIN 90 87 65 78 \n".getBytes());
fop.write("RAJ 80 69 54 67 \n".getBytes());
fop.write("KAUSHAL 62 37 52 65 \n".getBytes());
fop.write("BHUMIKA 74 39 81 57 \n".getBytes());
fop.write("VIKAS 56 61 91 48 \n".getBytes());
fop.close();
} catch (Exception ex)
{
System.out.println("Exception in WriteToFile : " +ex.getMessage());
}
}
}
public class WriteFile
{
FileOutputStream fop;
String FileName;
WriteFile(String FileName)
{
this.FileName = FileName;
}
public void WriteToFile()
{
try
{
fop = new FileOutputStream(FileName);
fop.write("SAHIN 90 87 65 78 \n".getBytes());
fop.write("RAJ 80 69 54 67 \n".getBytes());
fop.write("KAUSHAL 62 37 52 65 \n".getBytes());
fop.write("BHUMIKA 74 39 81 57 \n".getBytes());
fop.write("VIKAS 56 61 91 48 \n".getBytes());
fop.close();
} catch (Exception ex)
{
System.out.println("Exception in WriteToFile : " +ex.getMessage());
}
}
}
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
Download Full Program : Click Here
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
Thanks For Help
Manjoor Hussain Kapoor
Manjoor Hussain Kapoor
------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
No comments:
Post a Comment