Showing posts with label javacodes. Show all posts
Showing posts with label javacodes. Show all posts

Saturday, 3 September 2016

Creating a Calculator in JAVA


Step 1: Creating a new project


·         Click on the file menu and then select New Project.

·         Now select the Java node from the Categories on the left and select Java Application from the Projects menu on the right.
Click Next.

n

·         Now name the project as Calculator and leave the Create Main Class check box unselected.




·         Now you will see the project in the projects view on the left. Now Right_Click the project and follow the steps below. 


Now select JFrame Form
·      Now provide the name to the JFrame Form. Ignore the messages displayed at the bottom.
For detailed explanation See Here.

Now click finish.

·         Now you will be shown the design view. Now create the layout below using the pallete on the right.
Drag a jtextfield on the design area.
Now drag and drop a jpanel. Set the layout of the jpanel to be gridlayout.
Now Click on the gridlayout from the navigator view on the left and move to the properties view on the right.
Now drag and drop 16 buttons from the pallete to the jpanel on the design area.

·        

After creating the above format, copy and paste the code given below.
·         Enjoy your first java made calculator.

:: Source code ::



CHEERS!!!



Wednesday, 18 May 2016

Creating a screen shot application in JAVA

Ever wondered about creating your own screenshot application in java? If yes, then this post is for you!
Today, I share with you a code for creating a simple class capable of capturing your screen and saving it in a screen.jpg named file. With much delay lets have a look at the code.

Creating a simple Task Manager in java

Hey Guys, today I will show you how to create a simple task manager in java. For achieving this aim, I am going to make use of a application preloaded on all Windows machines. I am afraid, this trick and also the program shall not work for any non-windows platform. So, without much delay, let me present the code in front of you.

A program which types automatically by its own

Image result for ghostHey guys, Today, I am going to show you all how to type like a Ghost! I am kidding!
But have you ever wondered to create a program which can run by its own and types texts in an notepad file?
Yeah, you heard it write! Today, I am going to show you how you can type artificially using a program code written in java. I will make use of the java.awt.Robot and java.awt.event.KeyEvent classes to achieve my aim.

Here is the code :

import java.awt.Robot;
import java.awt.event.KeyEvent;

public class TypingArtificially 
{
public static void main(String args[])
{
	try
	{
	Runtime.getRuntime().exec("notepad.exe");
	Thread.sleep(2000);
	Robot r=new Robot();
	r.keyPress(KeyEvent.VK_Y);
	Thread.sleep(500);
	r.keyPress(KeyEvent.VK_O);
	Thread.sleep(500);
	r.keyPress(KeyEvent.VK_U);
	Thread.sleep(500);
	r.keyPress(KeyEvent.VK_SPACE);
	Thread.sleep(500);
	r.keyPress(KeyEvent.VK_R);
	Thread.sleep(500);
	r.keyPress(KeyEvent.VK_SPACE);
	Thread.sleep(500);
	r.keyPress(KeyEvent.VK_H);
	Thread.sleep(500);
	r.keyPress(KeyEvent.VK_A);
	Thread.sleep(500);
	r.keyPress(KeyEvent.VK_C);
	Thread.sleep(500);
	r.keyPress(KeyEvent.VK_K);
	Thread.sleep(500);
	r.keyPress(KeyEvent.VK_E);
	Thread.sleep(500);
	r.keyPress(KeyEvent.VK_D);
	
	}
	catch(Exception e)
	{
		System.out.println(e);
	}
}
}


Compile the program and enjoy sharing with your friends !

Upload Time Estimator Problem

