0% found this document useful (0 votes)
1 views

Lab 03 (1)

The document outlines a lab assignment for a second-year Object-Oriented Programming course focusing on Java. It includes tasks related to string manipulation, array handling, and the implementation of a tic-tac-toe game. Each task requires writing specific Java methods to perform calculations, manage player data, and develop game functionalities.

Uploaded by

Rim Bouhafs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Lab 03 (1)

The document outlines a lab assignment for a second-year Object-Oriented Programming course focusing on Java. It includes tasks related to string manipulation, array handling, and the implementation of a tic-tac-toe game. Each task requires writing specific Java methods to perform calculations, manage player data, and develop game functionalities.

Uploaded by

Rim Bouhafs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Object-Oriented Programming (OOP)- 2nd Year CPI

Lab 03 Introduc on to Java programming language 2


Part One (String and Arrays):
Task 1- Write java method that perform the following calculations:
1. The power of 5 of an integer given as a parameter.
2. The product of two integers given as a parameter minus their sum.
3. The product of three integers given as an integer Array parameter.
Task 2- In following a table of some Real Madrid team players.
Write a Method that takes a T-shirt number and returns a player's name.
Player Courtois Dani Alaba Nacho Fran Mbappé Bellingham Rodrygo Vinícius
Tshirt N° 1 2 4 6 20 9 5 11 7
Task 3- Write a java method that checks if an email ends with “@esi-sba.dz”.
Task 4- What will be the output of task4 program =>
Task 5- Write a java method that takes a String as
parameter and return the reverse of that String.
Task 6- Write a java method to reverse String using
recursion.
Task 7- Code Sales.java (see end of last page) contains a Java
program that prompts for and reads in the sales for each of 5 salespeople in a company. It then prints out
the id and amount of sales for each salesperson and the total sales. Study the code, then modify the
program as follows:

a) Compute and print the average sale. (no loop is necessary)


b) Find and print the maximum sale and the minimum sale.
c) After the list, sum, average, max and min have been printed, ask the user to enter a
value. Then print the id of each salesperson who exceeded that amount, and the amount
of their sales. Also print the total number of salespeople whose sales exceeded the value
entered.
d) The salespeople are objecting to having an id of 0—no one wants that designation.
Modify your program so that the ids run from 1–5 instead of 0–4. Do not modify the
table
e) Instead of always reading in 5 sales amounts, at the beginning ask the user for the
number of sales people and then create an array that is just the right size. The program
can then proceed as before.

Dr. Oussama SERHANE ([email protected]) 1/3


Object-Oriented Programming (OOP)- 2nd Year CPI
Lab 03 Introduc on to Java programming language 2
Part Two (Coding a Game):
We are interested to implement a tic tac toe game between two players using
java programming language. The main method will contain the following code:
The program output:

Todo: In the first tasks, we will start implement the display of the game, then we will
move to the game functionalities.
Task 01: Define a character 2D array that contains values from 1 to 9 (as shown in table
1) of type java char [][].
Task 02: Create a java method named show() that iterate for each value of the array and
print it. The output should be as show in table 02:
Table 01
Table 02

Dr. Oussama SERHANE ([email protected]) 2/3


Task 03: When a use choose a cell number, we should know which row and which
column of his choice. For example if player 1 choose cellule 5 we need to implement
two method that return column and row number from array
public static int get_cell_row(char input)
public static int get_cell_column(char input)
Task 04: Implement a method called playing(row, col, ‘user character: O or X’) that
takes as parameters row, col, and player character to update the 2D array.
Task 05 :
Implement a method that check the winner called check_the_winner(). That check how
is the winner.
Task 06 << Optional >>:
Implement a method that makes one of the players play randomly (human vs Random
player)
Task 07 << Optional >>:
Implement a function that treats all possible cases and makes it hard from a player to
beat a computer.

3/3

Dr. Oussama SERHANE ([email protected])

You might also like