C# help with this code... public class Game { public Game(int numPlayers, int nu
ID: 3602824 • Letter: C
Question
C# help with this code...
public class Game {
public Game(int numPlayers, int numRounds) {
/*Game's constructor. This is called with the number of players in the game and the number of rounds that will be played. This method:
+Creates a numPlayers size array of TankController (which is stored as a private field of Game)
+Sets another private field to the number of rounds that will be played
+Creates an array or list collection of Attack (if it's an array, a suitably large array should be created for it, e.g. 100).
No objects of type TankController or Attack should be created here; only the arrays.
-numPlayers will always be between 2 and 8 (inclusive)
-numRounds will always be between 1 and 100 (inclusive)*/
}
public void CreatePlayer(int playerNum, TankController player) {
This method takes a player number (guaranteed to be between 1 and the number of players) and sets the appropriate field in Game's TankController array to player. Note that the value of playerNum is indexed from 1 while arrays are indexed from 0, so CreatePlayer() will need to account for this.
}
public TankController GetPlayerNumber(int playerNum){
//This method takes a player number (playerNum, between 1 and the number of players) and returns the appropriate TankController from the TankController array. Again, note that arrays are indexed from 0 while playerNum is indexed from 1.
}
}
Explanation / Answer
import java.io.File;
importjava.io.IOException;
import java.util.Scanner;
public class SpellCheck {
public static void main(String[] args) throwsIOException {
Scanner dictionary = new Scanner(newFile(args[0]));
Scanner size = dictionary;
int numWords = 0;
while (size.hasNext()) {
numWords++;
size.next();
}
int count = 0;
String[] words = newString[numWords];
while (dictionary.hasNext()) {
words[count] =dictionary.next();
count++;
}
System.out.println("What file doyou wish to spell check? Or type quit when done.");
Scanner document = newScanner(System.in);
String w = document.next();
String [] mispelled = new String[10];
while (!w.equalsIgnoreCase("quit")){
Scanner in = newScanner(new File(w));
int j;
while (in.hasNext()){
Stringword = in.next();
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.