To set user expectations during file uploads, Online Cloud Service "ABC", indicates how long a file will take to transfer with its upload time estimator.
Your goal is to implement a particular type of a upload time estimator. Suppose that several clients are uploading files to Dropbox at the same given moment. The ith client uploads a file of sizesi megabytes. For a single file, upload speed is V megabytes per second, but if there are several files uploading at the same time then uploads occur simultaneously in parallel threads. For each thread the upload speed equals V / n, where n is the number of currently active threads.
Given each file's size and its upload start time, determine the upload end times.
Example
For sizes = [21, 10]uploadingStart = [100, 105] and V = 2
the output should be
loadTimeEstimator(sizes, uploadingStart, V) = [116, 115].
  • During the first 5 seconds only the first file is uploading at a speed of 2 MB/sec. Thus, when the second file upload begins, 10 MBs of the first file will already have been uploaded.
  • For the next 10 seconds both files upload simultaneously with a speed of 1 MB/sec each.
  • After this point (15 seconds since the first file started uploading) the second file is uploaded successfully, and only 1 MB of the first file remains to be transferred.
  • It takes 0.5 more seconds to finish uploading the first file. Rounding 115.5 up, we obtain 116.
  • [input] array.integer sizes
    Array of positive integers. sizes[i] equals the size of the ith file in megabytes.
  • [input] array.integer uploadingStart
    Array of positive integers of the same length as sizesuploadingStart[i] represents the number of seconds that will pass from the current moment before uploading of the ith file starts.
  • [input] integer V
    A positive integer.
  • [output] array.integer
    The ith element of the result should be equal to the number of seconds that will pass from the current moment before uploading of the ith file finishes. If the upload takes a non-integer number of seconds, round it up.

Friday, 23 October 2015

Creating a Web Browser in Java

Welcome Back,
Today lets' see how to make a Web Browser for displaying webpages available on the web with the power of Java.

Screen Shots:


Code:

Sunday, 18 October 2015

Creating a Story Writer in Java.

Today we are going to show you how to write and save documents over JAVA programming language. To reach our desired aim, I have personally created a StoryWriter – A program which helps its users to write story and save the story in a .txt file. Our sample program uses some manipulating streams available in JAVA.
The Program writes the story line by line and closes the file sockets as soon as it finds a break statement (Ctrl+ Z)  

Screen Shots:
[Fig. 1 Opening Screen]



























[Fig. 2  Story Write Screen]

Code:

Thursday, 15 October 2015

Creating a Quadratic Equation Solver program in JAVA

Here is a simple code written in JAVA to solve quadratic equations even with complex roots.


Description of member Functions:

  • discriminant(double a, double b, double c) - Variable 'a' signifies the coefficient of x^2, 'b' signifies the coefficient of x and 'c' signifies the constant.
  • wait(int n) - Variable 'n' signifies the number of milliseconds to wait before displaying the output. *This function is an extra written to make the program more realistic.
Screens:

Code:



Create a JAVA Task Manager

Hello this is Shouvik Mitra,
Lately I was working on project which involved me in developing my own Task Manager which helps to list down all the ongoing processes by the system.
Here's a small code on how to list down all the task performed by the system.

Friday, 5 December 2014

A boat like pattern in JAVA

Here come another time-pass pattern from our friend Soham Chakraborty. It gives a boat like pattern. I am not the actual author of this code. Enjoy it !!!
Code:

class Pattern{
public static void main(){
int sp=15,s=0,d=17;

for(int i=1;i<=6;i++){
for(int j=0;j<sp;j++){
System.out.print(" ");}
for(int k=1;k<=i;k++){
System.out.print("! ");}
sp--;System.out.println();
}
for(int i=1;i<=4;i++){
for(int j=0;j<s;j++)
{ System.out.print(" ");}
for(int k=1;k<=d;k++){
System.out.print("* ");}
s++;d--;System.out.println();
}
}
}


Monday, 10 November 2014

Rock, Paper, Scissors Game in JAVA.

The most loved and played game among the children's is here with JAVA. As the game is simple so is the code. It is based on simple switch...case...default. structure. It is programmed by me within 15 mins as the idea came to my mind

