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



Home Answers Viewqa Java-Beginners writing program

Have Programming Question? Ask it here!
 
 
 


Meera
writing program
1 Answer(s)      4 years and 8 months 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
Writing Calculator Program in Swing
Writing Calculator Program in Swing       In this tutorial we are providing you an example which... shot. For developing a small calculator program in swing we need two different
writing and appending to a file
writing and appending to a file  My input file includes data from both males and females. My code below replaces a 'male string' with the key... for females and write into a different 'female string' in the same program? Sorry If I
File saving and Writing
File saving and Writing   Hello Rose india..... I have a doubt for you plzzz kindly Help me... I have an "Arraylist" which includes some table values... What i want to ask is "I want to create a jsp page which will include
Image writing over URLConnection
Image writing over URLConnection  Hello, I am trying to write... problems trying to write an image I have succeeded in writing to the local HD using.... The problem is that when writing by ImageIO on URL what will the name of the file
writing a code - Java Beginners
writing a code  write a code for a class called display that will display your name and age onto the screen  Hi Friend, Try the following code: class display{ String name; int age; public display(String n,int
Writing a trigger for an userdefined datatype
Writing a trigger for an userdefined datatype  i have a user defined datatype in EMP table like COLUMNNAME:ADDRS_TYPE where ADDRS_TYPE have the following columns DATATYPE :ADDRESS VARCHAR2(136) V_CODE VARCHAR2(8) T_CODE
freelance writing jobs
of writing content for web & print media.  To work in a team
Writing a loop statement using Netbean
Writing a loop statement using Netbean  Write a loop program using NetBeans.   Java Loops class Loops{ public static void main(String[] args){ int sum=0; for(int i=1;i<=10;i
Writing and Reading A File
Writing and Reading A File  Hello, I've been trying to learn writing and reading data from file for our assignment, but just stuck on how to proceed. Our assignment requires us to make an application to read and write customer
File Writing - Java Beginners
File Writing  Hi... I need a syntax or logic or program by which we can write into the desired shell of the Excel file from console window...  Hi friend, I am sending you a link. This is will help you. Please
program
program  any program of hotel or school management
Articles Writing,Articles Writing Services,Articles Writing India,Articles Writing & Content Development
Articles Writing and Content Development In web medium, content... be readable by all. As far as writing an article is concerned, then it becomes... and understandable by all in general. Article writing is the driving force of your
program
program  write a program different between to dates in terms of days in java
program
program  write a html program in show table and this word in box
program
program  write a javascript program to create a application form with validation
program
program  program of jdbc using ms access for creating table
Book Writing
Book Writing We have been providing exceptional writing solutions to a diverse range of clients across the world. So if you are proficient in thinking than writing, or if you are just short
program
program  WAP a java program to form 1/2+3/4+5/6+7/8 series
program
program  develop a servlet to insert the data in the database from our program in the table stored in the database
Advertisements
 

 

 

DMCA.com