priya_btech24
need program
1 Answer(s)      3 years and 8 months ago
Posted in : Java Beginners

View Answers

September 16, 2009 at 4:13 PM


Hi Friend,

Try the following code:

import java.util.*;

class ShowData implements Comparable{
int rollNo;
String name;
int marks;
String grade;

public void setRollNo(int rollNo){
this.rollNo=rollNo;
}
public int getRollNo(){
return rollNo;
}

public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}

public void setMarks(int marks){
this.marks=marks;
}
public int getMarks(){
return marks;
}

public void setGrade(String grade){
this.grade=grade;
}
public String getGrade(){
return grade;
}
public int compareTo(Object Student) throws ClassCastException {
if (!(Student instanceof ShowData))
throw new ClassCastException("Error");
int studentmarks = ((ShowData) Student).getMarks();
return this.marks - studentmarks;
}
}
public class DisplayMarks{
public static void main(String[]args){
ShowData data[]=new ShowData[5];
data[0] = new ShowData();
data[0].setRollNo(1);
data[0].setName("A");
data[0].setMarks(85);
data[0].setGrade("B");

data[1] = new ShowData();
data[1].setRollNo(2);
data[1].setName("B");
data[1].setMarks(75);
data[1].setGrade("C");

data[2] = new ShowData();
data[2].setRollNo(3);
data[2].setName("C");
data[2].setMarks(95);
data[2].setGrade("A+");

data[3] = new ShowData();
data[3].setRollNo(4);
data[3].setName("D");
data[3].setMarks(92);
data[3].setGrade("A");

data[4] = new ShowData();
data[4].setRollNo(5);
data[4].setName("E");
data[4].setMarks(88);
data[4].setGrade("B");

for(int i=0;i<5;i++){
ShowData show = data[i];
int no=show.getRollNo();
String name = show.getName();
int marks = show.getMarks();
String grade = show.getGrade();
System.out.println(no + " " + name + " " + marks+" " +grade);
}
Arrays.sort(data);
System.out.println("********Sorted by marks********");

for (int i=0; i<5; i++) {
ShowData show = data[i];
int no=show.getRollNo();
String name = show.getName();
int marks = show.getMarks();
String grade = show.getGrade();
System.out.println(no + " " + name + " " + marks+" " +grade);
}
}
}
Thanks









