Posts

Learn SQL using MySQL

       SQL – Structured Query Language . It has various commands to execute. Let us the mysql to run the SQL commands . Steps to follow: ·        MySql is open source,you can run the SQL command in this environment. ·        First, download the MySql from official website. ·        Install it in your system. ·        Login into mysql in command prompt by entering the passwords. Enter password: *********** ·        The environment is look like as follows. Welcome to the MySQL monitor.   Commands end with ; or \g. Your MySQL connection id is 21 Server version: 9.6.0 MySQL Community Server - GPL ·        First, create   a database as my_database. mysql> create database my_database; Query OK, 1 row affected (0.995 sec) ·      ...

Stock Price Predictor in java

               It is mathematical model which describes the relationship between variables. One is dependent variable and another one is independent variable . For eg: stock price predictor. Here, dependent variable is stock price. Independent variables are time, trade data and volume . The formula for predicted stock price is given by, Y= beta1+beta2*X+ error term Where, Y = predicted stock price X = predictor value ‘beta1’ = intercept ‘beta2’ = slope Error term The java implementation is given below… public class StockPricePredictor {     private double slope1;     private double intercept1;     // Train simple regression model     public void fit(double[] x, double[] y) {         if (x.length != y.length) {             throw new IllegalArgumentException ("Two...

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...