We appreciate your visit to Task 1 Random Integer Guessing Game Write a program that generates a random integer from 1 to 10 inclusive and asks the user to guess. This page offers clear insights and highlights the essential aspects of the topic. Our goal is to provide a helpful and engaging learning experience. Explore the content and find the answers you need!

**Task 1: Random Integer Guessing Game**

Write a program that generates a random integer from 1 to 10 (inclusive) and asks the user to guess it. Then, tell the user what the number was and how far they were from it. Note that the distance they were off by should always be non-negative (i.e., 0 or positive), whether they guessed higher or lower than the actual number.

**Task 2: Convert Seconds to Time**

Write a program that takes a number of seconds as an integer command-line argument and prints the number of years, days, hours, minutes, and seconds it's equal to. Assume a year is exactly 365 days. Some values may be 0. You can assume the number of seconds will be no larger than 2,147,483,647 (the largest positive value a Java int can store).

**Task 3: Tic-Tac-Toe Board Drawing**

Write a program that draws the board for a tic-tac-toe game in progress. X and O have both made one move. Moves are specified on the command line as a row and column number, in the range [0, 2]. For example, the upper right square is (0, 2), and the center square is (1, 1). The first two command-line arguments are X's row and column. The next two arguments are O's row and column.

- The canvas size should be 400 × 400, with a 50-pixel border around the tic-tac-toe board, so each row/column of the board is (approximately) 100 pixels wide.
- There should be 15 pixels of padding around the X and O, so they don't touch the board lines.
- X should be drawn in red, and O in blue.
- You can use `DrawTicTacToe.java` as a starting point.
- You should only need to modify the `paint` method, not `main`.
- You may want to (and are free to) add your own methods.
- The input values are parsed for you and put into variables `xRow`, `xCol`, `oRow`, and `oCol`, which you can access in `paint` or any other methods you add.
- You can assume the positions of the X and O will not be the same square.

Answer :

1) Generating a random integer from 1 to 10 (inclusive) and asks the user to guess it and tell the user what the number was and how far they were from itimport java.util.Random;


import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Random random = new Random();
int randomNumber = random.nextInt(10) + 1;
Scanner scanner = new Scanner(System.in);
System.out.println("Guess the number between 1 and 10");
int userGuess = scanner.nextInt();
System.out.println("The number was " + randomNumber);
System.out.println("You were off by " + Math.abs(userGuess - randomNumber));
}
}
2) Taking a number of seconds as an integer command-line argument, and prints the number of years, days, hours, minutes, and seconds it's equal toimport java.util.Scanner;
public class Main {
public static void main(String[] args) {
int totalSeconds = Integer.parseInt(args[0]);
int years = totalSeconds / (60 * 60 * 24 * 365);
totalSeconds -= years * (60 * 60 * 24 * 365);
int days = totalSeconds / (60 * 60 * 24);
totalSeconds -= days * (60 * 60 * 24);
int hours = totalSeconds / (60 * 60);
totalSeconds -= hours * (60 * 60);
int minutes = totalSeconds / 60;
totalSeconds -= minutes * 60;
int seconds = totalSeconds;
System.out.printf("%d years, %d days, %d hours, %d minutes, %d seconds", years, days, hours, minutes, seconds);
}
}
3) Drawing the board for a tic-tac-toe game in progress import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JComponent;
public class DrawTicTacToe extends JComponent {
private int xRow, xCol, oRow, oCol;

public DrawTicTacToe(int xRow, int xCol, int oRow, int oCol) {
this.xRow = xRow;
this.xCol = xCol;
this.oRow = oRow;
this.oCol = oCol;
}

public void paint(Graphics g) {
// Draw border
g.setColor(Color.BLACK);
g.drawRect(50, 50, 300, 300);

// Draw lines
g.drawLine(150, 50, 150, 350);
g.drawLine(250, 50, 250, 350);
g.drawLine(50, 150, 350, 150);
g.drawLine(50, 250, 350, 250);

// Draw X
g.setColor(Color.RED);
g.setFont(new Font("Arial", Font.PLAIN, 100));
int x1 = 50 + 15 + xCol * 100;
int y1 = 50 + 15 + xRow * 100;
int x2 = x1 + 70;
int y2 = y1 + 70;
g.drawLine(x1, y1, x2, y2);
g.drawLine(x1, y2, x2, y1);

// Draw O
g.setColor(Color.BLUE);
g.drawOval(50 + 15 + oCol * 100, 50 + 15 + oRow * 100, 70, 70);}

To know more about number visit:

https://brainly.com/question/3589540

#SPJ11

Thanks for taking the time to read Task 1 Random Integer Guessing Game Write a program that generates a random integer from 1 to 10 inclusive and asks the user to guess. We hope the insights shared have been valuable and enhanced your understanding of the topic. Don�t hesitate to browse our website for more informative and engaging content!

Rewritten by : Barada