Hi all, I am learning the basic of Java and got some question of my homework. he
ID: 3620666 • Letter: H
Question
Hi all, I am learning the basic of Java and got some question of my homework. here is the problem:I just start learning how to use classes so I am not really familiar with how to access data back and forward , need some help ,there are two classes in this program in different file, I've copied all " getString()" into the main method and display it to test if it work, but now I am stuck with
1. question How can I access arraylist for each object such as " Kobe Byran" for the alphabetical sort .
2. question , how can I use split method to break apart for the array?
HOMEWORK QUESTION: Player Class: The Player Class consists of at least two elements -- the player name and a list of scores for games. The score attribute is not used in Program & but will be needed in Program *. Include in the class appropriate accessor and mutator methods for each element in the class. You may have other attributes if needed. Team Class: The Team class consists of at least 6 elements -- the name of the team and five players from the Player class. Include in the class appropriate accessor and mutator methods for each element in the class. You may have other attributes if needed.
Input3 class: The Input3 class is provided for you. The Input3 class supplies data for your program. The Input3 class has a public method called getNextString, which returns a string with the input for your program, one after the other. You must use this class to get the data for your program. See Input3.java on eLearning to understand the class construction. Your program should display the roster of each team in alphabetical order by last name.
and here is my code
import java.util.ArrayList;
public class TeamClass
{
public static void main(String[] args)
{
String passarray;
String Stored;
for(int i=0;i<=17;i++)
{
input3 name= new input3();
passarray = name.getNextString();
Stored = passarray;
ArrayList testList=new ArrayList();
testList.add(Stored);
System.out.println(testList);
}
and the given program is
import java.util.StringTokenizer;
public class input3 //class
{
public String[] input = new String[40];
public static int StringNum = -1;
public static final int NUMBER_OF_TEAMS = 3;
public static final int NUMBER_OF_PLAYERS = 5;
public input3() //method
{
//The first six inputs will be for the first team
input[0] = "LAKERS";
input[1] = "Kobe Bryant";
input[2] = "Derek Fisher";
input[3] = "Shaquille O'Neal";
input[4] = "Karl Malone";
input[5] = "Brian Cook";
//The next six inputs will be for the second team
input[6] = "MAVERICKS";
input[7] = "Antoine Walker";
input[8] = "Dirk Nowitzki";
input[9] = "Tony Delk";
input[10] = "Shawn Bradley";
input[11] = "Travis Best";
//The next six inputs will be for the third team
input[12] = "KNICKS";
input[13] = "Mike Sweetney";
input[14] = "Allan Houston";
input[15] = "Howard Eisley";
input[16] = "Kurt Thomas";
input[17] = "Shanon Anderson";
}
//This method returns the strings one after the other.
public String getNextString()
{
StringNum++;
return input[StringNum];
}
}
}
} HOMEWORK QUESTION: Player Class: The Player Class consists of at least two elements -- the player name and a list of scores for games. The score attribute is not used in Program & but will be needed in Program *. Include in the class appropriate accessor and mutator methods for each element in the class. You may have other attributes if needed. Input3 class: The Input3 class is provided for you. The Input3 class supplies data for your program. The Input3 class has a public method called getNextString, which returns a string with the input for your program, one after the other. You must use this class to get the data for your program. See Input3.java on eLearning to understand the class construction.
Explanation / Answer
You can create a Comparator to alter the ordering of the sorting.Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.