Game Play Instructions :
It is simple. Just enter "rock" or "paper" or "scissor" and the program calls the random functions which in turn uses the computers internal clock to get a random value. As we know that the random function in java returns a value greater than 0.00 and less than 1.00 I have multiped the value to get an integer between 1-3 which i used in the switch...case...default.

Snapshot: 

Source Code:

Sunday, 9 November 2014

Snake and Ladder Game in Java ( 2-D Array Concept)


Name of Game : Snake and Ladder

Concept : 2-D Matrix

Instruction to play: This program will simulate a regular snakes and ladders game,where you will befacing the computer. Both start at square 1, and the first one to square 100 wins, The Default presets of Snakes : [54->19] [90->48] [99->77] Ladders : [9->34] [40->64] [67->86]. In simple words, there are some blocks (numbers) which role as sanke and some block(numbers) which role as ladders. If while playing you get that number then the respective happens.

Snapshots:




Coding :


package Games;
import java.io.*; // used to allow user to input data
 
public class Snakes_and_Ladders
{// start class
 
    //Main Method
    public static void main (String [] args) throws IOException
    {   // start main method
     
        //Welcoming Screen
     
        BufferedReader myInput2 = new BufferedReader (new InputStreamReader (System.in));
        // Print the welcome screen and instructions
        System.out.println ("\t\t\t\t\t\t-----------------------------------");
        System.out.println ("\t\t\t\t\t\t|  Welcome To Snakes And Ladders   |");
        System.out.println ("\t\t\t\t\t\t-----------------------------------\n\n");
        System.out.println ("\t\t\t\t\t\t\tInstructions:");
        System.out.println ("\t\t\t\t This program will simulate a regular snakes and ladders game, ");
        System.out.println ("\t\t\t\t where you will befacing the computer. Both start at square 1,");
        System.out.println ("\t\t\t\t and the first one to square 100 wins, The Default presets of");
        System.out.println ("\t\t\t\t Snakes : [54->19] [90->48] [99->77] Ladders : [9->34] [40->64] [67->86] ");
        System.out.println ("\t\t\t\t\t\t\t Good Luck and Have FUN!!!");
        displayBoard();
        String sGame = "y"; // decare variable used to ask user if he wants to play
     
        System.out.print ("Do you want to play? (y/n) :  "); // ask user if we wants to play the game
        sGame = myInput2.readLine (); // reads the user's input into the variable sGame
        System.out.print ("\n\n\n\n\n\n");
        // While the user says yes, go to startGame method
        // startGame is fuction type method, which start the game
        while (sGame.equals ("Y") || sGame.equals ("y"))
        {
            sGame = startGame(sGame); // give startGame a variable to work with
        }
        System.out.println ("\n\n\n\n\t\t\t\t\t\tSEE YA!!");
     
     
    } //end main method
 
    //The method for displaying The game board
    public static void displayBoard()
    {
     
        int counter= 100,iteration=-1; // sets the counter and iteration vaiables to be used in making the board
        System.out.println ("-----------------------------------------------------Game Board--------------------------------------------------------------------");
     
        /*
        This while loop makes the board for the player to visualize what the
        game looks like, it uses a counter to increment or decrement by 1.
        It will also subtract by 9 or 10 when necessary to create a board
        exactly like the one given.
        */
        while (counter > 0){// start while
            if (counter%10 == 0 && counter != 100){// checks if the counter is at a 90, or 80...
                if(iteration==-1)
                {
                    // subtract 9 from the counter
                    // and sets it to start adding by one
                    counter-=9;
                    iteration=1;
                }
                else
                {
                    System.out.print(counter+"\t");
                    counter-=10;
                    iteration=-1; // set the counter to start subtract by ones
                }
                if(counter!=0)
                System.out.print("\n" + counter + "\t"); // just prints out the counter with a line breck
            }
            else
            System.out.print(counter + "\t"); // just prints out the counter
            counter+=iteration; // sets counter to add by iteration
        }// end while
        System.out.println();
        System.out.println ("__________________________________________________________________________________________________________________________________");
    }
 
 
 
