Java Reference
In-Depth Information
Ronaldo
10400
Didier
9800
Pele
9750
Kaka
8400
Cristiano
8000
The constructor should test if the file exists. If it does not exist, then the file should
be created with blank names for each of the players and a score of 0. If the file does
exist, then the data from the file should be read into the class's instance variables.
Along with appropriate constructors, accessors, and mutators, add the following
methods:
void playerScore(String name, int score): Whenever a game is over,
this method is called with the player's name and final score. If the name is one
of the top five, then it should be added to the list and the lowest score should
be dropped out. If the score is not in the top five, then nothing happens.
String[] getTopNames() : Returns an array of the names of the top players,
with the top player first, the second best player second, etc.
int[] getTopScores() : Returns an array of the scores of the top players, with
the highest score first, the second highest score second, etc.
Test your program with several calls to playerScore and print out the list of top
names and scores to ensure that the correct values are stored. When the program
is restarted, it should remember the top scores from the last session.
PROJECTS INVOLVING BINARY FILES
8. Write a program that will search a binary file of numbers of type int and write
the largest and the smallest numbers to the screen. The file contains nothing but
numbers of type int written to the file with writeInt .
9. Write a program that takes its input from a binary file of numbers of type double
and outputs the average of the numbers in the file to the screen. The file contains
nothing but numbers of type double written to the file with writeDouble .
10. Write a program that takes its input from a binary file of numbers of type double .
The file contains nothing but numbers of type double written to the file with
writeDouble . The program outputs to the screen the average and standard devia-
tion of the numbers in the file. The standard deviation of a list of numbers n 1 ,
n 2 , n 3 , and so forth is defined as the square root of the average of the following
numbers:
( n 1 - a ) 2 , ( n 2 - a ) 2 , ( n 3 - a ) 2 , and so forth.
VideoNote
Solution to
Programming
Project 10.8
Search WWH ::




Custom Search