vanshi
using class and methods
3 Answer(s)      5 years ago
Posted in : Java Beginners
Sir,Plz help me to write this below pgm. here is the question:

Assume a table for annual examination results for 10 students. write a program to read the data 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.Use appropriate classes and methods
Advertisement
View Answers

June 12, 2010 at 4:30 PM


Hi Friend,

Try the following 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<Student> list = new ArrayList<Student>();
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;
}
}


June 12, 2010 at 4:31 PM


continue..

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");
}
}

}
}

Thanks


June 12, 2010 at 4:34 PM


Hi Friend,

We have created a loop for only 2 students, you can place 10 in place of 2 so that program will display the results of 10 students.

Thanks









Related Tutorials/Questions & Answers:
using class and methods - Java Beginners
using class and methods  Sir,Plz help me to write this below pgm. here is the question: Assume a table for annual examination results for 10... the following code: import java.util.*; public class Student{ int rollNo
What's the proper way to test a class with private methods using JUnit?
What's the proper way to test a class with private methods using JUnit?  What's the proper way to test a class with private methods using JUnit
Advertisements
can we use scanner class,class , object and methods to get output without using constructor ????
can we use scanner class,class , object and methods to get output without using... am i getting error here... can we get output using scanner class , object and methods without using constructor??? //Program to illustrate the classes
to create a java class and methods
to create a java class and methods  How to create a java class without using the library class to represent linked lists of integers and also provide it with methods that can be used to reverse a list & append two lists.Also
java object class methods
java object class methods  What are the methods in Object class?  There are lots of methods in object class. the list of some methods are as- clone equals wait finalize getClass hashCode notify notifyAll
Getting Methods Information of a class
Getting Methods Information of a class   ... to retrieve information of all methods of a class (that included in the program... by using different methods on that method object. Here is the example code
what is class methods in objective c
what is class methods in objective c  What is class methods in objective c? Explain the class method of objective c with the help of an example
what is class methods in objective c
what is class methods in objective c  What is class methods in objective c? Explain the class method of objective c with the help of an example
Class AsyncEvent important methods
In this section, you will learn about the important methods of AsyncEvent Class
PHP list class methods
Function get_class_methods gives the all methods names of the given class. It takes input as class name and returns the array of the methods name PHP LIst Class Methods Example <?php class myclass{ function aa
creating class and methods - Java Beginners
of the Computers. This class contains following methods, - Constructor method...creating class and methods  Create a class Computer that stores... ( ) method that creates array of 4 objects of Computer class and that takes input
Abstract class,Abstract methods and classes
to implement the methods inherited from the abstract class (base class... Abstract methods and classes     ... is used with methods and classes.  Abstract Method An abstract method one
variables and methods declared in abstract class is abstract or not
variables and methods declared in abstract class is abstract or not  variables and methods declared in abstract class is abstract
write a program to demonstrate wrapper class and its methods......
write a program to demonstrate wrapper class and its methods......  write a program to demonstrate wrapper class and its methods
An application using swings and vector methods
An application using swings and vector methods   Hi, I want an application in Java swings which uses good selection of Vectors methods
Abstract class or methods example-1
;Animal class"); // this     // ...;form Animal class");   } } class ...;called form BuzzwordAnimal class");   }  
Object Class Methods in Java
We are going to discus about Object Class Methods in Java... or indirectly. There are many methods defined in java.lang.Object class...(), wait(), etc Java object class methods are:- finalize() clone() equals
Writing code with multiple Class Methods and String Arrays
Writing code with multiple Class Methods and String Arrays  So what I am trying to do is create a code that lists music artists names using user input. It has to have multiple classes so I will have a main class, and a class
Writing code with multiple Class Methods and String Arrays
Writing code with multiple Class Methods and String Arrays  So what I am trying to do is create a code that lists music artists names using user input. It has to have multiple classes so I will have a main class, and a class
Calling Methods Using SpEL
Calling Methods Using SpEL Spring 3 provides powerful Expression Language... by calling methods. Person.java: The Person class contains property named "... of the Person class using Spring expression Language. <beans xmlns="http
code for multiplication of matrix in java using methods
code for multiplication of matrix in java using methods  code for multiplication of matrix in java using methods
methods
methods  PrintStream class has two formatting methods,what
methods
methods  PrintStream class has two formatting methods,what
methods
methods  PrintStream class has two formatting methods,what
Can a abstract class be defined without any abstract methods?
Can a abstract class be defined without any abstract methods?   hi, Can a abstract class be defined without any abstract methods? thanks
Calling Static Methods Using SpEL
to wire random property of the MyClass class using T() operator of Spring...Calling Static Method Using SpEL Spring 3 provides powerful Expression... method of any bean using SpEL's T() operator. Lets take an example
Can I have multiple main() methods in the same class?
Can I have multiple main() methods in the same class?  Hi, Can I have multiple main() methods in the same class?   Hi, No, We cann't use multiple main() method within the same class. If we do this then the program
Call class methods
Call class methods       This Example shows you how to call class method in velocity... through method  init(). 2: Create object of VelocityContext Class. 3
Class, Object and Methods
Class, Object and Methods      ... is a software bundle of variables and related methods of the special class...) something related to the class's methods. Constructor is the method which name
Using Abstract Class
Using Abstract Class      ... class. This class must be inherited. Unlike interface the abstract class may implement some of the methods defined in the class, but in this class at least one
Abstract class or methods example-2
;defined in the non abstract class } abstract class ...;runLion1(); // defined in the non abstract class