    //-------------------------------------------------------------------startGame Method------------------------------------------------------------------------------
 
    /*
    startGame method:
 
    This method is responsible for organizing the game, asking the user to continue playing,
    and setting the important varibales. It will also return a vaule to the main method, which
    will reset the game so the user can play again.
    */
    public static String startGame (String start) throws IOException // Recieves data from the main method
    {// start startGame method
     
        BufferedReader myInput = new BufferedReader (new InputStreamReader (System.in));
     
        // sets important variables for the game
        // NOTE: These variables will change as the game progresses
     
        int userPosition = 1; // sets the default loaction for user's piece to 1
        int compPosition = 1; // sets the default loaction for computer's piece to 1
        int diceRoll = 0; // creates the first die
        int diceRoll2 = 0; // creates the second die
        int userRoll = 1; // declares what the user rolled
        int compRoll = 1; // declares what the computer rolled
        String playAgain = "y"; // sets the play again variable
     
        // declare all the snakes and ladders in a array
        int snakesLaddersArray [] = new int [6]; // create a 6 element array
        // store the snakes and ladders location in the array
        snakesLaddersArray [0] = 54;
        snakesLaddersArray [1] = 90;
        snakesLaddersArray [2] = 99;
        snakesLaddersArray [3] = 9;
        snakesLaddersArray [4] = 40;
        snakesLaddersArray [5] = 67;
     
     
        while (playAgain.equals ("y") || playAgain.equals ("Y")) // loops while the playAgaim vaiable equals "y" or "Y".
        {// start playAgain While
         
         
            // gets the dice roll for user and computer
            userRoll =  getDice(diceRoll, diceRoll2); // sends data to a function type method called getDice
            compRoll =  getDice(diceRoll, diceRoll2); // does the same for the computer
            System.out.println("__________________________________________________________________________________________________________________________________");
            System.out.println ("\t\t\t\t\t------------------------------------------");
            System.out.println ("\t\t\t\t\t|\tYou Rolled a " + userRoll + "\t\t|"); // print the roll the user got
            System.out.println ("\t\t\t\t\t|\tThe Computer Rolled a " + compRoll + "\t|"); // print the roll the computer got
            System.out.println ("\t\t\t\t\t------------------------------------------");
         
            // hold the user's last position for switching back if current position was greater than 100
            userPosition = userPosition + userRoll;
         
            // hold the computer's last position for switching back if current position was greater than 100
            compPosition = compPosition + compRoll;
         
         
         
            // check to see if user landed on top of a snake or at the bottom of a ladder
            // give getP parameters to work with, and recieve a final value which can be printed out
            userPosition = getP(userPosition, userRoll, snakesLaddersArray);
            // The same goes for compPosition, however compgetP gets an additional
            // parameter (userPosition) to check if user has already won
            compPosition = compgetP(compPosition, compRoll, snakesLaddersArray, userPosition);
         
            System.out.println("\t\t\t*************************************************************************");
            System.out.println ("\t\t\t*\t\tYou are currently on square " + userPosition + "\t\t\t*"); // print out the user's current location
            System.out.println ("\t\t\t*\t\tThe Computer is currently on square " + compPosition + "\t\t*"); // print out the computer's current location
            System.out.println("\t\t\t*************************************************************************");
         
            // resets the position values, if the user or the computer won
            // so that the user could play the entire game again if he/she wanted to
            if (userPosition == 100 || compPosition == 100)
            {
                userPosition = 1;
                compPosition = 1;
                // asks the user if we wants to play again
                System.out.print ("Do you want to play? Y or N     >  ");
                playAgain = myInput.readLine ();
                System.out.print ("\n\n\n\n\n\n\n\n\n\n\n\n");
            }
            else
            {
                // asks the user if we wants to continue playing
                System.out.print ("Do you want to play? Y or N     >  ");
                playAgain = myInput.readLine ();
             
            }
         
         
        }// end playAgain While
     
        return playAgain; // returns prameter "playAgain" to main: if the user wants to play the game again
    }// end startGame method
 
 
 
 
 
 
    //-------------------------------------------------------------------geDice Method------------------------------------------------------------------------------
 
