writing program

writing program

View Answers

December 16, 2009 at 11:53 AM

Hi Friend,

Try the following code:

import java.util.*;
class ShowData implements Comparable{
String n;
int match;
int run;
int avg;


public void setN(String n){
this.n=n;
}
public String getN(){
return n;
}

public void setMatch(int match){
this.match=match;
}
public int getMatch(){
return match;
}

public void setRun(int run){
this.run=run;
}
public int getRun(){
return run;
}

public void setAvg(int avg){
this.avg=avg;
}
public int getAvg(){
return avg;
}
public int compareTo(Object Player) throws ClassCastException {
if (!(Player instanceof ShowData))
throw new ClassCastException("Error");
int averageRuns = ((ShowData) Player).getAvg();
return this.avg - averageRuns;
}
}
public class BubbleSort{

public static void main(String[]args){
ShowData data[]=new ShowData[5];

Scanner input=new Scanner(System.in);
System.out.println("*****Cricketer Details*****");
int average=0;
int counter=0;
for(int i=0;i<5;i++){
System.out.println("Enter cricketer name: ");
String name=input.next();
System.out.println("Enter number of matches: ");
int matches=input.nextInt();
System.out.println("Enter runs: ");
int runs=input.nextInt();
average=runs/matches;
data[i] = new ShowData();
data[i].setN(name);
data[i].setMatch(matches);
data[i].setRun(runs);
data[i].setAvg(average);
}
for(int i=0;i<5;i++){
ShowData show = data[i];
String name = show.getN();
int matches = show.getMatch();
int runs = show.getRun();
int avg = show.getAvg();
System.out.println(name + " " + matches + " " + runs+" " +avg);
}
Arrays.sort(data, Collections.reverseOrder());
System.out.println("********Sorted In Descending Order by Average********");

for (int i=0; i<5; i++) {
ShowData show = data[i];
String name = show.getN();
int matches = show.getMatch();
int runs = show.getRun();
int avg = show.getAvg();
System.out.println(name + " " + matches + " " + runs+" " +avg);
}
}
}

Thanks









