Friday 5 February 2016

TO SAVE THE OUTPUT OF A PROGRAM TO SAVE VOWELS IN A FILE IN THE HARD DISK.

/* Hi people , we have run java programs but as soon as we finish running with the programs we cannot store our results;


 *  consequently they get deleted;
 *  Now through 'File Handling' we can actually save our output! 
 *  Here is a simple program on File Handling,
 */ 
import java.util.*;// importing java.util package
import java.io.*;// importing java.io package
class vowels
{
    void main() throws IOException
    {
        int ch = 0;
        Scanner in = new Scanner(System.in);
        System.out.println("Enter String");
        String st = in.nextLine();// Taking input through scanner class
        FileWriter fw = new FileWriter("v.dat");// creating another file named- v.dat
        BufferedWriter bw = new BufferedWriter(fw);
        PrintWriter pw = new PrintWriter(bw);
       
        String str = "AEIOUaeiou";
        for(int i = 0 ;i<st.length();i++) //To write all the vowels in v.dat
        {
            ch = 0;
            for(int j = 0 ;j<str.length();j++)
            if(str.charAt(j)==st.charAt(i))
            {
                ch =1 ;
                break;
            }
            if(ch==1)
            pw.println(st.charAt(i));// the function that we use to write vowels
        }
        pw.close();
        bw.close();
        fw.close();//closing the writer
         FileReader fr = new FileReader("v.dat");
        BufferedReader br = new BufferedReader(fr);
        String sl = br.readLine();
        while(sl!=null) // so that it stops as soon as the reader looks at a null string
        {
            System.out.println(sl);// To print all the files
            sl = br.readLine();
        }
        br.close();
        fr.close();// closing the reader
    }
}
in the file : you can see the extention
    

Friday 21 August 2015

PROGRAM TO SORT AN ARRAY WITHOUT SHIFTING OR SWAPPING.

/* Wondered how we can do sort an array without Shifting or Swapping ? Well, here it is: */
MY OUTPUT

import java.util.*;  
class sorting_without_shifing_or_swapping
    {
        void main()
        {
            Scanner in = new Scanner(System.in);
            int array[] = new int[5];
            for(int v = 0 ; ; )
            {
            System.out.println("Enter the Array" ); //I am assumung that the array is of length = 5
            for(int i =  0 ; i<5 ; i++) // inputting the array
            {
                array[i] = in.nextInt();
            }
            int largest  = array[0], small = array[0];
            for(int j = 0 ; j<5 ; j++)// a loop to find the smallest and the largest element
            {
                if(largest<array[j])
                {
                    largest = array[j];
                }
                if(small>array[j])
                small = array[j];
            }
            System.out.println("The sorted array :");
            for(int i = small ;i<=largest ; i++) //Here is the magic!!!
                {
                    for(int k = 0 ; k<5 ; k++)
                    {
                        if(i==array[k])
                        {
                            System.out.println(array[k]);
                        }
                    }
                }
                System.out.println("If you want to EXIT enter 1 else enter any other number");
                int ch = in.nextInt();
                if(ch==1)
                {
                    break;
                }
            }
        }  
        }
                                                                          - SHASHWAT SRIVASTAVA 

Saturday 8 August 2015

WHICH SARABHAI VS SARABHAI CHARACTER ARE YOU?