    /*
    getDice method:
 
    This method generates two random numbers bewteen 1 and 6, then
    adds them to get a final roll. Next it returns the value to be
    diplayed on the screen.
    */
    public static int getDice (int diceRoll, int diceRoll2)
    {// start getDies class
        diceRoll = (int)(Math.random()*6 )+1 ; //creates dice roll number 1
        diceRoll2 = (int)(Math.random()*6 )+1 ; //creates dice roll number 2
        int move = diceRoll + diceRoll2; // adds the two dice rolls to get a final move
        return move; // return parameter move: this will give the final dice roll back to startGame
    }// end getDice class
 
 
 
 
    //-------------------------------------------------------------------getP Method------------------------------------------------------------------------------
    /*
    getP method:
 
    This method is responsible for checking if the USER is on
    top of a snake, or at the bottom of a ladder, and then
    adjusting the user's position to mathch the snake or
    ladders value.
    */
    public static int getP (int userPosition, int userRoll, int snakesLaddersArray []) throws IOException // recieves two parameter from startGame
    {// start getP
     
     
        if(userPosition == snakesLaddersArray[0]) //if position equals snake 1
        {
            userPosition = 19; // set new position
            System.out.println ("\t\t\t\t~~~~~~~~~~~~~You Got Bit By A Snake, GO DOWN!!!~~~~~~~~~~~~~");
        }
        else if (userPosition == snakesLaddersArray[1]) //if position equals snake 2
        {
            userPosition = 48; // set new position
            System.out.println ("\t\t\t\t~~~~~~~~~~~~~You Got Bit By A Snake, GO DOWN!!!~~~~~~~~~~~~~");
         
        }
        else if (userPosition == snakesLaddersArray[2]) //if position equals snake 3
        {
            userPosition = 77; // set new position
            System.out.println ("\t\t\t\t~~~~~~~~~~~~~You Got Bit By A Snake, GO DOWN!!!~~~~~~~~~~~~~");
        }
        else if (userPosition == snakesLaddersArray[3]) //if position equals ladder 1
        {
            userPosition = 34; // set new position
            System.out.println ("\t\t\t\t~~~~~~~~~~~~~You Got A Ladder!! GO UP!!!~~~~~~~~~~~~~");
         
        }
        else if (userPosition == snakesLaddersArray[4]) //if position equals ladder 2
        {
            userPosition = 64; // set new position
            System.out.println ("\t\t\t\t~~~~~~~~~~~~~You Got A Ladder!! GO UP!!!~~~~~~~~~~~~~");
         
        }
        else if (userPosition == snakesLaddersArray[5]) //if position equals ladder 3
        {
         
         
            userPosition = 86; // set new position
            System.out.println ("\t\t\t\t~~~~~~~~~~~~~You Got A Ladder!! GO UP!!!~~~~~~~~~~~~~");
        }
     
        if (userPosition < 0 || userPosition > 112) // This is ab ERROR TRAP to catch any unwanted system errors that may occur by chance
        {
            System.out.println ("An error has occured please reset the game!!!!!!");
        }
     
        else if (userPosition > 100) // checks if user's location if greater then a 100
        {
            userPosition = userPosition - userRoll; // subtract userRoll from the userposition to get back old position
            System.out.println ("OHHH You cant jump, you must land on a 100"); // print out the users current location
         
        }
        else if (userPosition == 100)
        {
            System.out.println ("YOU WON, GOOD JOB!!!"); // print out that the user won
         
        }
     
     
     
        return userPosition; // return the final position to starGame: this position had gone through all checks and test and can be displayed on screen
    }// end getP
 
 
 
 
 
 
    //-------------------------------------------------------------------compgetP Method------------------------------------------------------------------------------
 