Related Pages:
need
need  hello anybody can write a javascript program for the capturing of mouse click anywhere in web page and use that click event in specified co-ordinates of x and y(i mean specified x and y cordinates)which can i mention
need
need  hello anybody can write a javascript program for the capturing of mouse click anywhere in web page and use that click event in specified co-ordinates of x and y(i mean specified x and y cordinates)which can i mention
need a java program for the following
need a java program for the following  Write a java program with three horizontal sliders. Name the sliders, the first one as red, the second one as green and the third one as blue. You design the program such that on varying
i need program or code for this program
i need program or code for this program  out should be in this form 1 2 3 4 5 6 3 5 7 9 11 8 12 16 20 20 28 36 48 64 112
Need help with console program?
Need help with console program?  Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). thanks in advance.   Here is an example that repeatedly
need program - Java Beginners
need program  I need a java program to get the multiple student name and mark.display the student information by sorting the marks in ascending or desending order.  Hi Friend, Try the following code: import
Need a java program
Need a java program  Write a code of java to print the fibonacci series.   for(int j=1;j<=5;j++) { int i,a,b,c; a=1;b=1;int n=5; System.out.print("fibonicci series is " + a +" " + b
need help with a program - Java Beginners
Java algorithm - need help with a program  Java algorithm - need help with a program
need help with a program - Java Beginners
need help with a program   Part I An algorithm describes how... by the user. The output of the program should be the length and width (entered.... First you would need to make up the "test data". For this algorithm, the test data
need a java program - Java Beginners
need a java program  Draw a bar chart for the following data using frames Year: 2000 2001 2002 2003 2004 2005 TurnOver:7 8 4 5 9 12
Need help writing a console program
Need help writing a console program  I need help cant seems to figure it out! Write a program that consists of three classes. The first class will be the actual program. The second class will simply convert a string to lower
I need add my java program with a picture.
I need add my java program with a picture.  Good evng Frnds Friends i created 1 jar file in my desktop. I need add this program with 1 picture. Whenever the user double clicking on that picture The program must start instead
Desperately need Java program ASAP - Java Beginners
Desperately need Java program ASAP  I need the source code for a java application that asks the user to enter a 10 character telephone number... should display 555-438-3663. I need this program ASAP if possible. Thank you
Need to develop Java Program - Development process
Need to develop Java Program  Design classes for Currency, Rupee, and Dollar. Write a program that randomly generates Rupee and Dollar objects and write them into a file using object serialization. Write another program to read
beginner need help with online ordering program please
beginner need help with online ordering program please  I have created a program for an online ordering system and now have to add error handling and a few other things my teacher doesn't teach well is there a template I can go
NEED A PROG
NEED A PROG   whats the program to add,delete, display elements of an object using collecions. without using linked list   Hi Friend, Try the following code: import java.util.*; class CollectionExample { public
Need to develop Java Program - Development process
Need to develop Java Program  Develop multi-threaded echo server and a corresponding GUI client in Java
need help on writing a program. - Java Beginners
Writing first Java Program  Hi, I need help to write my first Java Program other then Hello World! Thanks!!  Hi Thanks for choosing roseIndia to get your query solved. check given link to see the solution of your Java
Need to develop Java Program - Development process
Need to develop Java Program  Write a multi-threaded Java program to print all numbers below 100,000 that are both prime and fibonacci number (some examples are 2, 3, 5, 13, etc.). Design a thread that generates prime numbers
Need to develop Java Program - Development process
Need to develop Java Program  [Mini-Project] Develop a programmer's editor in Java that supports syntax-highlighting, compilation support, debugging support, etc
Need help with this!
Need help with this!  Can anyone please help me... Program"); entry = myScanner.nextInt(); numberOfStudentsTest = 0... to effectivly end the loop with out the need to break it. for(i=(0); i <
Need to develop Java Program - Development process
Need to develop Java Program  Develop a simple OPAC system for library using even-driven and concurrent programming paradigms of Java. Use JDBC to connect to a back-end database
need help creating a lift program - Java Beginners
need help creating a lift program  Classes, Methods, Constructors please i need help to create an elevator program Simulating an Elevator write an Elevator class containing various methods. Then, write a program
need help with java program as soon as possible
need help with java program as soon as possible  So my assignment is to write a program that used while loops to perform 6 different things. 1. prompt the users to input two integers: firstNum and secondNum (firstNum must be less
Need in desperate help in writing a console program
Need in desperate help in writing a console program  Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). As they enter the data, assign it to a two
Need in desperate help in writing a console program
Need in desperate help in writing a console program  Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). As they enter the data, assign it to a two
Need in desperate help in writing a console program
Need in desperate help in writing a console program  Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). As they enter the data, assign it to a two
Need to develop Java Program - Development process
Need to develop Java Program  Develop Date class in Java similar to the one available in java.util package. Use JavaDoc comments.  Hi Friend, Try the following code: public class Date { private final int
Need the program urgent veryyyyyyyyyyyyy urgent plsssssssssssssssssss follow the standard in the program
Need the program urgent very urgent please follow the standard in the program  Restaurant Order Management System (ROMS) Problem Case: Create a ROMS system, which is intended to take an order from the customer and charge
need sourcecode - Java Beginners
need sourcecode  Hai, I need program for packetization for videos
i need program to insert data in database using javascript
i need program to insert data in database using javascript  please help me
i need a program that will generate daily base log file dynamically - Log4J
i need a program that will generate daily base log file dynamically  i need a program that will generate daily base log file dynamically For example: if suppose today date is 2 sep 2009, when i execute the program it ll
need of java coding - JavaMail
need of java coding  Design a java interface for ADT stack. Develop it and implement the interface using link list. Provide necessary exception handling for that implementations. pls mail me this lab program..its urgent
Need Help in Java programming
Need Help in Java programming  Hello. Can someone please help me with writing the following program Java program that gives assignment details such as:assignment number,assignment name,due date,submission date,percentage marks
Need help in completing a complex program; Thanks a lot for your help
Need help in completing a complex program; Thanks a lot for your help  Hi, I am currently working on one program which works in this way. 1... content is user inputted and static content is prewritten. 3) We need to search
need help please
need help please  Dear sir, my name is logeswaran. I have a big problem that I can't find the solution for a program. How can I block a user from enter a page second time. Please help me. By the way I'm using Access database
New to JSP..need help to make & run a JSP program.
New to JSP..need help to make & run a JSP program.  Hi, I have installed Tomcat 5.5 on my system. Plz help me to make a simple JSP program...:8080/examples/hello.jsp and press enter. You jsp program will then display
java program...need help as soon as possible!!! - Java Beginners
java program...need help as soon as possible!!!  Modify the Lexer (15.... 4. Print each token with line number READLINE: program { int i int j program left: 0 right: 6 line: 1 { left: 8 right: 8: line: 1 int
I have need to help
I have need to help  Write a program that, for four points A, B, C and P, draws a triangle formed by ABC and a small cross showing the position of P; and displays a line of text indicating which of the following three cases
hello there i need help
hello there i need help  : i need to do a program like... transaction? thats the problem. I dont know how to start this program because... me with the codes and please explain to me how it works. i only need to use
need help - Swing AWT
need help  Create a program to correct and grade a set of multiple choice test result. this is a console program that uses JOptionPane dialog boxes.... The program must then ask the user to: "Please enter the number of students". Therafter
need help - Java Beginners
need help  Need help in programming in Java  Simple java program that will show the output within quotes using system.out.println... of this program is : " * "" *** "" ***** ""
seriously need help....
seriously need help....  Write a program that will prompt the user... for 30 days. Constraints Your program will be divided into four separate sub... program. Use each of the following Java statements at least once in your program
NEED ASSISTANCE ASAP!! THANX!!
NEED ASSISTANCE ASAP!! THANX!!  Problem 4.1 Design an implement.... Name your class RandomNum. You will need two classes to implement... all the crayon objects. Problem 4.3 Design and implement a program with a class
need
need  i need a jsp coding based project plz help me
Need help - Java Beginners
Need help   To Write a Java program that asks the users to enter a m * n matrix of integers, m and n being the number of rows and columns, respectively. The program stores this matrix into a two dimensional m*n array
Need help with my project
Need help with my project  Uses a while loop to perform the following... results to a file in the same directory as the program, placing an appropriate label between each section of output. Note that your program must be able to run
need help. - Java Beginners
program code and get to the output in uppercase letter.amar
Need help in java programming
Need help in java programming  Hello. Can someone please help me with writig the following programm. Assignment 20% Presentation 10% Mini Test 10% Exam 60% Java program that accepts the following details: student
i need help - Development process
i need help  hello, i need help regarding this program. public..., guide me and how my program can take ping for every 5Minutes and store the result in to the files,if i want to do this i must make my program running

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.