/* Sarabhai versus Sarabhai was a sitcom that ran on Indian Television 10 years back. It is one of my favourite sitcoms and I created THIS GAME just for fun ;) */
import java.util.*;    // Taking input using Scanner Class
class WhichSarabhaiCharacterareyou
    {
        int sahil = 0 , monisha = 0 , dush = 0 ,  indu = 0 , maya = 0 , rohsesh = 0,i = 0 ;
        public void SarabhaiVSSarabhai()
        {
           
            Scanner in = new Scanner(System.in);
            System.out.println("Welcome to Quiz Which Sarabhai Character are you");
            System.out.println("Answer all the 10 Questions by only Entering a SINGLE 'small' alphabet");
            System.out.println("Q1. What Profession do you want to indulge into ? ");
            System.out.println("a: Engineering   b: Fashion Designing   c: Can't Work - Want to enjoy life   d: Industrialist");
            char q1 = in.next().charAt(0);
           {
            if(q1=='a')
            {
            sahil++ ;
            dush++;
        }
             else if(q1=='b')
             {
                 maya++;
                 rohsesh++;
                }
                else if(q1=='c')
                {
                     ;
                    monisha++;
                    rohsesh++;
                }
                else
                {
                    indu++;
                    maya++;
                }
            }
                System.out.println("Q2. What do you do in your free time?");
                System.out.println("a: Visit a friend's home or call him/her to your home    b: Show your Artistic skills like painting , etc   c : Conspire   d: Clean your home and rearrange objecs of your house");
                char q2 = in.next().charAt(0);
                   if(q2=='a')
                maya++ ;
             else if(q2=='b')
             {
                dush++ ;
                 monisha++;
                 rohsesh++;
                }
                else if(q2=='d')
                {
                     ;
                    monisha++;
                    sahil++;
                }
                else
                {
                    indu++;
                    maya++;
                }
                System.out.println("Q3. What would you do if someone admonishes your close friend  ?");
                System.out.println("a: Endure it patiently and try to change the topic   b: Slap that person   c: Take that seriously and test whether he/she is right or not   d: Laugh and make fun of every person");
                char q3 = in.next().charAt(0);
                 if(q3=='a')
                {
                    sahil++ ;
                    maya++;
                }
             else if(q3=='b')
             {
                 monisha++;
                  ;
                }
                else if(q3=='c')
                {
                    ;
                    monisha++;
                    rohsesh++;
                }
                else
                {
                    indu++;
                    ;
                }
                  System.out.println("Q4. Whom are you most close to ?");
                  System.out.println("a: Mom   b: Dad   c: Spouse   d: Sibling");
                 char q4 = in.next().charAt(0);
                  if(q4=='a')
                {
                    sahil++ ;
                    rohsesh++ ;
                    indu++;
                      ;
                }
             else if(q4=='b')
             {
                 monisha++ ;
                 sahil++ ;
                }
                else if(q4=='c')
                {
                    dush++;
                    monisha++;
                    sahil++;
                   
                }
                else
                {
                    rohsesh++;
                    ;
                }  
                System.out.println("Q5. What will be the first thing that comes in your mind when you see your spouse with any one else ?");
                System.out.println("a: Who is the other person?   b: How dare heORshe be with any one else   c: The other person might be a GOOD friend of your spouse   d: Lets pull the legs of the person ");
                char q5 = in.next().charAt(0);
                if(q5=='a')
                {
                    sahil++ ;
                    monisha++;
                    dush++;
                      ;
                }
             else if(q5=='b')
             {
                 monisha++ ;
                 ;
                }
                else if(q5=='c')
                {
                    dush++;
                    maya++;
                    sahil++;
                    rohsesh++;
                }
                else
                {
                    indu++;
                }
                System.out.println("Q6. Who is your sworn Enemy ");
                System.out.println("a: Mom  b: Dad  c: Spouse  d: SonORSon-in-Law");
                char q6 = in.next().charAt(0);
                if(q6=='a')
                {
                   
                    monisha++;
                    dush++;
                   
                }
             else if(q6=='b')
             {
                 sahil++ ;
                 rohsesh++;
                 ;
                dush++ ;
                }
                else if(q6=='c')
                {
                    dush++;
                    indu++;
                    maya++;
                    sahil++;
                    rohsesh++;
                }
                else
                {
                    indu++;
                }
                {
               while(i!=1)//If the points of any heroes are equal , then we deal with it in this block
            {
               {
                if(dush==sahil)
                {
           System.out.println("Congratulations, You Actually match the traits of two superheroes");
       System.out.println("You seem to an INTERESTING person ; I hope that I am not wrong . You are the most INTELLIGENT person in the family ; you are SAHIL ");
        }
        else if(dush==maya)
        {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
       System.out.println("You seem to be HIGH CLASS and SELF LOVING but sometimes you also can be SNOBBISH , you are MAYA");
    }
    else if(dush==indu)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
        System.out.println("You seem to be a CONSPIRING and FUN LOVING person , People can also LOVE you or HATE you because of your SENSE OF HUMOUR , you are INDRAVADAN" );
    }
    else if(dush==rohsesh)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
         System.out.println("You seem to be a very COMPLICATED person , very fond of your ARTISTIC talents writing Poems everytime , you are ROHSESH SARABHAI");
    }
    else if(dush==monisha)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
         System.out.println("You seem to be a MIDDLE CLASS person , very fond of SIMPLE THINGS  and ready to leave your In-Law's home anytime , You are MONISHA (OLD MANISHA)");
        }
        System.out.println("You seem to a GIZMO-FREAK ;you are very dedicated to your work even more than your life and family .  you are DUSHYANT ");
         if(true)
         break;
        }
            if(sahil>=dush&&sahil>=indu&&sahil>=maya&&sahil>=rohsesh&&sahil>=monisha)
            {
                if(sahil==dush){
           System.out.println("Congratulations, You Actually match the traits of two superheroes");
        System.out.println("You seem to a GIZMO-FREAK ;you are very dedicated to your work even more than your life and family .  you are DUSHYANT ");
        }
        else if(sahil==maya)
        {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
System.out.println("You seem to be HIGH CLASS and SELF LOVING but sometimes you also can be SNOBBISH , you are MAYA");
    }
     else if(sahil==rohsesh)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
         System.out.println("You seem to be a very COMPLICATED person , very fond of your ARTISTIC talents writing Poems everytime , you are ROHSESH SARABHAI");
    }
    else if(sahil==indu)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
         System.out.println("You seem to be a CONSPIRING and FUN LOVING person , People can also LOVE you or HATE you because of your SENSE OF HUMOUR , you are INDRAVADAN" );
    }
     else if(sahil==monisha)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
         System.out.println("You seem to be a MIDDLE CLASS person , very fond of SIMPLE THINGS  and ready to leave your In-Law's home anytime , You are MONISHA (OLD MANISHA)");
        }
