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
What tag pair is used to link web page documents to each other?
V125BC [204]
<span><BODY> …</BODY>
It identifies the document's body area, which contains the Web page contents that appear in the browser window.
Hope this is the answer you are looking for.</span>
8 0
4 years ago
/****************************************************************************** [25 points] Exercise #3.29, p. 115: write a prog
Gemiola [76]

your have no luck here

Explanation:

8 0
4 years ago
How are the chart and tables are alike
aleksley [76]

Charts present information in graphs, diagrams and/or tables. ... better than one, if each graph shows a different aspect of the same data set.

6 0
3 years ago
Select the statements that identify benefits of programming design. Choose all that apply. It ensures that programmers working o
scoundrel [369]

Answer:

The answer is "Option i, iii, and iv"

Explanation:

The software design is a sequence of code, which is used to aggregate, calculating the efficiency of a common issue in software development within the same specific scenario.

  • It's also not a finished specification, that can be immediately translated into the origin of machine language code.
  • These testing aims to detect a list of steps on a machine, which is often used to solve a certain problem and optimize the performance of a task which is just as complicated as a corporate structure.
6 0
3 years ago
FOR A BRAINLIEST
Ludmilka [50]

A sample word problem to calculate the volume and surface area of a three-dimensional object would be: "A logistics company has a wide area that is 300m^2 and has a parking space that is 50m in height and is 12 feet long. Find the volume of the parking space"

<h3>What is a Word Problem?</h3>

This refers to the use of words that describes a real scenario that would lead to a mathematical calculation.

Hence, to make a sample word problem based on the given description, the above description should be helpful, and remember that \pi is 3.142 when doing your calculations.

Read more about word problems here:

brainly.com/question/13818690

#SPJ1

7 0
2 years ago
Other questions:
  • These things are commonly found on the front of desktop computer cases:
    12·1 answer
  • What is the area of a triangle whose base is 14 m and whose height is 22 m?
    7·1 answer
  • Write a function called matches that takes two int arrays and their respective sizes, and returns the number of consecutive valu
    6·1 answer
  • Micheal has increased the contrast of the given picture. Which feature or menu option of a word processing program did he use? A
    15·1 answer
  • A general-use dimmer switch is required to be counted as ? where installed in a single-gang box on a circuit wired with 12 awg c
    8·1 answer
  • Which alignment aligns text to the left and right side margins?
    15·1 answer
  • List three types of Software:
    15·1 answer
  • Write a simple algorithm in pseudocode that asks the user their favourite colour and then agrees with their choice, quoting the
    15·1 answer
  • Speed and security are advantages generally associated with<br> networks.
    9·1 answer
  • ASAP PLEASE the online research you did to describe how Senet is related to the culture and historical period when it was create
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!