Related Tutorials/Questions & Answers:
writing program - Java Beginners
writing program  WAP to input Name of Cricketer, Number of matches, total runs scored for 250 players from the user and print data in descending order of their average runs using bubble sort. Average runs=total runs divided
writing angularjs hello world program
tutorials. I want to make simple program and thinking to start from the Hello World program in AngularJS. Searching for simple example for writing angularjs...writing angularjs hello world program  Hi, I just started to learn
Advertisements
writing program in bluej - Java Beginners
writing program in bluej  How to write the program on follwing WAP to inpout a string and print Input : I stidied Hard   Hi Friend, Try the following: import java.util.*; public class UserInput{ public
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
Writing a GUI program - Java Beginners
Writing a GUI program  Hello everyone! I'm trying to write a program that has a text field for input, two buttons and the output text area. A user... if that number is prime or not. When the second button is pressed the program
want a program for cd writing in java - Java Beginners
want a program for cd writing in java  Hi Can u tell some body, doing a program on cd writing in java. I m facing some problem on it. Thanks in advance. Regards sanjaya
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 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
java program for writing xml file - Java Beginners
java program for writing xml file  Good morning i want to write values from my database(one table)into one xml file. Like i have 3 coloumns in my table along with their values,so when click some button i need to generate one
without writing web.xml file we can write servlet program
without writing web.xml file we can write servlet program  Sir Morning... Sir I have one Question "without writing web.xml file we can write servlet program". if yes which way? if no why? but without use Annotation........ Plz
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.  Hello, I would like to know how to write a program to read data from a file. Then use the numerical data within
I am writing a program which converts a string to a timestamp and add days to it
I am writing a program which converts a string to a timestamp and add days to it  java.sql.Timestamp ts2 = java.sql.Timestamp.valueOf("2012-01-11 12:34:39"); long l=ts2.getTime() +(100060602424);//add 24 days Date d=new Date(l
Having a hard time writing program to calculate test scores..........
Having a hard time writing program to calculate test scores..........  i need a program that does this:Standardized Test Scores A local high... to have your program open the data file, count the number of elements in the file
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.  Hello, I would like to know how to write a program to read data from a file. Then use the numerical data within
Writing Simple Java Script Program
Writing Simple Java Script Program   ... of JavaScript and create your first JavaScript program. Creating your first... java script program. To run the program open the html file in any browser
i written the program in the files but in adding whole file is writing once again - Java Beginners
i written the program in the files but in adding whole file is writing once again  Very Urgent: Write a small record management application file and it should not be re-written for every add/delete operation.  Hi
writing characters
writing characters  how to write a group of characters to a string ... i mean for writing single character using charAt in java
Ghost Writing
Ghost Writing Ghost Writing is the kind of writing when someone... of writing it. So ghostwriter is a person who works behind the scene on a writing project in return of certain amount. The write-ups of the writer
Blog Writing
Blog Writing A blog, the short form of web log is an online user... on that. But the professionals are a better choice for writing the blog for commercial or promotional purpose. We provides the services of writing blogs for the commercial
Writing Actions
Writing Actions The Action is responsible for controlling of data flow within an application. You can make any java class as action. But struts have some built in interface and class for making action easily. To make an Action class
dynamically writing text javascript
dynamically writing text javascript  dynamically writing text javascript. Is it possible
dynamically writing text javascript
dynamically writing text javascript  dynamically writing text javascript. Is it possible
ModuleNotFoundError: No module named 'writing_style'
ModuleNotFoundError: No module named 'writing_style'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'writing_style' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'writing_style'
ModuleNotFoundError: No module named 'writing_style'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'writing_style' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'writing_style'
ModuleNotFoundError: No module named 'writing_style'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'writing_style' How to remove the ModuleNotFoundError: No module named
program
program  any program of hotel or school management
program
program  program of jdbc using ms access for creating table
program
program  write a javascript program to create a application form with validation
program
program  write a html program in show table and this word in box
program
program  write a program different between to dates in terms of days in java
program
program  WAP a java program to form 1/2+3/4+5/6+7/8 series
program
program   Write a program to find the difference between sum of the squares and the square of the sums of n numbers
program
program  write a program reversee a string. input-hi this is roseindia output-roseindia is this hi
program
program  develop a servlet to insert the data in the database from our program in the table stored in the database
program
program   An old-style movie theater has a simple profit program. Each customer pays $5 per ticket. Every performance costs the theater $20, plus $.50 per attendee. Develop the program calculateTotalProfit that consumes
program
program  write a java program to input a no. and print wheather the no. is a special no or not. (special no. are those no whose factorial of the sum of digit of the no is same as the original
program
program  Develop the program calculateCylinderArea, which accepts radius of the cylinder's base disk and its height and computes surface area of the cylinder
program
program  explanation of program on extending thread class   Hi Friend, Please go through the following link:ADS_TO_REPLACE_1 Java Threads Thanks
program
program  Develop a program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time, and the Pythagorean
program
program  how to improve programming skills plss tell some tips..i am understanding concepts but unable to write program so,pls give some guideness plsss
Program
Program  a program to prove that default constructor of super class is available to subclass by default. Define a parameterize constructor for super class to store name = â??Tommyâ?? age=â??23â?? and call this constructor
Program
Program  a program to create two classes Commercial and Domestic. Override the method calculatebill() of Commercial class(Rs.8 per unit) into Domestic class(Rs 6 per unit) to compute electricity bill for both classes
program
program  no i want a program that shows how merge sort algorithm works in graphical representations like numbers are taken in circles and computation... in rectangles or circles wat ever it may be. the theme of program is to show algorithm
program
program  . Develop a program that accepts an initial amount of money (called the principal), a simple annual interest rate, and a number of months will compute the balance at the end of that time. Assume that no additional
program
program  Write a JSP Program, which displays a web page containing the name of the Courses, Courses being offered currently, number of students enrolled in each course, new courses to be offered, eligibility criteria for taking
program
program  i want a progra in java to print a sentence in alphabetic order, taking the input from the user.the program should writen without using the array for example : if input= this is a cat then output sould = a cat
program
program  Utopias tax accountants always use programs that compute income taxes even though the tax rate is a solid, never-changing 15%. Define the program calculateTax which determines the tax on the gross pay. Define
program
program  Write a JSP Program, which displays a web page containing two web links one for your profiling and other for the schedule of theory of practical classes of your Batch. When one click on link for getting your profile

Ads