System.out.println("You seem to an INTERESTING person ; I hope that I am not wrong . You are the most INTELLIGENT person in the family ; you are SAHIL ");
break;          
}
             if(indu>=sahil&&indu>=dush&&indu>=maya&&indu>=rohsesh&&indu>=monisha)
             {
                if(indu==dush)
                {
           System.out.println("Congratulations, You Actually match the traits of two superheroes");
        System.out.println("You seem to a GIZMO-FREAK ;you are very dedicated to your work even more than your life and family .  you are DUSHYANT ");
        }
         else if(indu==rohsesh)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
         System.out.println("You seem to be a very COMPLICATED person , very fond of your ARTISTIC talents writing Poems everytime , you are ROHSESH SARABHAI");
    }
        else if(indu==maya)
        {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
System.out.println("You seem to be HIGH CLASS and SELF LOVING but sometimes you also can be SNOBBISH , you are MAYA");
    }
    else if(indu==sahil)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
System.out.println("You seem to an INTERESTING person ; I hope that I am not wrong . You are the most INTELLIGENT person in the family ; you are SAHIL ");
    }
     else if(indu==monisha)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
         System.out.println("You seem to be a MIDDLE CLASS person , very fond of SIMPLE THINGS  and ready to leave your In-Law's home anytime , You are MONISHA (OLD MANISHA)");
        }
 System.out.println("You seem to be a CONSPIRING and FUN LOVING person , People can also LOVE you or HATE you because of your SENSE OF HUMOUR , you are INDRAVADAN" );
 break;
}
             if(maya>=dush&&maya>=rohsesh&&maya>=indu&&maya>=indu&&maya>=monisha)
                   {
                if(maya==dush)
                {
           System.out.println("Congratulations, You Actually match the traits of two superheroes");
        System.out.println("You seem to a GIZMO-FREAK ;you are very dedicated to your work even more than your life and family .  you are DUSHYANT ");
        }
        else if(maya==rohsesh)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
         System.out.println("You seem to be a very COMPLICATED person , very fond of your ARTISTIC talents writing Poems everytime , you are ROHSESH SARABHAI");
    }
   
        else if(maya==indu)
        {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
 System.out.println("You seem to be a CONSPIRING and FUN LOVING person , People can also LOVE you or HATE you because of your SENSE OF HUMOUR , you are INDRAVADAN" );
    }
    else if(maya==sahil)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
System.out.println("You seem to an INTERESTING person ; I hope that I am not wrong . You are the most INTELLIGENT person in the family ; you are SAHIL ");
    }
     else if(maya==monisha)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
         System.out.println("You seem to be a MIDDLE CLASS person , very fond of SIMPLE THINGS  and ready to leave your In-Law's home anytime , You are MONISHA (OLD MANISHA)");
        }
System.out.println("You seem to be HIGH CLASS and SELF LOVING but sometimes you also can be SNOBBISH , you are MAYA");
break;          
}
 if(monisha>=sahil&&monisha>=dush&&monisha>=maya&&monisha>=rohsesh&&monisha>=indu)
             {
                if(monisha==dush)
                {
           System.out.println("Congratulations, You Actually match the traits of two superheroes");
        System.out.println("You seem to a GIZMO-FREAK ;you are very dedicated to your work even more than your life and family .  you are DUSHYANT ");
        }
         else if(monisha==rohsesh)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
         System.out.println("You seem to be a very COMPLICATED person , very fond of your ARTISTIC talents writing Poems everytime , you are ROHSESH SARABHAI");
    }
        else if(monisha==maya)
        {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
System.out.println("You seem to be HIGH CLASS and SELF LOVING but sometimes you also can be SNOBBISH , you are MAYA");
    }
    else if(monisha==sahil)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
System.out.println("You seem to an INTERESTING person ; I hope that I am not wrong . You are the most INTELLIGENT person in the family ; you are SAHIL ");
    }
     else if(monisha==indu)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
                        System.out.println("You seem to be a CONSPIRING and FUN LOVING person , People can also LOVE you or HATE you because of your SENSE OF HUMOUR , you are INDRAVADAN" );
        }
 System.out.println("You seem to be a MIDDLE CLASS person , very fond of SIMPLE THINGS  and ready to leave your In-Law's home anytime , You are MONISHA (OLD MANISHA)");
 break;
}
 if(rohsesh>=sahil&&rohsesh>=dush&&rohsesh>=maya&&rohsesh>=monisha&&rohsesh>=indu)
             {
                if(rohsesh==dush)
                {
           System.out.println("Congratulations, You Actually match the traits of two superheroes");
        System.out.println("You seem to a GIZMO-FREAK ;you are very dedicated to your work even more than your life and family .  you are DUSHYANT ");
        }
         else if(rohsesh==monisha)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
         System.out.println("You seem to be a MIDDLE CLASS person , very fond of SIMPLE THINGS  and ready to leave your In-Law's home anytime , You are MONISHA (OLD MANISHA)");
    }
        else if(rohsesh==maya)
        {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
System.out.println("You seem to be HIGH CLASS and SELF LOVING but sometimes you also can be SNOBBISH , you are MAYA");
    }
    else if(rohsesh==sahil)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
