Need help, I am terrible with Java, can someone help.

Please can someone help me with this program. I am in a JAVA programming class and I am having a heck of a time. I am still having a problem with the basic concepts of JAVA but the teacher continues to give us difficult assignments with out any help. Here is the assignment:
Write a class named 'Player' that has two attributes, 'name' (which has to be a 'Sting') and 'rating' (which has to be a 'int'). Then write an application class named "PlayerRating" that first creates an array consisting of 5 player objects, then display the list three times; first unsorted, then sorted by Name and finally sorted by rating.
Must use the Bubble Sort Program and do NOT use Array.sort.
Example output:
Unsorted
Name: Rating:
Mickey Mantle 5
Ty Cobb 3
Babe Ruth 4
Pete Rose 3
Sammy Sosa 1
Sorted by Name
Name: Rating:
Babe Ruth 4
Mickey Mantle 5
Pete Rose 3
Sammy Sosa 1
Ty Cobb 3
Sorted by Rating
Name: Rating:
Sammy Sosa 1
Pete Rose 3
Ty Cobb 3
Babe Ruth 4
Mickey Mantle 5
Here is what I have and it is not much, cause I am so lost:
1 import java.io.*;
2 import javax.swing.*;
3 import java.text.*;
4 import java.lang.*;//String[][];
5 import java.util.*; //ArrayList;
6
7
8 public class Player
9 {
10 public static void main (String [][]args)
11 {
12
13 int maxSize = 100; //array size
14 // String[][] s = new String[100][100]; //Default values: null
15 boolean [] b = new boolean[4]; //default values: false
16 int[][] i = new int[10][10]; //default values: 0
17
18
19 PlayerRating arr; //reference to array
20 //arr = new PlayerRating(maxSize);
21 Sting player[]={"Mickey Mantle 5","Ty Cobb 3"
22 ,"Babe Ruth 4","Pete Rose 3","Sammy Sosa 1"};
23
24
25 }
26 }
Here is all I have on the second program:
public class PlayerRating
public void PlayerRating (int Max)
int[][] i = new int[10][10];
Please help I am totally lost.

