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
Kris, an IT manager at Park Infosystems, is handling four projects simultaneously. Each project has loaned and shared resources
Natalija [7]

Answer:

many-to-many relationship

Explanation:

They are different types of relationship between projects. A many-to-many relationship occurs when a row in a table associates with many related rows in another table. For example the relationship between an employee and a project, An employee can work on many projects and a project can have many employees working on it.

8 0
3 years ago
Read 2 more answers
15:28
nordsb [41]
This question made no sense whatsoever, sorry
3 0
3 years ago
Why do all the people are mean, why report my answer even when it is correct and the reason would i have violated their terms .
Alexxx [7]

Answer:

Sometimes annoying people get bored and decide to report random things for no reason. it sucks. sometimes people accidentally press the report button when they didn't mean to, I did that once and i felt really bad. There should be a "are you sure you want to report this" button when you hit the report button. It would help.

Explanation:

7 0
4 years ago
A Uniform Resource Locator (URL) consists of three separate parts: network protocol, host, and web browser. True False
harkovskaia [24]

Answer:

False.

Explanation:

A URL (Uniform Resource Locator), usually called a web address is a reference to a web resource that specifies its location on a computer network and a mechanism for retrieving it.

The three basic parts of a URL are the network protocol, the domain name/host and the path.

A URL is used in a web browser, and A web browser is not termed as one of its fundamental parts.

6 0
3 years ago
Why are coders using encoder software? What are their advantages and disadvantages? And when might a coder need to use the codin
IrinaVladis [17]
<span>Coders using encoder software:
To enhance their productivity</span><span>
Speed and Efficiency
</span><span>Accuracy and consistency
</span>
Encoding is done to reduce the number of bit to be transmitted and save bandwidth .can be fairly complex and contain some delicate parts. This makes them less tolerant of mechanical abuse and restricts their allowable temperature.

<span>including increased productivity, accuracy, and efficiency in coding and the consistent application of coding rules. However, there is a cost to the software, but savings can be seen in other areas.</span>

7 0
3 years ago
Other questions:
  • A __________ network is good for connecting computers over boundaries.
    6·2 answers
  • For which product would the producer keep a high profit margin and offer after-sales service?
    6·1 answer
  • The status bar only lets you view the current X, Y and Z coordinates of the cursor. Select one: True False
    8·2 answers
  • Which statement is true about the purpose of a work in process constraint?
    15·1 answer
  • What does a codec do? Choose all that apply.
    5·2 answers
  • Which line in the following program contains the header for the showDub function? 1 #include 2 using namespace std; 3 4 void sho
    9·1 answer
  • For a string s ∈ {0, 1} let denote the number represented by in the binary * s2 s numeral system. For example 1110 in binary has
    10·1 answer
  • State three reasons why users attach speakers to their computer​
    8·1 answer
  • Research the significance of the UNIX core of macOS and write a few sentences describing your findings.
    8·1 answer
  • What construction work is the tender for​
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!