System.out.println("You seem to an INTERESTING person ; I hope that I am not wrong . You are the most INTELLIGENT person in the family ; you are SAHIL ");
    }
     else if(rohsesh==indu)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
                        System.out.println("You seem to be a CONSPIRING and FUN LOVING person , People can also LOVE you or HATE you because of your SENSE OF HUMOUR , you are INDRAVADAN" );
        }
 System.out.println("You seem to be a very COMPLICATED person , very fond of your ARTISTIC talents writing Poems everytime , you are ROHSESH SARABHAI");
 break;
}  

        }
    }
           //This Block in Particular is far more effective than the following Block, which is actually the easy way!  
             /*   if(dush>sahil&&dush>indu&&dush>maya&&dush>rohsesh&&dush>monisha)
                System.out.println("You seem to a GIZMO-FREAK ;you are very dedicated to your work even more than your life and family .  you are DUSHYANT ");
                else if(sahil>dush&&sahil>indu&&sahil>maya&&sahil>rohsesh&&sahil>monisha)
                System.out.println("You seem to an INTERESTING person ; I hope that I am not wrong . You are the most INTELLIGENT person in the family ; you are SAHIL ");
                else if(indu>dush&&indu>sahil&&indu>maya&&indu>rohsesh&&indu>monisha)
                System.out.println("You seem to be a CONSPIRING and FUN LOVING person , People can also LOVE you or HATE you because of your SENSE OF HUMOUR , you are INDRAVADAN" );
                 else if(maya>dush&&maya>sahil&&maya>indu&&maya>rohsesh&&maya>monisha)
                System.out.println("You seem to be HIGH CLASS and SELF LOVING but sometimes you also can be SNOBBISH , you are MAYA");
                  else if(rohsesh>dush&&rohsesh>sahil&&rohsesh>maya&&rohsesh>indu&&rohsesh>monisha)
                  System.out.println("You seem to be a very COMPLICATED person , very fond of your ARTISTIC talents writing Poems everytime , you are ROHSESH SARABHAI");
                  else if(monisha>dush&&monisha>sahil&&monisha>maya&&monisha>indu&&monisha>rohsesh)
                  System.out.println("You seem to be a MIDDLE CLASS person , very fond of SIMPLE THINGS  and ready to leave your In-Law's home anytime , You are MONISHA (OLD MANISHA)");
                */
                }
            }
       

Friday 10 July 2015

'GUESS THE NUMBER' - THE GAME

/* We all have played Guess the Number in our childhood
 * It is a two player game , in which one player has to guess the number ,the other player had selected .
 * Although , he gets a limited amount of chances to do so.
 * So lets begin :
 */
My Output

import java.util.*; //I am using Scanner class to take the input
class Guess_the_number
{
    int num,ch ;//My global variables
    Scanner in = new Scanner(System.in);
   public void main()// The main method
    {
        System.out.println("Guess The Number");
        Random ran = new Random();
        for(int i = 0; ; )
        {
        System.out.println("\nTo guess a number between 0 and 100 , enter 0 \nTo guess a number between 0 and 1000 ,enter 1\nIf you want to exit ,enter any other number.");
        int no_ch = in.nextInt();//To take user's choice
        if(no_ch==0)
        {
            ch = 5 ;//Number of chances left
            System.out.println("You will have 5 chances to guess the correct number \n");
           num = 0 + ran.nextInt(100);//To get the random number
        }
        else if(no_ch==1)
        {
            ch=7;//Number of chances left
            System.out.println("You will have 7 chances to guess the correct number \n");
            num = 0 + ran.nextInt(1000);//To get the random number or computer's choice
        }
        else
        {
            System.out.println("Thank you for playing!!");
            break;
        }
        while(ch!=0){
        System.out.println("\nEnter your Guess");
        int guess = in.nextInt();//To input the guess
        boolean result = play(guess);
        if(result==true)
        break;
    }
    if(ch==0)
    System.out.println("Hard Luck ! The number was "+num);
}
}
    private boolean play(int guess)//The main computation
    {
        if(guess>num)
        {
            System.out.println("Lower!");
            ch--;
            System.out.println("You have "+ch+" chances left");
            return false;
        }
        else if(guess<num)
        {
            System.out.println("Higher!");
            ch--;
            System.out.println("You have "+ch+" chances left");
            return false;
        }
        else // If user's guess and computer's guess are equal
        {
        System.out.println("Good job! You did manage to guess the correct Number");
        return true;
    }
}
}
           

           
       
                                                                                          -Shashwat Srivastava

Sunday 28 June 2015

' ROCK-PAPER-SCISSOR-LIZARD-SPOCK ' : GAME IN JAVA

/* ROCK-PAPER-SCISSOR-LIZARD-SPOCK */

My Computation