    /*
    compgetP method:
 
    This method is responsible for checking if the COMPUTER is on
    top of a snake, or at the bottom of a ladder, and then
    adjusting the compuer's position to mathch the snakes or
    ladders value.
    */
 
    public static int compgetP (int compPosition, int compRoll, int snakesLaddersArray [], int userPosition) throws IOException
    {// start compgetP
     
        // NOTE: this method is similar to getP, so the comments are the same for both!!
        // Look at getP's commments if you need help
     
        if(compPosition == snakesLaddersArray[0])
        {
            compPosition = 19;
            System.out.println ("\t\t\t\t~~~~~~~~~~~~~Computer Got Bit By A Snake, HE WENT GO DOWN!!!~~~~~~~~~~~~~");
         
         
        }
        else if (compPosition == snakesLaddersArray[1])
        {
            compPosition = 48;
            System.out.println ("\t\t\t\t~~~~~~~~~~~~~Computer Got Bit By A Snake, HE WENT GO DOWN!!!~~~~~~~~~~~~~");
         
        }
        else if (compPosition == snakesLaddersArray[2])
        {
            compPosition = 77;
            System.out.println ("\t\t\t\t~~~~~~~~~~~~~Computer Got Bit By A Snake, HE WENT GO DOWN!!!~~~~~~~~~~~~~");
        }
        else if (compPosition == snakesLaddersArray[3])
        {
            compPosition = 34;
            System.out.println ("Computer Got TO A Ladder, HE WENT UP!!!");
        }
        else if (compPosition == snakesLaddersArray[4])
        {
            compPosition = 64;
            System.out.println ("Computer Got TO A Ladder, HE WENT UP!!!");
         
        }
        else if (compPosition == snakesLaddersArray[5])
        {
            compPosition = 86;
            System.out.println ("Computer Got TO A Ladder, HE WENT UP!!!");
        }
     
     
        if (compPosition < 0 || compPosition > 112) //  ERROR TRAP to catch any unwanted system errors that may occur by chance
        {
            System.out.println ("An error has occured for the computer, please reset the game!!!!!!");
        }
     
        else if (compPosition > 100) // checks if computers's location if greater then a 100
        {
            compPosition = compPosition - compRoll; // get old position
            System.out.println ("THE COMPUTER CAN'T JUMP!!! He must land on a 100"); // give message that the computer cant jump
         
        }
        else if (compPosition == 100 && userPosition != 100)
        {
            System.out.println ("THE COMPUTER WON, YOU FAILED!!!"); // print out that the computer won
         
        }
     
        return compPosition; // return the final position to starGame: this position had gone through all checks and test and can be displayed on screen
    } // end compgetPy
}//end clas

Tuesday, 4 November 2014

Hangman game in JAVA : BLUEJ

This is a simple game of Hangman created by me in java environment.

How to play ? 
In this game you are given a clue and required number of blank space for your answer. You are given a finite number of chances to fill the blanks with letters step-by-step. I have made this game different from others by making it case-sensitive, that is, "Albert" is different from "albert"

Snapshots from Game Play :


Code:
Click Here to download the code as .rar file
If you don't have an extractor you may download the .txt file from here.. The .txt file consist of 3 classes compile them separately in your java compiler (Bluej). And Enjoy !!!

////////////////////////////////////////////////////////////////////////////////////////////  Main class  
import java.util.Scanner;
/* Created by Shouvik Mitra */
public class hangManProject
{
    public static void main( String[] args) 
    {
        Scanner scan = new Scanner( System.in);
        // VARIABLES
        int totalMistake = 0;
        boolean b = false;
        // PROGRAM CODE
        showWelcome();
        SecretWord word = new SecretWord();
        System.out.println("Your clue: " + word.getClue());
        KeyboardInput input = new KeyboardInput();
        while (totalMistake < 4 && !word.isSolved())
        {
            System.out.println(word);
            char c = input.getNewLetter();
            if (!word.update(c))
                totalMistake = totalMistake + 1 ;
        }
        if (word.isSolved())
            System.out.println("Great, you done it.");
        else
            System.out.println("Sorry, too many errors.");
       
    }
        
