Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners using class and methods

Have Programming Question? Ask it here!
 
 
 


vanshi
using class and methods
3 Answer(s)      4 years and a month 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
Static/Class methods
Java NotesStatic/Class methods 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
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
Abstract class or methods example-1
;Animal class"); // this     // ...;form Animal class");   } } class ...;called form BuzzwordAnimal class");   }  
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
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
Defining handler methods using @RequestMapping annotation
In this section, you will learn about defining new handler methods using @RequestMapping annotation
Abstract class or methods example-3
abstract class BaseAbstractClass {   abstract void baseMethod1();    // Definition done in DerivedClass class   void 
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
core java ,io operation,calling methods using switch cases
core java ,io operation,calling methods using switch cases  How to create a dictionary program,providing user inputs using io operations with switch cases and providing different options for searching,editing,storing meanings
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
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
Graphics class
and imaging methods in the Java 2 javax.swing.Graphics2D class. There are also... Java NotesGraphics class Description The Graphics class contains drawing methods. A Graphics object is passed to your paintComponent(Graphics g). You
PHP Static Variable and Methods
the method using class, 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
how to use StringTokenizer to retrieve the class name, attributes name and methods name from the Java Source Code
one problem which is retrieve the Class Name, Attributes Name and Methods Names...how to use StringTokenizer to retrieve the class name, attributes name and methods name from the Java Source Code  hi, I have done a program whereby
Given a list of methods for a stateful or stateless session bean class, define which of the following operations can be performed from each of those methods: SessionContext interface metho
Given a list of methods for a stateful or stateless session bean class... of those methods: SessionContext interface methods, UserTransaction methods, Java Naming and Directory Interface API (JNDI API) access to java
How to access sub class member using super class object
How 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
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:- <?xml version="1.0
linking jsp with database using classes and methods and then access them all in to my jsp page - JSP-Servlet
linking jsp with database using classes and methods and then access them all in to my jsp page  how to connect jsp page with mysql using classes and methods so that i can use the reusability character of java.  just
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  
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
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
Class
techniques. A class defines the properties of  objects and methods used.... A class defines the properties of the objects and the methods used to control... class. Now we will learn, how to define a class having methods, objects
How to Compress file using DeflaterOutputStram class in java.
How to Compress file using DeflaterOutputStram class in java. In this tutorial... will compressed the data of a file by using DeflaterOutputStream class... java.io.FilterIntputStream class. It provides the following methods: Return Type
Advertisements
 

 

 

DMCA.com