1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Vlad1618 [11]
3 years ago
14

Write a program that demonstrates the skills we've learned throughout this quarter. This type of project offers only a few guide

lines, allowing you to invest as much time and polish as you want, as long as you meet the program requirements described below. You can write a simple game (e.g., tic-tac-toe, Battleship), a simulation (e.g., a zero-dimensional energy balance model of the climate), or an application (e.g., a mortgage calculator). Your main requirement is that you demonstrate six of the following features in your software program and that you comment and document your code well:
Computers and Technology
1 answer:
UNO [17]3 years ago
5 0

This type of project offers only a few guidelines, allowing you to invest as much time and polish as you want, as long as you meet the program requirements described below.

The code given below is tic-tac-toe

Explanation:

import java.util.Arrays;

import java.util.InputMismatchException;

import java.util.Scanner;

public class TicTacToe {

static Scanner in;

static String [ ] board;

static String turn;

public static void main(String[] args) {

 in = new Scanner(System.in);

 board = new String[9];

 turn = "X";

 String winner = null;

 populateEmptyBoard();

 System.out.println("Welcome to 2 Player Tic Tac Toe.");

 System.out.println("");

 printBoard();

 System.out.println("X's will play first. Enter a slot number to place X in:");

while (winner == null) {

  int numInput;

  try {

   numInput = in.nextInt();

   if (!(numInput > 0 && numInput <= 9)) {

    System.out.println("Invalid input; re-enter slot number:");

    continue;

   }

  } catch (InputMismatchException e) {

   System.out.println("Invalid input; re-enter slot number:");

   continue;

  }

  if (board[numInput-1].equals(String.valueOf(numInput))) {

   board[numInput-1] = turn;

   if (turn.equals("X")) {

    turn = "O";

   } else {

    turn = "X";

   }

   printBoard();

   winner = checkWinner();

  } else {

   System.out.println("Slot already taken; re-enter slot number:");

   continue;

  }

 }

 if (winner.equalsIgnoreCase("draw")) {

  System.out.println("It's a draw! Thanks for playing.");

 } else {

  System.out.println("Congratulations! " + winner + "'s have won! Thanks for playing.");

 }

}

static String checkWinner() {

 for (int a = 0; a < 8; a++) {

  String line = null;

  switch (a) {

  case 0:

   line = board[0] + board[1] + board[2];

   break;

  case 1:

   line = board[3] + board[4] + board[5];

   break;

  case 2:

   line = board[6] + board[7] + board[8];

   break;

  case 3:

   line = board[0] + board[3] + board[6];

   break;

  case 4:

   line = board[1] + board[4] + board[7];

   break;

  case 5:

   line = board[2] + board[5] + board[8];

   break;

  case 6:

   line = board[0] + board[4] + board[8];

   break;

  case 7:

   line = board[2] + board[4] + board[6];

   break;

  }

  if (line.equals("XXX")) {

   return "X";

  } else if (line.equals("OOO")) {

   return "O";

  }

 }

 for (int a = 0; a < 9; a++) {

  if (Arrays.asList(board).contains(String.valueOf(a+1))) {

   break;

  }

  else if (a == 8) return "draw";

 }

 System.out.println(turn + "'s turn; enter a slot number to place " + turn + " in:");

 return null;

}

static void printBoard() {

 System.out.println("/---|---|---\\");

 System.out.println("| " + board[0] + " | " + board[1] + " | " + board[2] + " |");

 System.out.println("|-----------|");

 System.out.println("| " + board[3] + " | " + board[4] + " | " + board[5] + " |");

 System.out.println("|-----------|");

 System.out.println("| " + board[6] + " | " + board[7] + " | " + board[8] + " |");

 System.out.println("/---|---|---\\");

}

static void populateEmptyBoard() {

 for (int a = 0; a < 9; a++) {

  board[a] = String.valueOf(a+1);

 }

}

}

You might be interested in
As marketing manager, you need to have ( blank) skills and (blank) skills.
andrew-mc [135]

Answer:

Leadership skills

Technical skills

Organizational skills

Communication skills

Creative skills

Explanation:

8 0
3 years ago
A(an) _______ is a set of instructions that a computer follows to perform a task.
Vikentia [17]
A(an) _______ is a set of instructions that a computer follows to perform a task.Answer is Program .
I hope the answer of the question.
7 0
4 years ago
Jack lost all the data he saved on his desktop because of a power outage while working on a presentation on which of these compu
Alchen [17]
The hard drive should have saved his data.
5 0
3 years ago
Read 2 more answers
An initialization expression may be omitted from the for loop if no initialization is required.
stealth61 [152]

Answer:

True

Explanation:

for loop is used to repeat the process again and again until the condition not failed.

syntax:

for(initialize; condition; increment/decrement)

{

    Statement

}

But we can omit the initialize or condition or increment/decrement as well

the syntax after omit the initialization,

for( ; condition; increment/decrement)

{

    Statement

}

The above for loop is valid, it has no error.

Note: don't remove the semicolon.

You can omit the condition and  increment/decrement.

and place the semicolon as it is. If you remove the semicolon, then the compiler show syntax error.

5 0
4 years ago
True or False: if there are multiple operations inside a parentheses, you do not need to complete theses in the order of pemdas​
damaskus [11]

I believe this is false.

Happy to help.

5 0
4 years ago
Other questions:
  • Ideation includes all of the following EXCEPT
    5·1 answer
  • When reading data across the network (i.e. from a URL) in Python 3, what string method must be used to convert it to the interna
    9·1 answer
  • To collect data using Google Analytics, which steps must be completed? (select all answers that apply)
    9·1 answer
  • Visual images taken directly from a source, such as pictures, charts, and graphs do not need a citation. true or false.
    8·1 answer
  • Dead state is the name of the time delay in a cpu caused by differences between the speed of the cpu and ram.
    15·1 answer
  • In what order does the Cascade look at factors to determine which CSS rule to follow?
    14·1 answer
  • 50 POINTS
    6·1 answer
  • Does anybody know how to fix my Minecraft??? My character isn’t loading and realms aren’t working?? Look at the picture!
    5·1 answer
  • I really need help in this!!!
    11·1 answer
  • Vector images take up much less space when saved to a computer or storage device because computers and storage devices just need
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!