import java.util.*;//Taking Input through Scanner class
import java.util.Random;//Importing class in order to get a random number [required later]
class rpsls
{
    Scanner in = new Scanner(System.in);
    public  void input()//To take the input
    {
     
        System.out.println("Hey, remember how we used to play 'Stone-Paper-Scissor' in our childhood??");
        System.out.println("So , here is a modified version of the game : Stone-Paper-Scissor-Lizard-Spock \n");
        System.out.println("For rules , check the wiki page,i.e: https://en.wikipedia.org/wiki/Rock-paper-scissors#Additional_weapons");
        System.out.println("\n Enter the numbers adjacent to the names : 0-Rock , 1-Spock , 2-Paper , 3-Lizard and 4-Scissor");
     
        int cond = 7 ;
        for(int i = 1 ;cond!=9 ;i++)//To ensure that the game ends when user inputs '9'
        {
            System.out.println("Enter your choice");
            int ch = in.nextInt();
            if(ch>4||ch<0)//to check the validity of the number
            {
                System.out.println("Enter a valid number");
            break;
        }
            player_chooses(ch);
            compute(ch);
            cond = in.nextInt();//whether the user wants to end the program or not
         
        }
        System.out.println("Thank you for playing!");
    }
    private void compute(int ch)//This is the main function that computes the result
    {
     Random generator = new Random();
     int comp_choice = generator.nextInt(5) + 0;//To generate a number between 0-4
     comp_chooses(comp_choice);
     int diff = (ch - comp_choice)%5;//This was my method of decreasing the length of the program ; Otherwise, it would have reqiured us to write 5*5 lines of code
     if(diff==0)
     System.out.println("Match tie!");
     else if(diff==1||diff==2)
     System.out.println("Player wins!");
     else
     System.out.println("Computer wins!");
     System.out.println("\n If you want to exit press 9 , else press any digit");
    }
    private void player_chooses(int ch)//To print user's choice
    {
        switch (ch)
        {
            case 0:
            System.out.println("Player chooses Rock");
            break;
            case 1:
            System.out.println("Player chooses Spock");
            break;
            case 2:
            System.out.println("Player chooses Paper");
            break;
            case 3:
            System.out.println("Player chooses Lizard");
            break;
            case 4:
            System.out.println("Player chooses Scissor");
            break;
        }
}
private void comp_chooses(int ch)//To print computer's choice
    {
        switch (ch)
        {
            case 0:
            System.out.println("Computer chooses Rock");
            break;
            case 1:
            System.out.println("Computer chooses Spock");
            break;
            case 2:
            System.out.println("Computer chooses Paper");
            break;
            case 3:
            System.out.println("Computer chooses Lizard");
            break;
            case 4:
            System.out.println("Computer chooses Scissor");
            break;
        }
}
}
         
        

Tuesday 26 May 2015

WHICH SUPER HERO ARE YOU???

/* We all have favourite Superheroes , but which Superhero belongs to you??
 * You have to answer some questions.
 * The heroes we are taking into account are batman , superman , ironman ,and spiderman.
 * Later , you can modify this program to your own convenience , may be you can change the superheroes
 */   

MY INPUT