You repeat code, you should do a generic bubble sort with comparators, or declare class as Comparable. You can see how String class is Comparable, furthermore it has a final static Comparator for CASE_INTENSENSITIVE_ORDER.
class User implements Comparable<User>{
  public static final java.util.Comparator<Cliente> RATING_COMPARATION=new java.util.Comparator<Cliente>(){
    public int compare(User u1,User u2){
           int comp=u1.rating-u2.rating;
           return comp==0?u1.name.compareTo(u2.name):comp;
     private String name;
     private int rating;
     public User(String name, int rating){
          setName(name);
          setRating(rating);
     public String getName(){
          return name;
     public void setName(String name){
          this.name = name;
     public int getRating(){
          return rating;
     public void setRating(int rating){
          this.rating = rating;
        // Compare users first by name and last by rating;
        public int compareTo(User anotherUser){
           int comp=name.compareTo(anotherUser.name);
           return comp==0?rating-anotherUser.rating:comp;
         public void equals(Object o){
          if(this==o)
            return true;
          if(o instanceof User){}
             User anotherUser=(User)o;
             return name.equals(anotherUser.name)&&rating==anotherUser.rating;
          return false;
           public int hashCode(){
              return name.hashCode()+rating<<16;
public class Sorting{
     public <E extends Comparable<E>>static void bubleSort(E[] arr){
          for(int i = 0; i < arr.length - 1; i++){
               for(int j = arr.length - 1; j > i; j--){
                    if(arr[j].compareTo(arr[j - 1])<0)
                                 swap(arr,j,j-1);
     public static<E> void bubleSort(E[] arr,Comparator<E> cmp){
          for(int i = 0; i < arr.length - 1; i++){
               for(int j = arr.length - 1; j > i; j--){
                    if(cmp.compare(arr[j],arr[j-1]) < 0)
                                  swap(arr,j,j-1);
        private static void swap(Object[] arr,int x,int y){
           Object tmp=arr[x];
           arr[x]=arr[y];
           arr[y]=tmp;
     public static void main(String[] args){
          User[] arr = new User[5];
          arr[0] = new User("Mickey Mantle", 5);
          arr[1] = new User("Ty Cobb", 3);
          arr[2] = new User("Babe Ruth", 4);
          arr[3] = new User("Pete Rose", 3);
          arr[4] = new User("Sammy Sosa", 1);
          System.out.println("Sorting by Name : ");
          bubleSort(arr)
          System.out.println(Arrays.toString(arr));
          System.out.println("Sorting by Rating : ");
          bubleSort(arr,User.RATING_COMPARATION);
          System.out.println(Arrays.toString(arr));
}

Similar Messages

  • I need to Integrate microsoft outlook with java application

    I need to integrate outlook express with java application
    can anyone help how should i proceed with that
    Thanks in advance

    I'm not sure that there is a generically understood
    meaning for the word. Why do people enjoy being nasty
    on these threads? I was just trying to get some more
    info to help the guy out. Aren't these forums around
    to help solve problems? Why not be positve?the humorous remark was not directed at you, but merely a commentary on the sheer magnitude of obtuse questions received here. i think it is positive, because it may enlighted those who intend to ask questions to better formulate theirs before submitting.

  • Ok I have an fully upgraded iPad 2 and the volume button don't work but it do with headphones can someone help

    Ok I have an fully upgraded iPad 2 and the volume button don't work but it do with headphones can someone help. I try to go to settings and the volume won't go up there either I have the home button gesture and still the same. I try resting my iPad and nothing no sound work unless I have my headphones in. Do anybody know how to fix this

    Did you try rebooting the iPad? You will need to have some battery power for this.
    Reboot the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons.
    This may be helpful
    iPhone, iPad or iPod touch: Not responding or does not turn on
    Frozen or unresponsive iPad - Apple
    iPad: Unable to update or restore

  • Hi, How do I communicate CANopen device with anyother CAN device? What things needs to be made compatible with 2 CAN devices to communicate?

    Hi,
    I have to communicate CANopen device with other CAN device which uses GMLAN. 
    So in general, How do I communicate CANopen device with anyother CAN device?
    What things needs to be made compatible with 2 CAN devices (i.e, one is CANopen and anyother CAN device) to communicate?
    Please reply.
    Thanks,
    Najmu

    Hello,
    The two devices need to be connected with a CAN cable and while carrying out the communication, one device should be the master and the other should be the slave. Also you should maintain the same protocol (Baud rate, Arbitration ID etc.) at the two devices. 
    Regards
    Akshat Jain

  • I have an iPhone 4 with iso6, can someone tell me where i find siri? how does this siri work?

    I have an iPhone 4 with iso6, can someone tell me where i find siri? When i hold in my home key, voice pops up for contacts or music but i cant figure out Siri??

    Welcome to the Apple Support Communities
    Siri is only supported on the iPhone 4S and 5. If you have an iPhone 4, you can't use Siri. If you have an iPhone 4S or 5, open Settings > Siri and turn it on. Then, hold Home button until Siri shows up

  • What's going on with JAVA, Can't load POGO games?

    Please let me know about JAVA.  I can't get POGO games to load and some chat rooms on other websites won't load ????

    Java 7 updated  for 10.7-10.8
    Released Feb 1, 2013,  fixes 50+ security flaws
    http://www.esecurityplanet.com/patches/oracle-responds-to-java-security-flaws-wi th-50-fixes.html
    Download and install
    https://www.java.com/en/download/faq/java_mac.xml
    For Java versions 6 and below OS X 10.5-10.6 machines
    Apple supplies their own version of Java. For Mac OS X 10.6 and below, use the Software Update feature available under the Apple menu to check that you have the most up-to-date version of Java 6 for your Mac.
    https://www.java.com/en/download/faq/java_6.xml
    Java SE 6 End of Public Updates
    After February 2013, Oracle will no longer post updates of Java SE 6 to its public download sites. We highly recommend downloading and installing Java 7.
    If your considering upgrading OS X from 10.6.8 to 10.8 via AppStore to run Java 7
    Be forewarned no PowerPC based programs or driver software will run any longer.
    Check here BEFORE you upgrade OS X!
    http://roaringapps.com/apps:table
    Alternatives if you must run Java 7
    If Apple disabled Java 6 in 10.6, and you can't upgrade OS X to 10.8, then your pretty much done with Java in OS X because Oracle won't issue updates for Java 6 anymore.
    However you can install Windows 7 and continue to use Java 7+ there until support for Windows 7 ends in 2020.
    Windows in BootCamp or Virtual Machine?
    If your on 10.6, I very highly recommend the free Virtualbox for the virtual machine software as it gets updates, VMFusion and Parallels have moved on with only 10.7+

  • I have a galexy prevail 3g I need to download an adobe flash player can someone help please

    I need help to find an adobe flash player for galexy prevail  3g

    Hi Greg,
    I don't know what's wrong with that link, on Firefox/Waterfox I get this
    On Internet Explorer it shows
    I will try later today on a different location/network.

  • When opening my lightroom 5- It pops up Lightroom encountered an error when reading its preview Cache and needs to quit.... Can someone walk me through the steps!?

    Opening my lightroom 5.. I get a message that Lightroom encountered an error when reading its preview Cacge and needs to quit.
    Can someone walk me through the steps. Im dealing with MAC computer

    Go to the folder containing your catalog and delete the folder with the extension .lrdata. Then start Lightroom, and it will begin creating a new cache file.
    If you need to know where the files are: Preference and other file locations in Lightroom 5

  • I am using MacBook Pro OS 10.6.8. I need a compatible CD/DVD burner. Can someone recommend one?

    Can someone recommend a compatible CD/DVD burner for a MacBook Pro? I have returned two burners, so far, that were not compatible,.

    LowLuster wrote:
    The Apple external DVD drive will NOT work on a Mac computer that originally came with a built in DVD drive. They only work on Mac computers that did NOT originally come with a built in DVD drive. The Air, Retina and iMacs from late 2012 to present.
    True to the extent that out of the box they indeed will not work with Macs other than Airs and Retinas.  However a minor modification WILL make them compatible with other Macs.  Here are the instructions:
    http://www.tuaw.com/2012/04/02/use-the-macbook-air-superdrive-with-any-almost-ma c/
    Thus it is a valid choice for consideration.
    Ciao.

  • Im new to java can someone please help me with external method calls

    I have only been doing java for a couple of months using bluej, I really dont understand external method calls, this is for an assignment and i have managed the bulk of the code, ineed to make external calls to the other classes to return and input data.
    this is the code i have writen so far.
    class CD
    // The fields.
    public Artist performer;
    private String album;
    private String genre;
    private int numberOfTracks;
    private int yearReleased;
    *Please enter CD details, text entry requires quote marks "Greatest Hits"
    public CD (String album_Name){
    album = album_Name;
    numberOfTracks = 0;
    yearReleased = 0;
    performer = new Artist();
    /**blank constructor*/
    public CD ()
    {album = "";
                genre = "";
                numberOfTracks = 0;
                yearReleased = 0;
                performer = new Artist();}
    * accessor methods
    /** method to return album details to the output window*/
    public void print_albumDetails(){
    System.out.println("Album: " + album);
    System.out.println("Genre: " + genre);
    System.out.println("Number of Tracks: " + numberOfTracks);}
    /** accessor method to return the name of the album*/
    public String show_album(){
    return album;}
    /** accessor method to show artist details from artist class*/
    public void print_details(){
    performer.print_details();}
    * mutator methods
    /** mutator method to change album name please enter name with quotes*/
    public void change_album(String newAlbum){
    album = newAlbum;}
    /**mutator method for adding the album year and checking it correct
    * please enter a year between 1900 and 2005*/
    public void album_year (int year){
    if ((year < 1900) || (year > 2005))
    System.out.println("sorry the year is incorrect please enter a year between 1900 and 2005");
    else yearReleased = year;}
    /** mutator method to alter the number of tracks and check if the ammount is greater
    * than zero*/
    public void change_Number_Of_Tracks(int no_Of_Tracks){
    if (no_Of_Tracks > 0)
    numberOfTracks = no_Of_Tracks;
    else System.out.println("you have not entered a correct number");}
    /** mutator method to change the genre and check it has been entered correctly
    * Please enter 1 for Soul
    * 2 for Blues
    * 3 for Jazz*/
    public void change_Genre(int Change_Genre){
    if ((Change_Genre <= 0) || (Change_Genre > 3)){
    System.out.println("You have not entered the correct available genres");
    System.out.println("which are 1 for Soul,2 for Blues or 3 for Jazz");}
    else if (Change_Genre == 1)
    genre = "Soul";
    else if (Change_Genre == 2)
    genre = "Blues";
    else if (Change_Genre == 3)
    genre = "Jazz";
    to this i need to add an external call to the class Artist to be able to enter firstname and second name, I know that external calls use dot notation
    and the instance of Artist is called performer but i cant get the call to these methods in the Artist class to work
    Artist class
    /** mutator method to change or add artist first name, remember to add quotes*/
    public void cName(String name){
    firstname = name;}
    /** mutator method to change or add artist surname remember to add quotes*/
    public void csurName(String surname){
    lastname = surname;}
    can some please give me some help

    Also, if you can't get them to work, what is the error message you are getting?
    Baron Samedi

  • Pretty new to Java can someone please help with an addObject() problem?

    Hi I'm pretty knew to programming and I have an assignment which I've been working on but I am stuck
    I have to create a 'space invaders' style game, and I've got some basics working. I wanted to add a boss enemy, which appears when all other enemies have been destroyed. It kind of works, only the program spawns a seemingly infinite amount of the boss which then creates a 'wipe' effect across the top of the screen.
    Here is my code:
    import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
    import java.util.List;
    public class Space extends World
    * Constructor for objects of class Space.
    public Space()
    // Create a new world with 200x250 cells with a cell size of 3x3 pixels.
    super(200, 250, 3);
    //add class with starstreaks
    addObject(new EmptyBox(),1,1);
    //add player character
    addObject(new Player(), 100, 228);
    //add 4 romulan enemies row 1
    for(int i=0; i<4; i++){
    addObject(new Romulan(), (25 + 50 * i), 15);
    //add 3 klingon enemies row 2
    for(int i=0; i<3; i++){
    addObject(new Klingon(), (50 + 50 * i), 40);
    //add 4 romulan enemies row 3
    for(int i=0; i<4; i++){
    addObject(new Romulan(), (25 + 50 * i), 65);
    //add 3 klingon enemies row 4
    for(int i=0; i<3; i++){
    addObject(new Klingon(), (50 + 50 * i), 90);
    //add 3 shields
    for(int i=0; i<3; i++){
    addObject(new Shield(), (30 + 70 * i), 180);
    *public void act(){*
    List<Enemy> enemies = getObjects(Enemy.class);
    *if(enemies.size()==0 ){*
    addObject(new Borg(), 100, 30 );
    I believe the part in bold is the problem, but I dont know why. Klingon and Romulan are subclasses of the Enemy class. The Borg class is it's own seperate class, but with the exact same functions as Enemy. I made it seperate as I figured it would keep respawning if it was a subclass of Enemy.
    Any ideas?

    Its ok, after more than an hour I've got it.
    I simply added private int bossValue = 0; at the beginning and then changed act to this:
    public void act(){
    List<Enemy> enemies = getObjects(Enemy.class);
    if(enemies.size()==0 && bossValue==0 ){
    //for(int i=0; i<1; i++){
    addObject(new Borg(), 100, 30 );
    bossValue =1;
    }

  • Logic Pro 9 will not load because it needs Pro Application Support version 5.0 Can someone help?

    I have Logic Pro 9.1.4  When I attempt to open the application, I get the following message: 
    Wrong Pro Application Support version installed.  This version of Logic Pro requires Pro Application Support 5.0 (883.0) or newer.  ProKit: 722.0 (OS BUILD 9L31a)  I have tried to find Pro Application Support 5.0 as a download or update without success. I am currently on a MacBook Pro running OS 10.5.8  Any help here would be appreciated!
    Thanks

    Hi Ana,
    This is it.  Once I installed, Logic opened fine.
    I do have another question.  After updating Logic Studio, I now have both Logic Pro 9.0 and 9.1.4 and Logic Node 9.0 and 9.1.4  Do I need both of these on my hard drive?  Can I delete the 9.0 version?
    Thanks!
    David

  • XML driven FLV player with playlist, can someone please help me?

    OK so ive been working for a client recently building him a new site for his racing team and he wants a video jukebox on the "videos section" of the site.
    Now i am the one with the job of updating this jukebox with new videos which he makes (this happens often) so i want updating to be as easy as possible.
    Im new to the use of XML with flash and followed a tutorial to create a dynamic Image Gallery which is really easy to update, all i have to do is drop the files into the right directories in my FTP client and edit the XML file, perfect.
    I want the jukebox to do the same thing.
    I want to have a jukebox with a "video screen" with basic controlls (play/pause, volume, rewind, seek) on the left and a small vertically scrolling menu on the right that contains thumbnails and descriptions of the videos that when clicked changes the content of the video component to play the chosen video.
    I found a tutorial on the adobe site that shows how to achive this through the use of the "video component" and the "list component" in flash 8 HOWEVER, this isnt very pretty and almost impossible to customise due to the list component and i would like to be able to mimic the style of the image gallery i already produced to keep things all nice and uniform.
    i want to use XML to point flash to the source of the FLV files, the source of the thumbnail jpgs and give the text for the description so that its easy to update and use flash's drawing interface to make it pretty.
    Basically i want to reproduce something like this.
    Ive been searching for weeks now and i cant find anything to help me with this, if anyone knows of any tutorials, books, videos or has any idea how to help me it would be MUCH appreciated.
    Thankyou.

    Try this link:
    http://www.taiwantrade.com.tw/MAIN/en_front/searchserv.do?method=listProductComp anyDetail&company_id=163054&locale=2
    There is an email address and telephone numbers.
    Also look on the box and instructions.
    Ciao.

  • Issue with wallpaper, can someone help?

    Hello all. I found a wallpaper that someone posted on reedit that I wanted to use. It is a 1920x1080 resolution wallpaper. When I try to set the wallpaper, sometimes it won't let me crop it correctly, and only allows me to select a small portion of the photo. Other times I'm able to properly crop it, but then after I lock the screen and wake it back up, the picture is blown up and only displays part of the picture. Has anyone encountered this before? And if so, is there a fix?
    Solved!
    Go to Solution.

    On a side note, I'm not amused by your last private message but as a great person said before
    "I do not agree with what you have to say, but I'll defend to the death your right to say it."
    "I'd rather be hated for who I am, than loved for who I am not." Kurt Cobain (1967-1994)

  • I need for Pinnacel's dc10plus instrument driver.Can someone help me please? thanks

    I asked for it at pinnacle and NI but iìm still attending for question.

    Are you running OS 10.1.x on your iMac?
     Cheers, Tom

Maybe you are looking for

  • HT3131 can i turn my computer on and off in clamshell mode will useing with a thurderbolt display?

    I have an early 2011 mackbook pro 17inch and love using it in clamshell mode with my thunderbolt display.  Is there a way to turn power on and off with a thunderbolt display? regards, floyd.

  • Message mapping transformation error for RFC calls

    Hi, I am having a weird problem. recently client migrated the server and we started getting all possible errors in XI which we are able to fix. Now we have a strange problem in quality system alone where the bapi calls are made from QA11 and MIGO. Th

  • Oracle Receiving (Purchasing) Interface

    Has anyone implemented this and/or can point me in right direction for documenation? null

  • Data in UDF disappears

    Hello, Since three weeks we are using SAP 9.0 PL8. Could someone explain, after I entered a code in a UDF, why this code disappears. This code (code scannen) is a short article number which shows the original article code by using a FMS. In version 8

  • Aperture 3.1.2 untag faces

    Hello everyone. I would like to untag some persons in my Aperture library. Is it possible to remove the "faces" tag from persons? As well as be able to put them in the "skip" list so that they don't appear all the time as unknown faces. People I took