Posts

Showing posts from 2026

Maze Solver in java

               It is logical thinking game. Let us implement this program in java. Maze solver can be done in many ways as follows.. This maze solver uses DFS (Depth First Search) This algorithm starts from a root node and traverses through its child node until depth. It marks the visited node as visited and continues to next node. Complete all nodes using recursion . Code: import java.util .*; public class MazeSolver {     // let us create the Maze.here, 0 = path, 1 = wall     private static int[][] maze = {         {0, 1, 0, 0, 0},         {0, 1, 0, 1, 0},         {0, 0, 0, 1, 0},         {1, 1, 0, 1, 0},         {0, 0, 0, 0, 0}     };     private static boolean[][] m_visited; ...

Implementation of TicTacToe in java

               TicTacToe program is a classic one. Here, we implement this with AI . When a player plays,AI plays opposite side. The program is given below. // importing built-in package. import java.util. Scanner ; //public class definition public class TTTAI {     static char[][] board1 = {         {' ', ' ', ' '},         {' ', ' ', ' '},         {' ', ' ', ' '}     }; // main() function includes the play_Move(), ai_Move(), isGameOver().     public static void main(String[] args) {         Scanner s1 = new Scanner( System.in );         while (true) {             printIt();             play...

Sentiment Word Detector

               Let us create a java program to find the sentiment words in the input. The words are created in two categories such as positive or negative. The program finds the words and prints it as the output. This is one of the sample programs in AI coding in beginner’s level. Steps to follow: This program begins by importing java.util package. A public class is created. The class name is “SwordDetector”. It includes the main () function. Positive and negative words are created as set of string. Using Scanner object, the system input is read from the user. Each and all words are separated. Each word is compared with positive and negative words list. Finally, check the category of the word and print it accordingly. Program: import java.util.*; public class SwordDetector {     public static void main(String[] args) {         // create a simple positive and negative words ...

Trading System in C++

              Trading system deals with finance management. It gets the input from the console and display the output in the console. It has the following components. A structure ‘ T_order ’ with 3 elements. It has t_type,t_quantity and t_price. A class ‘ TradingSystemEg ’   creates a vector and a variable ‘t_balance’. ‘placeIt()’, ‘showIt()’ are the two functions to buy the units and displayed. The constructor TradingSystemEg() is used to initialise the variable values. ‘placeIt()’ – it gets the three values as function input. This function checks the balance is greater than quantity ,then the type is “ BUYIT ”, the balance is reduced as quantity and multiplied with the price value. ‘showIt()’ – it displays the balance value and unit value. ‘main()’ – it creates the object for TradingSystemEg. The object calls the function. Code: #include <iostream> #include <vector> #include <string> struct T_Order { ...

Contact book creation in python

              Contact book is a collection of data which has the list of people name and contact details. It is an evergreen concept for file handling . It gets the user input, process it and display the contact. Let us create contact book. It has following activities ·        Add new contact ·        Save contacts to a file . ·        Search a contact ·        Display the contact details. ·        Delete a contact The python program to create a Contact Book : contactbook = {} def add_it():     c_name = input("Enter name: ")     c_phone = input("Enter phone number: ")     c_email = input("Enter email: ")     contactbook[c_name] = {"phone Number": c_phone, "email id": c_email}     print(f"{c_name} is a...

C++ program to display the calendar

               This blog creates a c++program to display the calendar. It prints a month calendar. How to implement the program? First, include the built-in header files and namespace std. Next, check the leap year of the year. It checks the year is divided by 4,100 and 400, then it is leap year. Function daysOfMonth() assigns each month’s days value. For February month,check for leap year and assign the value as 29. Zeller’s Congruence is used to find the weekday. Finally, main() function gets the input as month and year and prints the calendar. Code: #include <iostream> #include <iomanip> using namespace std; // leap year checking function bool checkLeap(int yr) {     return (yr % 4 == 0 && yr % 100 != 0) || (yr % 400 == 0); } // days of the month int daysOfMonth(int yr, int month) {     int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};    ...

Simple Chatbot Application in C++

              Chatbot is a chatting application which reads the user input, find the appropriate response from the response database . It retrieves it from the database and give it as response to the user. Major steps are given below. Read the input from the user. Search it with the database. Finds the proper answer. Reply it back to the user. Let us create a Simple Chatbot application in C++. There are two functions in this program. One is main() and next one is toLowerCase(String s1). ‘toLowerCase(String s1)’ makes the string to lowercase letters. ‘main()’ function is used to read the input from the user. ‘getLine()’ is used to read the input. Based on the inputs, the request is searched according to the options. Finally,it displays the output. Here, we named the ChatBot name as Chaty. Code: #include <iostream> #include <string> #include <algorithm> using namespace std; //This function makes the ...