import java.util.*;//I am using Scanner class to take the input
    class WhichSuperHeroareyou
    {
        public void SuperHero()//The main function
        {
           int batmn = 0 , supermn  = 0 , ironmn = 0 ,  spidey = 0  ; //The heroes we are taking into account are batman , superman , ironman ,and spiderman.
           for(int j = 1;j<2;j++)//To end the program when 'e' is entered
           {
               Scanner in = new Scanner(System.in);
            System.out.println("Welcome to the Quiz - 'Which Super Hero are you ?'");
            System.out.println();
            System.out.println(" Heroes  are a SYMBOL and remember It's not about money or anything but sending a MESSAGE ");
            System.out.println();
            System.out.println("Kindly Enter your Name ");
            String n = in.next();
            System.out.println("Hey dear "+n+" ,if you are in a hurry you can press 'e' any time end this 'Interrogation' Scenario although your result will no doubt be declared "); 
            System.out.println();
            System.out.println("Q1. What is your IMAGINERY family background ? ");
            System.out.println("a. Gods   b. Wealthy Business Tycoons  c. Devotees of the Country   d. Middle Class Family  ");
            char q1 = in.next().charAt(0);
            if(q1=='a')
             supermn++ ;
             else if(q1=='b')
             {
             batmn++;
             ironmn++;
            }
             else if(q1=='c')
             {
                 batmn++;
                 
                }
                else if(q1=='d')
                spidey++;
               else if(q1=='e')
                break;
             System.out.println("Q2. What trait would compel you to become a Hero ?");
             System.out.println("a. You are Different from others   b. The Death of your Loved ones  c. After seeing the miserable condition of the world   d. Some incident related to you  ");
             char q2 = in.next().charAt(0);
             if(q2=='a')
             supermn++ ;
             else if(q2=='b')
             spidey++;
             else if(q2=='c')
             {
                 ironmn++;
                 batmn++;
                }
               else if(q2=='e')
                break;
                System.out.println("Q3. What SuperPowers do you wanna have (along woth enormous Strength) ?");
                System.out.println("a. Intelligence   b. Any Power you have inherited from any other animal or so   c. Abilty to fly   d. Self Made Weapons  ");
                char q3 = in.next().charAt(0);
                if(q3=='a')
             batmn++ ;
             else if(q3=='b')
             spidey++;
             else if(q3=='c')
             supermn++;
             else if(q3=='e')
             break;
             else
             ironmn++;
             System.out.println("Q4. Do you want your identity to be Hidden ? ");
             System.out.println("a. Yes   b. No");
             char q4 = in.next().charAt(0);
             if(q4=='a')
             {
                 batmn++ ;
                 spidey++ ;
                
            }
            else if(q1=='e')
             break;
            else
            {
                supermn++ ;
                ironmn++ ; 
            }
            System.out.println("Q5. What would you do if you are supposed to go to a one-way mission and you know that there is no coming back ? ") ;
            System.out.println(" a. Search for a backup plan  b. Go there without thinking of the consequence   c. Help the people in any other way   d. Run away w.ith your loved ones ") ;
            char q5 = in.next().charAt(0);
             if(q5=='a')
             batmn++ ;
             else if(q5=='b')
             supermn++;
             else if(q5=='c')
             {
                 spidey++;
                 ironmn++ ;
                }
             else if(q5=='e')
             break;
                 System.out.println("Q6. What do you want people to think of you as ? ") ;
                  System.out.println(" a. You don't give damn   b. Their only Hope   c. A Freak   d. A crazy Billionare having time to do all this idiotic charity  ") ;
                  char q6 = in.next().charAt(0);
                   if(q6=='a')
             batmn++ ;
             else if(q6=='b')
             supermn++;
             else if(q6=='c')
             spidey++;
             else if(q6=='e')
             break;
             else
             ironmn++;
             System.out.println("Q7. If you are stuck at something whom would you take advice from ? ") ;
            System.out.println("a. People that you Trust   b. You do not need any help or even if you do , you would help yourself out   c. Your Family   d. Your Business Associates ");
            char q7 = in.next().charAt(0);
            if(q7=='a')
             batmn++ ;
             else if(q7=='b')
             supermn++;
             else if(q7=='c')
             spidey++;
             else if(q7=='e')
             break;
             else
             ironmn++;
        }
        if(batmn>=supermn&&batmn>=spidey&&batmn>=ironmn)//If the points of any heroes are equal , then we deal with it in this block 
            {
                if(batmn==supermn)
                {
           System.out.println("Congratulations, You Actually match the traits of two superheroes");
        System.out.print(" You are the Great Alien Warrior , Superman , who came from the planet Krypton . No one can defeat you in Strength as well as ");
        }
        else if(batmn==ironmn)
        {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
        System.out.println(" You are Ironman played by Robert Downy Jr. the Billionare who became a Super Hero when Kidnapped by a terrorist organisation  . You are worthy of a Noble Prize for your contribution in the field of Technology as well as ");
    }
    else if(batmn==spidey)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
        System.out.println(" You are Spiderman , Truly brilliant in your speed and aim . You accidently when bit by a hybrid spider became the great Hero that you are !! &");
    }  
             System.out.println(" You are the Dark Knight The Batman , You fight for Gotham city from the Dark Side . Bruce Wayne has been played by Christian Bale in the Batman Trilogy . You are best in your Intelligence and Fighting Technique that you learnt from Ra's Al Ghul ");
            }
            if(supermn>=batmn&&supermn>=spidey&&supermn>=ironmn)
            {
                if(supermn==batmn){
           System.out.println("Congratulations, You Actually match the traits of two superheroes");
        System.out.print(" You are the Dark Knight The Batman , You fight for Gotham city from the Dark Side . Bruce Wayne has been played by Christian Bale in the Batman Trilogy . You are best in your Intelligence and Fighting Technique that you learnt from Ra's Al Ghul as well as ");
        }
        else if(supermn==ironmn)
        {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
        System.out.println(" You are Ironman played by Robert Downy Jr. the Billionare who became a Super Hero when Kidnapped by a terrorist organisation  . You are worthy of a Noble Prize for your contribution in the field of Technology as well as ");
    }
    else if(supermn==spidey)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
        System.out.println(" You are Spiderman , Truly brilliant in your speed and aim . You accidently when bit by a hybrid spider became the great Hero that you are !! &");
    }  
             System.out.println(" You are the Great Alien Warrior , Superman , who came from the planet Krypton . No one can defeat you in Strength ");
            } 
             if(spidey>=supermn&&spidey>=batmn&&spidey>=ironmn) 
             {
                if(spidey==batmn)
                {
           System.out.println("Congratulations, You Actually match the traits of two superheroes");
        System.out.print(" You are the Dark Knight The Batman , You fight for Gotham city from the Dark Side . Bruce Wayne has been played by Christian Bale in the Batman Trilogy . You are best in your Intelligence and Fighting Technique that you learnt from Ra's Al Ghul as well as ");
        }
        else if(spidey==ironmn)
        {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
        System.out.println(" You are Ironman played by Robert Downy Jr. the Billionare who became a Super Hero when Kidnapped by a terrorist organisation  . You are worthy of a Noble Prize for your contribution in the field of Technology as well as ");
    }
    else if(spidey==supermn)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
        System.out.println(" You are the Great Alien Warrior , Superman , who came from the planet Krypton . No one can defeat you in Strength & ");
    }
        System.out.println(" You are Spiderman , Truly brilliant in your speed and aim . You accidently when bit by a hybrid spider became the great Hero that you are !!");
    }  
             if(ironmn>=batmn&&ironmn>=spidey&&ironmn>=spidey)
                   {
                if(ironmn==batmn)
                {
           System.out.println("Congratulations, You Actually match the traits of two superheroes");
        System.out.print(" You are the Dark Knight The Batman , You fight for Gotham city from the Dark Side . Bruce Wayne has been played by Christian Bale in the Batman Trilogy . You are best in your Intelligence and Fighting Technique that you learnt from Ra's Al Ghul as well as ");
        }
        else if(ironmn==spidey)
        {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
         System.out.println(" You are Spiderman , Truly brilliant in your speed and aim . You accidently when bit by a hybrid spider became the great Hero that you are !! &");
    }
    else if(ironmn==supermn)
    {
        System.out.println("Congratulations, You Actually match the traits of two superheroes");
        System.out.println(" You are the Great Alien Warrior , Superman , who came from the planet Krypton . No one can defeat you in Strength as well as");
    }
             System.out.println(" You are Ironman played by Robert Downy Jr. the Billionare who became a Super Hero when Kidnapped by a terrorist organisation  . You are worthy of a Noble Prize for your contribution in the field of Technology ");
            } 
        }
    }    
