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.
2 1580 -
public class PlayerRating {
-
-
Player[] players = new Player[]
-
{
-
new Player("Mickey Mantle", 5),
-
new Player("Ty Cobb", 3),
-
new Player("Babe Ruth", 4),
-
new Player("Pete Rose", 3),
-
new Player("Sammy Sosa", 1)
-
};
-
-
class Player {
-
String name = null;
-
int rating = 0;
-
Player(String n, int r) {
-
name = n;
-
rating = r;
-
}
-
public String toString() {
-
return name + " " + rating;
-
}
-
}
-
-
public static void main(String[] args) {
-
PlayerRating pr = new PlayerRating();
-
System.out.println("\n\nUnsorted");
-
pr.playerDisplay();
-
-
System.out.println("\n\nSorted by Name");
-
pr.bubbleSortName();
-
pr.playerDisplay();
-
-
System.out.println("\n\nSorted by Rating");
-
pr.bubbleSortRating();
-
pr.playerDisplay();
-
-
}
-
-
void playerDisplay() {
-
System.out.println("Name Rating");
-
for(int i=0; i<players.length; i++) {
-
System.out.println(players[i]);
-
}
-
}
-
-
void bubbleSortRating() {
-
Player temp = null;
-
int len = players.length;
-
for (int i = len - 1; i >= 0; i--) {
-
for (int j = 1; j <= i; j++) {
-
if (players[j-1].rating > players[j].rating) {
-
temp = players[j-1];
-
players[j-1] = players[j];
-
players[j] = temp;
-
}
-
}
-
}
-
}
-
-
void bubbleSortName() {
-
Player temp = null;
-
int len = players.length;
-
for (int i = len - 1; i >= 0; i--) {
-
for (int j = 1; j <= i; j++) {
-
String name_a = players[j-1].name;
-
String name_b = players[j].name;
-
int cmp = name_a.compareTo(name_b);
-
if (cmp >= 0) {
-
temp = players[j-1];
-
players[j-1] = players[j];
-
players[j] = temp;
-
}
-
}
-
}
-
}
-
}
-
you can check the bubble sort algo at this site http://linux.wku.edu/~lamonml/algor/sort/bubble.html
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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 <<...
|
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...
|
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
...
|
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...
|
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...
|
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 –...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |