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
Code the function definition for aNonclassFunction, picking up co. aNonclassFunction has no return value.
enot [183]

Answer:

b)void aNonclassFunction (Banana co);

Explanation:

In the function definition you have to pass the tell the function which type of argument it is taking.In our case we are taking a variable co of Banana type passing it to the function named aNonclassFunction having no return type.

So the definition will be like this.

void aNonclassFunction (Banana co);

6 0
3 years ago
what is created when the movement of light is blocked by an object and cannot pass through the other side?
larisa86 [58]
A shadow is created.
7 0
3 years ago
Read 2 more answers
A personal identification number (PIN) that opens a certain lock consists of a sequence of 3 different digits from 0 through 9,
Elan Coil [88]

Answer:

<u>720</u> possible PIN can be generated.

Explanation:

To calculate different number of orders of digits to create password and PIN, we calculate permutation.

Permutation is a term that means the number of methods or ways in which different numbers, alphabets, characters and objects can arranged or organized. To calculate the permutation following formula will be used:

nPr = n!/(n-r)!

there P is permutation, n is number of digits that need to be organize, r is the size of subset (Number of digits a password contains)

So in question we need to calculate

P=?

where

n= 10   (0-9 means total 10 digits)

r= 3     (PIN Consist of three digits)

So by using formula

10P3 = 10!/(10-3)!

        =10!/7!

        = 10x9x8x7!/7!

        = 10x9x8

        = 720

7 0
3 years ago
Where is the spell checker found in excel?
fenix001 [56]
Except keyboard of F7 and Spell Checkbutton in toolbar, you are also able to apply Spelling check command fromExcel 2007/2010/2013/2016 Ribbon: Click the Review tab; Go to Proofing group; Then you will view the Spellingbutton , that's Spell Check command.



hope this helps
5 0
4 years ago
Read 2 more answers
The faster data transfer port for computer today is port
qwelly [4]

USB Type C or 3.0/3.1 is the fastest

8 0
3 years ago
Other questions:
  • Windows Live SkyDrive is an example of _____ storage.
    13·1 answer
  • Is it necessary that every autonomous system use the same intra-AS routing algorithm? Why or why not?
    10·1 answer
  • What should a password policy contain to reduce a hackers ability to crack the passwords?
    10·1 answer
  • Which option should you select to ignore all tracked changes in a document? To ignore all tracked changes in a document, you sho
    15·2 answers
  • How do i know when someone answered my questions and where can i check what they wrote?
    6·1 answer
  • A blue NFiPA label indicates: A) Health Hazard B) Special information C) Flammability D) Reactivity
    6·2 answers
  • Can anyone fill in the space please
    6·1 answer
  • Xercise 1<br>1.<br>What is system? Explain the components of system in brief.​
    12·1 answer
  • Does anyone have 2.19.4 Guess a number 2.0 code for codehs?
    8·1 answer
  • Most case fans have standard _______________ connectors that are easy to plug in but can be forced to be connected the wrong way
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!