using class and methods 3 Answer(s) 2 years and 11 months 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
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 Pages:
using class and methods - Java Beginners usingclass 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
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
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
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
programes on methods
as parameters)
write a program to calculate factorial of a no. using recursive function
write a program to concatenate two strings entered by user
design a class
Functions and Methods using switch case statement.
import java.util.*;
class FindDay
{
public... the day number from the main class. The function uses a switch-case statement... the frequency of each vowel.
(5) Write a program in Java to input a string using
Writing code with multiple Class Methods and String Arrays
Writing code with multiple ClassMethods 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 ClassMethods 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
Java :Thread Methods
Java :Thread Methods
This section explains methods of Thread class.
Thread Methods :
Thread class provides many method to handle different thread... is a
daemon thread or not.
run() : If we are constructing thread by using
Calling Methods Using SpEL
Calling MethodsUsing SpEL
Spring 3 provides powerful Expression Language... by calling methods.
Person.java: The Person class contains property named "... of the Person classusing Spring expression
Language.
<beans xmlns="http
Class Class, Object and Methods
 ... the class,
object and it's methods. This program uses the several values... is
declared. First class is square which is using for getting the Area
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
Callback Methods
Callback Methods
Callbacks methods are the way of managing life cycle of
an instance. Callback methods are generally used by containers. The methods are
called at specific time
Calling Static Methods Using SpEL
to wire random property of the MyClass classusing
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
methods in the applet - Applet
provides the Applet class with default implementation for all the applet methods. You can implement these methods in the applet class when you want to override... the applet1 class to Applet class, therefore the methods are already
Methods - OOP
utility methods
and main(...), you should probably not be using static methods... is overloaded when there are two or more methods
by the same name in a class. At first...
Java NotesMethods - OOP
Static methods
If your method doesn't use
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'smethods. Constructor is the method which name
what is class methods in objective c
what is classmethods in objective c What is classmethods 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 classmethods in objective c What is classmethods in objective c? Explain the class method of objective c with the help of an example
Java - Class, Object and Methods in Java
Java - Class, Object and Methods in Java
 ... will see how to use the class, object and it's methods.
This program uses... the main function is declared. First class is square which
is using for getting
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
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 ClassMethods Example
<?php
class myclass{
function aa
PHP Static Variable and Methods
the method usingclass, without instantiating any object.
Example of PHP Static Variables & Methods :
<?php
class
One{
private static
$var=0...PHP Static Methods and Variables:
In this tutorial we will study when we
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
Static/Class methods
Java NotesStatic/Classmethods
There are two types of methods.
Instance... methods in the predefined Math
class. (See Math and java.util.Random... to specify the class where the
method is defined. For instance methods
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
Java Methods Problem - Java Beginners
here: two types which include class variable (static- access using the class...Java Methods Problem I have to write a program that has three types... the slices in each pie are done and then how do I create class variables that tell me
Java Methods Problem - Java Beginners
here: two types which include class variable (static- access using the class...Java Methods Problem I have to write a program that has three types... the slices in each pie are done and then how do I create class variables that tell me
Collections Class using Comparator comp.
There are many more methods in Collections...
Java NotesCollections Class
The java.util.Collections class contains static utility methods
for manipulating collections.
Some useful Collections
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 ClassMethods in Java... or indirectly. There are many methods defined in java.lang.Object
class...(), wait(), etc
Java object classmethods are:-
finalize()
clone()
equals
Access Static Member Of The Class Through Object
that work
without any object of the class. Static methods are limited to calling other static
methods in the class and to using only static variables...
Access Static Member Of The Class Through Object
 
Overriding methods
,same argument and same return type as a method in the superclass.
class Animal... for grass");
}
}
class Cat extends Animal {
public void eat(String str) {
System.out.println("Drinking for milk");
}
}
class Dog extends Animal
Explain final class, abstract class and super class.
.
An abstract class is a class that is declared by using the abstract keyword. It may...Explain final class, abstract class and super class. Explain final class, abstract class and super class.
Explain final class, abstract
Java Abstract Class
;
An abstract class is a class that is declared by
using the abstract keyword.... Which helps us to organize our classes based on common methods. An
abstract class... of the abstract methods.
The key idea with an abstract class is useful when
there is common
Functions and Methods
is equilateral,isosceles or scalene.
import java.util.*;
class TypeOFTriangle
Object-Oriented Implementation of Numerical Methods - Java Tutorials
Object-Oriented Implementation of Numerical Methods
2002-04-01 The Java... of Numerical Methods
Author:
Dr. Heinz M. Kabutz
If you are reading... Implementation of Numerical Methods by Dr. Didier Besset
As promised, this week I am
Old and New Vector Methods
, the
DefaultListModel still uses the old methods, so if you are using
a JList, you...
Java: Old and New Vector Methods
When the new Collections API was introduced in Java 2 to
provide uniform data structure classes, the Vector class
class
medals. In this class, you should also define constructors, and assessor, mutator
methods.
Task 2
MedalTally.java is a class to model a medal tally, containing... is a class to represent a country in medal tally. It has an attribute of
country
Java Abstract Class Example using 'abstract' keyword. An abstract class may contain
abstract....
A subclass of an abstract class must have to define all of its abstract methods... will be as follows :
An another way to create and call the methods of abstract class
abstract class
abstract class Explain the concept of abstract class and it?s use with a sample program.
Java Abstract Class
An abstract class is a class that is declared by using the abstract keyword. It may or may not have
coolection class
coolection class how to find maximum and minimum from a list using max & min method of collection class
Here is an example... provides direct methods to get maximum and minimum value from any collection