Home Tutorial Java Core Student Result Application

 
 

Share on Google+Share on Google+
Student Result Application
Posted on: June 12, 2010 at 12:00 AM
Advertisement
Here we have created an application by assuming a table for annual examination results for 10 students.

Student Result Application

Here we have created an application by assuming a table for annual examination results for 10 students. For this, we have allowed the user to enter roll no and marks of five subjects and determine the following:

a) Total marks obtained by each students
b) The highest marks in each subject and roll no of the students who have secured it.
c) The student who obtained the highest total marks.

Here is the code:

import java.util.*;

public class Student {
	int rollNo;
	double sub1;
	double sub2;
	double sub3;
	double sub4;
	double sub5;
	double totalMarks;

	public Student(int rollNo, double sub1, double sub2, double sub3,
			double sub4, double sub5, double totalMarks) {
		this.rollNo = rollNo;
		this.sub1 = sub1;
		this.sub2 = sub2;
		this.sub3 = sub3;
		this.sub4 = sub4;
		this.sub5 = sub5;
		this.totalMarks = totalMarks;
	}

	public int getRollNo() {
		return rollNo;
	}

	public double getSub1() {
		return sub1;
	}

	public double getSub2() {
		return sub2;
	}

	public double getSub3() {
		return sub3;
	}

	public double getSub4() {
		return sub4;
	}

	public double getSub5() {
		return sub5;
	}

	public double getTotalMarks() {
		return totalMarks;
	}

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		double max1 = 0, max2 = 0, max3 = 0, max4 = 0, max5 = 0, max = 0;
		int no = 0;
		double s1 = 0, s2 = 0, s3 = 0, s4 = 0, s5 = 0, tm = 0;
		ArrayList list = new ArrayList();
		for (int i = 1; i <= 2; i++) {
			System.out.print("Enter Roll No: ");
			no = input.nextInt();
			System.out.print("Enter marks of Maths: ");
			s1 = input.nextDouble();
			System.out.print("Enter marks of Science: ");
			s2 = input.nextDouble();
			System.out.print("Enter marks of Hindi: ");
			s3 = input.nextDouble();
			System.out.print("Enter marks of English: ");
			s4 = input.nextDouble();
			System.out.print("Enter marks of Social Studies: ");
			s5 = input.nextDouble();
			tm = s1 + s2 + s3 + s4 + s5;
			list.add(new Student(no, s1, s2, s3, s4, s5, tm));
			System.out.println();

			if (s1 > max1) {
				max1 = s1;
			}
			if (s2 > max2) {
				max2 = s2;
			}
			if (s3 > max3) {
				max3 = s3;
			}
			if (s4 > max4) {
				max4 = s4;
			}
			if (s5 > max5) {
				max5 = s5;
			}
			if (tm > max) {
				max = tm;
			}
		}
		System.out.println("*********Roll No and Total Marks*********");
		System.out.println("Roll No     Total Marks");
		for (Student s : list) {
			System.out.println(s.getSub1() + "            " + s.getSub2());
		}
		System.out.println();
		System.out
				.println("*********Highest marks in each subject with RollNO*********");
		for (Student s : list) {
			if (s.getSub1() == max1) {
				System.out.println("Roll No " + s.getRollNo()
						+ " get highest marks in Subject 1 i.e " + max1);
			}
		}
		for (Student s : list) {
			if (s.getSub2() == max2) {
				System.out.println("Roll No " + s.getRollNo()
						+ " get highest marks in Subject 2 i.e " + max2);
			}
		}
		System.out.println();
		for (Student s : list) {
			if (s.getSub3() == max3) {
				System.out.println("Roll No " + s.getRollNo()
						+ " get highest marks in Subject 3 i.e " + max3);
			}
		}

		for (Student s : list) {
			if (s.getSub4() == max4) {
				System.out.println("Roll No " + s.getRollNo()
						+ " get highest marks in Subject 4 i.e " + max4);
			}
		}
		for (Student s : list) {
			if (s.getSub5() == max5) {
				System.out.println("Roll No " + s.getRollNo()
						+ " get highest marks in Subject 5 i.e " + max5);
			}
		}
		System.out.println();
		System.out.println("*********Student Obtained Highest Marks*********");
		for (Student s : list) {
			if (s.getTotalMarks() == max) {
				System.out.println("Roll No " + s.getRollNo()
						+ " get highest marks");
			}
		}

	}
}
Advertisement

Related Tags for Student Result Application:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 12, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com