May 3rd, 2014, 09:42 AM
Declare and create a Set of the code of the courses as “Math”, “Physics”, “biology”, “chemistry”, “English”.
Write the code that asks the user to fill codes of the courses in the Set. It should stop if the user entered "stop".
Write the code that prints elements of the Set and the size of the Set.
Write the code that checks whether "math" is an element of the Set or not.
Write the code that sorts the Set then prints the first and the last course in the Set.
Write the code that prints the courses after sorting.
ايضا هذا
The following table represents a part of a list of Players showing various
names with their points.
Name Points
“khaled” 282
“ahmad” 170
“faisal” 190
“ali” 155
This table is to be implemented and managed by an instance of a
class called Player.
(a) Write a class header of the class Player and write a single attribute:
index that will reference a collection suitable forholding the data in table1.
(b) Write a zero argument constructor for Player that initializes index to an
instance of a suitable empty collection class.
(c) Write a public instance method called fill() for the Player class that takes
no arguments and returns no value. This method should simply fill the
index with the data as in the table, it should ask the user to add Players
until he entered Zero as the name of the Player.
(d) Write a public instance method for the Player class called: findPoints
(String name). This method returns the points of the specific name that
are found in the collection .
(e) Write a public instance method for the Player class called printAll().
This method prints the index entries. Use for-each statement.
(f) Write a public instance method for the Player class called average(). This
method returns average of grades of the index entries.
(g) Write Java statements to do the followings
• Declare and create an object called players of Player class.
• Use players object to call fill() method and printAll() method.
• Printout average of players object.
• Printout the points of “faisal”.
May 3rd, 2014, 09:42 AM
Declare and create a Set of the code of the courses as “Math”, “Physics”, “biology”, “chemistry”, “English”.Write the code that asks the user to fill codes of the courses in the Set. It should stop if the user entered "stop".
Write the code that prints elements of the Set and the size of the Set.
Write the code that checks whether "math" is an element of the Set or not.
Write the code that sorts the Set then prints the first and the last course in the Set.
Write the code that prints the courses after sorting.
ايضا هذا
The following table represents a part of a list of Players showing various
names with their points.
Name Points
“khaled” 282
“ahmad” 170
“faisal” 190
“ali” 155
This table is to be implemented and managed by an instance of a
class called Player.
(a) Write a class header of the class Player and write a single attribute:
index that will reference a collection suitable forholding the data in table1.
(b) Write a zero argument constructor for Player that initializes index to an
instance of a suitable empty collection class.
(c) Write a public instance method called fill() for the Player class that takes
no arguments and returns no value. This method should simply fill the
index with the data as in the table, it should ask the user to add Players
until he entered Zero as the name of the Player.
(d) Write a public instance method for the Player class called: findPoints
(String name). This method returns the points of the specific name that
are found in the collection .
(e) Write a public instance method for the Player class called printAll().
This method prints the index entries. Use for-each statement.
(f) Write a public instance method for the Player class called average(). This
method returns average of grades of the index entries.
(g) Write Java statements to do the followings
• Declare and create an object called players of Player class.
• Use players object to call fill() method and printAll() method.
• Printout average of players object.
• Printout the points of “faisal”.