Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5. Display game board in table format with player\'s intial for each slot. The t

ID: 3729370 • Letter: 5

Question

5. Display game board in table format with player's intial for each slot. The team1 scores should be column headers. Ask the user to put each quarter scores and system shoukld show the winner for each quarter.

//In java

Your program will generate superball box game board. 1. There should be 10 (rows) x 10(columns) board which will have 100 slots. You should use two dimensional ArrayList. 2. Read 20 people's initials (two letters for each name) from file (names.txt) and store their names into ArrayList or LinkedList. You should not have duplicate names. 3. Each person should be assigned to 5 random slots in the board. Each slot can only be assigned with one person. You must use the random method from java.util.Collections object. If the random slot is already occupied by other player, you need to move to next random slot.

Explanation / Answer

Answer of 1 to 4 :

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.io.File;

import java.util.Scanner;

import java.util.Random;

class gamebox

{

static public ArrayList<ArrayList<String>> gameBoard = new ArrayList<ArrayList<String>>(); //Answer 1

static public ArrayList<String> peopleList = new ArrayList<String>();

static public ArrayList<Integer> teamScore= new ArrayList<Integer>();

public static void insertObjects()

{

for (int rowNum = 0; rowNum != 9; rowNum++) {

ArrayList<String> ArrayList<String>();

gameBoard.add(rowNum, oneRow);

for (int columnNum = 0; columnNum != 9; columnNum++)

{

oneRow.add(columnNum,"");

}

}

}

public static boolean assignSlot(int slot,String name)

{

int counter=0;

for (int rowNum = 0; rowNum != 10; rowNum++)

{

for (int columnNum = 0; columnNum != 10; columnNum++)

{

if(counter==slot)

{

if(gameBoard.get(rowNum).get(columnNum)!=name)

{

gameBoard.get(rowNum).add(columnNum,name);

return true;

}

else

{

return false;

}

}

counter++;

}

counter++;

}

return false;

}

public static void assignScore()

{

for (int rowNum = 0; rowNum != 1; rowNum++)

{

Random rnd = new Random(9);

int score = rnd.nextInt();

if(rowNum==0)

{

teamScore.add(rowNum,rnd.nextInt());

}

else

{

int newScore = getScore(rowNum,score);

teamScore.add(rowNum,newScore);

}

}

}

public static int getScore(int index,int score)

{

while(teamScore.get(index)!=score)

{

Random rnd = new Random(9);

score = rnd.nextInt();

}

return score;

}

  

// answer 5 display game board in table format

public static void DislayGameBoard()

{

for (int rowNum = 0; rowNum != 10; rowNum++)

{

for (int columnNum = 0; columnNum != 10; columnNum++)

{

System.out.print(gameBoard.get(rowNum).get(columnNum) +" ");

}

System.out.println();

}

}

  

  

public static void main(String[] args)

{

insertObjects();

//Answer 2 : read 20 people list

String filename="names.txt";

try

{

File file = new File("filename");

Scanner sc = new Scanner(file);

while (sc.hasNextLine())

{

String line = sc.nextLine();

if(line!="")

{

String[] name = line.split(" ");

String nameInitial = name[0].substring(0,1) +name[1].substring(0,1);

if(!peopleList.contains(nameInitial))

{

peopleList.add(nameInitial);

}

}

}

// answer 3 assign 5 slot to each people

Random rand = new Random();

for (String people : peopleList)

{

for(int i=0;i<5;i++)

{

int randomSlot = rand.nextInt(100);

assignSlot(randomSlot,people);

}   

}

  

assignScore();

DislayGameBoard();

  

}

catch(FileNotFoundException ex)

{

ex.printStackTrace();

}

  

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote