0

hi there i have some python coding which i need to convert to java can ne1 help me please email me back if you can help then i will show you the coding much appriciated

5
Contributors
7
Replies
46
Views
12 Years
Discussion Span
Last Post by Arpita_1
0

what it is is that i need to convert it to proper java so it can be run on actual java software thnaks for the link though

0

HERE IS THE CODE

import javax.swing.JOptionPane;

//=== CONSTANTS ====
public class version21
{
//decalaration
    private int LOWER_EASY = 0;
    private int UPPER_EASY = 100;
    private boolean FIRST = true;
    private boolean OTHER = false;
    String numG;
    private int numGoes, totalGoes, numCorrect;
    private boolean start, carryOn;
    private int num;
    private int guess,getGuess;
    private boolean playAgain;
    private boolean tryAgain;
    private boolean retValue;
    private boolean numGuesses;

    public static void main(String [] args)
    {
    // === declare and initialise main's local variables ===
        numGoes = 0;  //number of times the game is played
        totalGoes = 0;   // total number of guesses made
        start = true;
        numCorrect = 0;

    // === BEGIN MAIN LOOP FOR THE GAME ===

        while (start){
            numGuesses = 0;
            boolean carryOn = true;
            String s;
            int guess = Integer.parseInt(JOptionPane.showInputDialog(null,"pick a number between 1 and 100"));
            int num = Random.nextInt(UPPER_EASY-LOWER_EASY)+LOWER_EASY; //range between LOWER_EASY and UPPER_EASY
            System.out.println("For testing purposes the num generated is: "+num);
            numGuesses++;
        }//while (start)
        // === GET USERS GUESSES. LOOP 'TIL THEY EITHER GET IT RIGHT OR GIVE UP ===

        while (guess != num && carryOn)
        {
            carryOn = tryAgain(guess, num);
            if (carryOn)
            {
                guess = getGuess(OTHER);
                numGuesses += 1;
            }//if (carryOn)
        }//while guess

        if (guess == num)
        {
            numG = numGuesses;
            String sInput = JOptionPane.showMessageDialog ("Great! You got it right in " + numG + " goes!");
            numCorrect += 1;

            totalGoes += numGuesses;

            start = playAgain();
        }//if
   // === END MAIN-LOOP

        outputResults(numCorrect, numGoes, totalGoes);

    public static int getGuess()
    {
        System.out.println ( "... getting guess");
        guess = 0; // some dummy value to pass back
        JOptionPane.showInputDialog(null, "guess");
    }//getguess()

    public static String tryAgain()
    {
        System.out.printLn(" .... seeing if user wants to guess again");
        retValue = false; // some dummy value to pass back
        return JOptionPane.showMessageDialog(null, "retValue");
    }//tryagain()

    public static String playAgain()
    {
        retValue = false; // some dummy value to pass back
        System.out.printLn( "That Game's over.... checking for play again ... ");
        return JOptionPane.showMessageDialog(null, "retValue");
    }//playagain()

    public static int outputResults(String correct, int timesPlayed, int totalAttempts)
    {
        System.out.printLn( "Thanks for playing.. hope you had fun...");
        System.out.printLn( "You played" + timesPlayed +"times.");
        System.out.printLn( "You guessed correctly" + correct + "times, and you gave up" + timesPlayed - correct + "times");
    }//outputresults()

    public static String validResponse( )
        {
        System.out.println( "...checking that value supplied by user is in the right range");
        ok = true; // some dummy value to pass back
        return JOptionPane.showMessageDialog(null, "ok");
        }//validresponse()




}//Version21

Edited by pyTony: fixed formating

0
def Get_Data(Input):
         New_List = []
             for i in range(len(Input)):
                 New_List.append(Input[i])
         return Check_Twain(New_List)

     def Check_Twain(List_Data):
         for b in range(int((len(List_Data)/2)+1)):
             for a in range(len(List_Data)-1):
                 if List_Data[a] == "(" and List_Data[a+1] == ")" or List_Data[a] == "[" and List_Data[a+1] == "]" or List_Data[a] == "{" and List_Data[a+1] == "}":
                     List_Data.pop((a+1))
                     List_Data.pop(a)
                     break
         return len(List_Data)  

     Input_Number = int(input("กรุณาใส่จำนวนข้อมูลที่ต้องการตรวจสอบ : "))
     List_Data = []

     for i in range(Input_Number):
         List_Data.append(input("กรุณาใส่ข้อมูลที่ต้องการตรวจสอบ : "))

     for s in range(len(List_Data)):
         if Get_Data(List_Data[s]) > 0 :
             print (" no")
         else: 
             print(" yes")
-1
import random
import string

def printAll(conversation):
   for line in conversation:
       print (line)

def main():
   cannedlist = ["How are you?", "Why is the sky blue?" , "How's the
weather?" , "When will it end?" , "Why are we here?" , "Sounds good!",
"That's great!", "What time is it?"]
   num_canned = len(cannedlist)
   response = input("How many rounds of conversation?")
   conversation = []
   number = random.randrange(0,num_canned)
   computer = cannedlist[number]
   print (computer)
   conversation.append(computer)

   # perform specified number of interaction rounds
   for interaction in range(eval(response)):
       user = input("")
       conversation.append(user)

       # search for mirror words and construct response
       userwords = user.split()
       mirror_words_found = False
       computer = ""
       for word in userwords:
           if word == "I":
               new_word = "You"
               mirror_words_found = True;
           elif word == "you":
               new_word = "I"
               mirror_words_found = True;
           elif word == "You":
               new_word = "I"
               mirror_words_found = True;
           elif word == "am":
               new_word = "are"
               mirror_words_found = True;
           elif word == "are":
               new_word = "am"
               mirror_words_found = True;
           elif word == "me":
               new_word = "you"
               mirror_words_found = True;
           elif word == "you're":
               new_word = "I'm"
               mirror_words_found = True;
           elif word == "I'm":
               new_word = "You're"
               mirror_words_found = True;
           else:
               new_word = word
           computer = computer + new_word + " "
       computer = computer.replace(".","?");
       computer = computer.replace("!","?");

       # if we found no mirror words, use a canned response instead
       if not mirror_words_found:
           number = random.randrange(0,num_canned)
           computer = cannedlist[number]

       # use whatever response we came up with
       print (computer)
       conversation.append(computer)

   # end the conversation
   computer = ("Goodbye!")
   print (computer)
   conversation.append(computer)
   print()
   print()
   printAll(conversation)

main()     
print (line)

   # search for mirror words and construct response
   userwords = user.split()
   mirror_words_found = False
   computer = ""
   for word in userwords:
       if word == "I":
           new_word = "You"
           mirror_words_found = True;
       elif word == "you":
           new_word = "I"
           mirror_words_found = True;
       elif word == "You":
           new_word = "I"
           mirror_words_found = True;
       elif word == "am":
           new_word = "are"
           mirror_words_found = True;
       elif word == "are":
           new_word = "am"
           mirror_words_found = True;
       elif word == "me":
           new_word = "you"
           mirror_words_found = True;
       elif word == "you're":
           new_word = "I'm"
           mirror_words_found = True;
       elif word == "I'm":
           new_word = "You're"
           mirror_words_found = True;
       else:
           new_word = word
       computer = computer + new_word + " "
   computer = computer.replace(".","?");
   computer = computer.replace("!","?");

   # if we found no mirror words, use a canned response instead
   if not mirror_words_found:
       number = random.randrange(0,num_canned)
       computer = cannedlist[number]

   # use whatever response we came up with
   print (computer)
   conversation.append(computer)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.