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



Home Answers Viewqa Java-Beginners writing program
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Meera
writing program
1 Answer(s)      5 years ago
Posted in : Java Beginners



Advertisement
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 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
Advertisements
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
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 Simple Java Script Program
Writing Simple Java Script Program   ... of JavaScript and create your first JavaScript program. Creating your first JavaScript Program In the last lesson you learned how to create simple java script
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
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
question "writing prog"
question "writing prog"  Hello I want helping for this question, please Write a program that reads some friends‚?? names, stores them in an array, and then prints out on the screen all friends who start by a particular letter
Web Writing
Web Writing       The art of writing for the web is far removed from writing for the print world.... Following is the prime aspect you need to keep in mind while writing for the web
SEO Writing
SEM and SEO Article Writing SEM and SEO article helps your business to grow... the intended traffic through SEM and SEO article writing in addition to other tools... is the demand of SEM and SEO article writing services. A good command over
writing HTML entirely by hand
writing HTML entirely by hand  How comfortable are you with writing HTML entirely by hand
writing plugin - WebSevices
writing plugin  can anyone help me in writing plugin for internet explorer browser using c++ in .net environment
writing aprogram - Java Beginners
writing aprogram  Write a program to reverse any string  Hi Friend, Try the following code: import java.util.*; class StringReverse{ public static void main(String[]args){ Scanner input=new Scanner(System.in
writing webservices in php
writing webservices in php  How to write a simple web service in PHP
writing programs - Java Beginners
writing programs  1.write a program to display odd numbers from 1-50. 2.And Write a program to find the facorial of a number  Hi Friend, 1) class OddNumbers{ public static void main (String args
help on writing a javascript - Java Beginners
help on writing a javascript  really have no idea on how to write it if some 1 could help out it would be great of you. thanks in advance...?? 60 D : 0 ‚?? 40 3. Write a JavaScript program to take as input three
 

 

 

DMCA.com