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:
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
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;
}
}
Related Tutorials/Questions & Answers:
using class and methods - Java Beginnersusing 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
Advertisements
to create a java class and methodsto 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 methodsjava 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
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 or the base
class. Subclasses are derived to implement the
methods inherited from...
Abstract
methods and classes
... is used
with
methods and classes.
Abstract MethodADS_TO_REPLACE_1
Object Class Methods in JavaWe 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
Calling Methods Using SpELCalling
Methods Using SpEL
Spring 3 provides powerful Expression Language... by calling
methods.
Person.java: The Person
class contains property named "... getPersonName()
method to wire name property of the Person
class using Spring
methodsmethods PrintStream
class has two formatting
methods,what
methodsmethods PrintStream
class has two formatting
methods,what
methodsmethods PrintStream
class has two formatting
methods,what
Using Abstract ClassUsing 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
Calling Static Methods Using SpEL property of the MyClass
class using
T() operator of Spring expression...Calling Static Method
Using SpEL
Spring 3 provides powerful Expression... method of any bean
using SpEL's
T() operator.
Lets take an
example
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..._TO_REPLACE_5
An another way to create and call the
methods of abstract
class 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 MethodsClass, Object and
Methods
...
methods. Constructor is the method which name
is same to the
class.... This program is
using two classes. First
class is another and
second is the main
Java :Thread MethodsJava :Thread
Methods
This section explains
methods of Thread
class.
Thread
Methods :
Thread
class provides many method to handle different thread... are constructing thread by
using a
separate Runnable run object, then run method
How to access sub class member using super class objectHow to access sub
class member
using super
class object
class A{
}
class B extends A{
int b=1;
}
class Test{
public static void main(String args[])
{
what to do here to access sub
class variable b
using super
class object
Java Abstract Class;
An abstract
class is a
class that is declared by
using the abstract keyword... an abstract
class. Which helps us to organize our classes based on common
methods... for all of the abstract
methods.
The key idea with an abstract
class is useful when
PHP Static Variable and Methods then we can access the method
using class, without instantiating any object.
Example of PHP Static Variables &
Methods :
<?phpADS_TO_REPLACE_2
class...PHP Static
Methods and Variables:
In this tutorial we will study when we
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
Decompress file using Inflater class.Decompress file
using Inflater
class.
In this tutorial, we will define the use of Inflater
class. The Inflater
class provide support for Decompression
using... Example, we
will explain how to decompress file
using Inflater
class. The Inflater
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
Setting Fields Information of a class using Reflection Setting Fields Information of a
class using Reflection... we have seen that we can get
field values of a
class by
using the Field
class. Now we can also set
different field values of that
class by
using set() method
String toLowerCase and toUppercase methods example()
methods example:-
String
class provides
methods toUpperCase() and toLowerCase... to
lowercase. We have used these two
methods in this example. user can see how to
use these
methods.
Example:-ADS_TO_REPLACE_1
<?xml
Immutable Image using Canvas Class
Immutable Image
using Canvas
Class
... to create the immutable
image
using canvas. In this example ImageCanvas
class extends the Canvas
class to create the immutable image. In the constructor