MY OUTPUT
*KINDLY EXPRESS YOUR VIEWS REGARDING THE PROGRAM BELOW IN THE COMMENTS SECTION
                                                                                                                                                                                                                                                                              - SHASHWAT SRIVASTAVA
 

Saturday 9 May 2015

A PROGRAM TO ENABLE USERS TO ORDER PIZZAS ONLINE !!!

/*DO YOU WONDER HOW DO WE ORDER A PIZZA WITH ALL ITS TOPPINGS AND OTHER STARTERS ONLINE??
 * SO HERE IS THE PROGRAM TO DO JUST THAT
 * WELL ,PERSONALLY I BELIEVE THAT IN THE NEAR FUTURE THE WAITERS WOULD BE TAKEN OVER BY MACHINES RUNNING ON PROGRAMS LIKE THESE.
 */ 

My INPUT
   

 import java.util.*;//using Scanner class to take input
    class pizza
    {
        Scanner in = new Scanner(System.in);
        void main()
        {
            System.out.println("Enter the Total Types of Pizzas and Starters in total that  you are going to order");
            int tt  = in.nextInt();
            double price[] = new double[tt ];
            double bill = 0.0 ;
            String top[] = new String[tt ];
            String options[] = new String[tt ];
            int quantity[] = new int[tt ];
            String size[] = new String[tt ];
            int ch , temp = 0 , qty,tp,sz;
            double pr=0.0 ;
            System.out.println("KINDLY ENTER YOUR NAME");
            String nm = in.next();//to input name
            System.out.println("The prices written will simply add to the Total Bill ");
            System.out.println("Kindly enter the NUMBERS written along with the option to select that option");
            System.out.println("Remember if your bill exceeds 100$ we offer you 4% rebate/discount on your bill");
            for(temp= 0 ;temp<tt   ; )
            {
             
            System.out.println("Enter the Type of Pizza You want. ");
            System.out.println(" 1.Veg Treat   2.Special Non Veg   3.Starters  ");
            int op1 = in.nextInt();//to input Choice
            switch (op1)
            {
                case 1:
                System.out.println("Pick your choice");
                System.out.println("1. Veg. Extravaganza[5$]   2. Cloud 9[8$]     3.Paradise[10$]    4.Mexican[12$]   5.Delux[15$]");
                ch = in.nextInt();//to input Choice
               System.out.println("Enter quantity ");
                qty = in.nextInt();
                quantity[temp] = qty ;//to input quantity
                switch (ch)
                {
                    case 1:
                options[temp] = "Veg. Extravaganza     " ;
                price[temp] = 5.0*qty;
                break;
                case 2:
                options[temp] = "Cloud                 ";
                price[temp] = 9.0*qty;
                break;
                case 3:
                options[temp] = "Paradise               " ;
                 price[temp] = 10.0*qty;
                break;
                case 4:
                options[temp] = "Mexican                 " ;
                 price[temp] = 12.0*qty;
                break;
                case 5:
                options[temp] = "Delux                   " ;
                 price[temp] = 15.0*qty;
                break;
            }
                System.out.println("Enter Size of Pizzas");
                System.out.println("1. Regular[5$]   2.Medium[7$]    3.Large[10$]");
                sz = in.nextInt();
              switch (sz)
                {
                    case 1:
                    price[temp] +=5.0;
                    size[temp] = "Regular";
                    break;
                    case 2:
                    price[temp]+=7.0;
                    size[temp] = "Medium";
                    break;
                    case 3:
                    price[temp]+=10.0;
                    size[temp] = "Large";
                    break;
                }
                System.out.println("Enter the toppings you want");
                System.out.println("1. Cheese Burst[5$]    2. Fresh Pan [7$]   3.Classic[10$]       4.Wheat Crust[12$]");
                tp = in.nextInt();
                switch (tp)
                {
                    case 1:
                    price[temp] +=5.0;
                    top[temp] = "Cheese Burst";
                    break;
                    case 2:
                    price[temp]+=7.0;
                    top[temp] = "Fresh Pan ";
                    break;
                    case 3:
                    price[temp]+=10.0;
                    top[temp] = "Classic";
                    break;
                    case 4:
                    price[temp]+=12.0;
                    top[temp] = "Wheat Crust";
                    break;
                }temp++;
         System.out.println("ORDER RECORDED");
           break;
           case 2:
                System.out.println("Pick your choice");
                System.out.println("1. Cheese & BPQ Chicken[7$]  2. Zesty Pork [10$]     3.Golden Delight[13$]    4.Salami special[15$]   5.Hawaiian Twist[18$]");
                ch = in.nextInt();
                System.out.println("Enter quantity ");
                qty = in.nextInt();
                quantity[temp] = qty ;
                switch (ch)
                {
                 case 1:
                options[temp] = "Cheese & BPQ Chicken   " ;
                price[temp] = 7.0*qty;
                break;
                case 2:
                options[temp] = "Zesty Pork           ";
                price[temp] = 10.0*qty;
                break;
                case 3:
                options[temp] = "Golden Delight       " ;
                 price[temp] = 13.0*qty;
                break;
                case 4:
                options[temp] = "Salami special       " ;
                 price[temp] = 15.0*qty;
                break;
                case 5:
                options[temp] = "Hawaiian Twist        " ;
                 price[temp] = 18.0*qty;
                break;
            }
                System.out.println("Enter Size of Pizzas");
                System.out.println("1. Regular[6$]   2.Medium[8$]    3.Large[11$]");
                sz = in.nextInt();
             
                switch (sz)
                {
                    case 1:
                    price[temp] +=6.0;
                    size[temp] = "Regular";
                    break;
                    case 2:
                    price[temp]+=8.0;
                    size[temp] = "Medium";
                    break;
                    case 3:
                    price[temp]+=11.0;
                    size[temp] = "Large";
                    break;
                }
                ;
                System.out.println("Enter the toppings you want");
               System.out.println("1. Cheese Burst[7$]    2. Fresh Pan [9$]   3.Classic[13$]       4.Wheat Crust[15$]");
                tp = in.nextInt();
                switch (tp)
                {
                    case 1:
                    price[temp] +=7.0;
                    top[temp] = "Cheese Burst           ";
                    break;
                    case 2:
                    price[temp]+=9.0;
                    top[temp] = "Fresh Pan             ";
                    break;
                    case 3:
                    price[temp]+=13.0;
                    top[temp] = "Classic              ";
                    break;
                    case 4:
                    price[temp]+=15.0;
                    top[temp] = "Wheat Crust           ";
                    break;
                }
                temp++;
                     System.out.println("ORDER RECORDED");
             break;
            case 3:
                System.out.println("Pick your choice");
                System.out.println("1. Mexican Roll[5$]   2. Coca-cola[8$]   3. Choco Lava Cake[12$]  4. Lemonade[4$] ");
                ch = in.nextInt();
                System.out.println("Enter quantity ");
                qty = in.nextInt();
                quantity[temp] = qty ;
                switch (ch)
                {
                    case 1:
                    price[temp] +=(5.0*qty);
                    options[temp] = "Mexican Roll         ";
                    break;
                    case 2:
                    price[temp]+=(8.0*qty);
                    options[temp] = "Coca-cola             ";
                    break;
                    case 3:
                    price[temp]+=(12.0*qty);
                    options[temp] = "Choco Lava Cake        ";
                    break;
                    case 4:
                    price[temp]+=(8.0*qty);
                    options[temp] = "Lemonade               ";
                    break;
                }
                size[temp]= "N/A";
                top[temp] = "N/A";
            temp++;
            System.out.println("ORDER RECORDED");
            break ;
            default:
            System.out.println("Wrong Choice. Kindly re-enter");
        }
    }
    double disc = 0.0 ;
    for(int j = 0 ; j<tt  ; j++)
    pr = price[j]+pr;
    if(pr>=100.0)
    disc = (0.04)*pr;
    bill = pr-disc;
System.out.println("\n \n \n");
System.out.println("############################# WELCOME TO DOMINOS ############################");
    System.out.println("\n $$$$$$$$$ SO YOUR BILL $$$$$$$$$$$");
    System.out.println();
    System.out.println("PIZZAS ORDERED            QUANTITY        COST       SIZE           TOPPINGS \n ");
    for(int l = 0 ; l<tt  ; l++)//To print the elements of the arrays
    System.out.println(options[l]+"    "+quantity[l]+"          "+price[l]+"         "+size[l]+"           "+top[l]);
    System.out.println("Your Bill = "+pr);
    System.out.println("Your Total Discount = "+disc);
    System.out.println("Your Final Bill = "+bill);
    System.out.println("\n *************THANK YOU***************");
    System.out.println("KINDLY VISIT AGAIN");
    System.out.println();
    System.out.println();
    System.out.println();
    System.out.println("________________________");
    System.out.println("  "+nm);
    System.out.println("         SIGNATURE");
    System.out.println("YOUR ORDER WOULD BE DELIVERED IN 30 MINUTES ");
    System.out.println("\n ********************* HAVE A NICE DAY!!! *************************");
}
}

MY OUTPUT


// PLEASE GIVE SUGGESTIONS AND ASK  QUESTIONS DOWN IN THE COMMENTS SECTION