        public static void showWelcome()
        {
            System.out.println( "Welcome to Hangman Game !!!" );
        }
        
}

//////////////////////////////////////////////////////////////////////////////////////////// Subsidiary Class 
import java.util.ArrayList;
import java.util.Scanner;

public class KeyboardInput
{   
    // Properties
    ArrayList<String> keyList ; 
    boolean chosen;
    
    //Constructor   
    public KeyboardInput()
    {
        keyList = new ArrayList<String>();
    }
    
    // Adds and stores the entered key in the Arraylist
    public void keyChosen( String key )
    {
        keyList.add( key );
    }
    
    // Checks if the entered key has been chosed before
    public boolean hasBeenChosen( String key)
    {
        chosen = keyList.contains( key );
        return chosen;
    }
    
    
    public char getNewLetter() 
    {
        Scanner scan=new Scanner( System.in);
    
        char a;
        boolean chosen;
        String aTmp;    // used to convert a into a String for compatibility with Group 6
        
        do
        {   
            System.out.println("Enter a Letter");
            a = scan.next().charAt( 0); 
            aTmp = "" + a;
            chosen = hasBeenChosen( aTmp);
            if(!chosen)
                keyChosen( aTmp);
            else
            {   
                System.out.println("You've already used that one. Please enter a new Letter");
                
            }
            
                        
        }
        // we repeat the process until we're out of trials.
        while(chosen);
        
        return a;  
    }
}

////////////////////////////////////////////////////////////////////////////////////// The Class for the Secret Word to Store
public class SecretWord
{
    String clue, visible, secret;

public SecretWord()
{
    String [] wordList = { "Umbrella", "Albert Einstien", "Hangman", "Shouvik Mitra" };
    
    String [] clueList = { "Rainy Season", "One of the greatest Scientist", "Name of this game", "Name of the creator" };
    int rand;
    rand = (int) (Math.random()*4);
    secret = wordList[rand];
    clue = clueList[rand];
    int wordLength = secret.length();
    
    visible = "";
   
    for ( int i = 0; i < secret.length(); i++)
    {
        char c = secret.charAt(i);
        
        if ( c == ' ' )
            visible += c;
        else
            visible += '_';
    }
}

public String getClue()
{
    return clue;
}

public String toString()
{
    // String s = "";
    // for(int i = 0; i < wordLength; i++)
    //    s = s + "_ ";
    // return s;
    
    return visible;
}

    // provided by Group 4 and 8
    public boolean update(char c)
    {
        char[] secretArray = new char [secret.length()];
        char[] visibleArray = new char [secret.length()];
        String s = "";
        boolean contains = false ;
        
        //We make the String secret an array
        for(int i = 0; i < secret.length(); i++)
        {
            secretArray[i] = secret.charAt(i);
            visibleArray[i] = visible.charAt(i);
        }
        
        //We are uptading our empty visible array
        for(int k = 0; k < secret.length();k++)
        {
            
            if(secretArray[k] == c)
            {
                visibleArray[k] = c;
                contains = true;
            }
        }
        //We are changing our visible array into the visible string
        for(int m=0; m < secret.length(); m++ )
        {
            s = s + visibleArray[m];
        }
        visible = s;
        
        return contains;
   }
    //This is a method to check if the secret word is solved
    public boolean isSolved()
    {   
        return secret.equalsIgnoreCase(visible);
    }
}

Click Here to download the code as .rar file
If you don't have an extractor you may download the .txt file from here.. The .txt file consist of 3 classes compile them separately in your java compiler (Bluej). And Enjoy !!!