473,395 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Please can someone help me with this program

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.
Nov 24 '06 #1
2 1580
Expand|Select|Wrap|Line Numbers
  1. public class PlayerRating {
  2.  
  3.     Player[] players = new Player[] 
  4.         {
  5.             new Player("Mickey Mantle", 5),
  6.             new Player("Ty Cobb", 3),
  7.             new Player("Babe Ruth", 4),
  8.             new Player("Pete Rose", 3),
  9.             new Player("Sammy Sosa", 1)
  10.         };    
  11.  
  12.     class Player {
  13.         String name = null;
  14.         int rating = 0;
  15.         Player(String n, int r) {
  16.             name = n;
  17.             rating = r;
  18.         }
  19.         public String toString() {
  20.             return name + "    " + rating; 
  21.         }
  22.     }
  23.  
  24.     public static void main(String[] args) {
  25.         PlayerRating pr = new PlayerRating();
  26.         System.out.println("\n\nUnsorted");
  27.         pr.playerDisplay();
  28.  
  29.         System.out.println("\n\nSorted by Name");
  30.         pr.bubbleSortName();
  31.         pr.playerDisplay();
  32.  
  33.         System.out.println("\n\nSorted by Rating");
  34.         pr.bubbleSortRating();
  35.         pr.playerDisplay();
  36.  
  37.     }
  38.  
  39.     void playerDisplay() {
  40.         System.out.println("Name   Rating");
  41.         for(int i=0; i<players.length; i++) {
  42.             System.out.println(players[i]);
  43.         }
  44.     }
  45.  
  46.     void bubbleSortRating() {
  47.         Player temp = null;    
  48.         int len = players.length;
  49.         for (int i = len - 1; i >= 0; i--) {
  50.             for (int j = 1; j <= i; j++) {
  51.                if (players[j-1].rating > players[j].rating) {
  52.                     temp = players[j-1];
  53.                     players[j-1] = players[j];
  54.                     players[j] = temp;
  55.                 }
  56.             }
  57.         }
  58.     }
  59.  
  60.     void bubbleSortName() {
  61.         Player temp = null;    
  62.         int len = players.length;
  63.         for (int i = len - 1; i >= 0; i--) {
  64.             for (int j = 1; j <= i; j++) {
  65.                String name_a = players[j-1].name;
  66.                String name_b = players[j].name;
  67.                int cmp = name_a.compareTo(name_b);
  68.                if (cmp >= 0) {
  69.                     temp = players[j-1];
  70.                     players[j-1] = players[j];
  71.                     players[j] = temp;
  72.                 }
  73.             }
  74.         }
  75.     }
  76. }
  77.  
you can check the bubble sort algo at this site http://linux.wku.edu/~lamonml/algor/sort/bubble.html
Nov 25 '06 #2
Ganon11
3,652 Expert 2GB
You know, the man asked for help, not for you to write his program for him. That's called cheating in academic circles.

shblack, if you need some advice or guidance on where to go from this problem, please PM me, and I'd be glad to assist you.
Nov 26 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Michael Lauzon | last post by:
A while back, I had a program that I was working on, while taking Java in a Web Design & Development course -- this was back in 1999 -- not having the mindset of a programmer I failed that part of...
8
by: kittykat | last post by:
Hi, could someone please check my code? its asking the user to enter 3 letters, and check to see if these letters exist in the text file. i know ive done something wrong. can someone fix my code...
5
by: jalkadir | last post by:
Can someone please explain to me why, if I type 'Ni(ALT-164)A' at the windows prompt, I get 'Niña', but if my program does this: int main(){ std::string str("Niña"); std::cout << str <<...
6
by: darren112 | last post by:
Hi Im new to python and I desperately need help with this task.... This is everything of what I need to do....... The program to be written in Python obviously...... The program should support...
5
by: johnlim20088 | last post by:
Hi SOMEONE PLEASE HELP ME I have a vb net program to call localhost http://localhost/hi.aspx, my page work FINE when I browse it, but when I call it through vb net program it return error ...
5
by: weidongtom | last post by:
Hi, I tried to implement the Universal Machine as described in http://www.boundvariable.org/task.shtml, and I managed to get one implemented (After looking at what other's have done.) But when I...
1
by: Programmar | last post by:
Hello. I'm new here and was wondering if someone could help me with a program i have in mind. Its not really anything serious, just a bit of fun. If someone could explain or make a program that keeps...
6
by: fido19 | last post by:
Once upon a time, there lived a chimpanzee called Luycha Bandor (aka Playboy Chimp). Luycha was unhappily married to Bunty Mona, a short but cute little lady chimp. Luycha was tall and handsome –...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.