O Dear! Basic Java Programming problem!

import java.lang.*;
import java.util.*;
import java.io.*;
import java.net.*;
import java.util.Random;
public class QuizApp extends Object
     public static void main(String[] argStrings) throws Exception
          Random random = new Random();
          int generateFirstFigure = random.nextInt(21);
          int generateSecondFigure = random.nextInt(31);
          int generateOperator = random.nextInt(3);
          String operator = "/";
          int correctAnswer = generateFirstFigure + generateSecondFigure;
          if (generateOperator == 0)
               operator = "+";
               int correctAnswer = generateFirstFigure + generateSecondFigure;
          if (generateOperator == 1)
               operator = "-";
               int correctAnswer = generateFirstFigure - generateSecondFigure;
          if (generateOperator == 2)
               operator = "/";
               int correctAnswer = generateFirstFigure / generateSecondFigure;
          //int correctAnswer = generateFirstFigure + operator + generateSecondFigure;
          int incorrectAnswerOne = correctAnswer -2;
          int incorrectAnswerTwo = correctAnswer + 1;
          int incorrectAnswerThree = correctAnswer + 3;
          String questionOne = "What is " + generateFirstFigure + operator + generateSecondFigure + "?"; 
          System.out.println(questionOne);
          System.out.println(incorrectAnswerThree);
          System.out.println(incorrectAnswerOne);
          System.out.println(correctAnswer);
          System.out.println(incorrectAnswerTwo);
}Basically this code, creates 2 random characters and then allows you to either add, divide or subtract the two numbers... firstly this bit of the code doesnt work, secondly how can the user input a value (the answer) to the math's question?
Thanks for help,
Joel

practissum wrote:
dketcham, i printed out your hello world pumpkin. its a huge hit in the office!Sorry for propogating the off-topic remarks...but link to the hello world pumpkin?it was the friday coding challenge for last week:
http://forum.java.sun.com/thread.jspa?threadID=5230548&messageID=9941964#9941964
It's all about the pretty colors, and trying to squish a simple little program into a squarish-shape, so that another shape can be put within!
As you can see, I have no real programming skills, but I like pretty colors, so it's all good.

Similar Messages

  • Java Programming Problem

    Hi all,
    I was looking for this java programming problem which had to do with a large building and there was some gallons of water involved in it too somehow and we had to figure out the height of the buiding using java. This problem is also in one of the java books and I really need to find out all details about this problem and the solution. NEED HELP!!
    Thanks
    mac

    Yes, it will. The water will drain from the bottom of
    the tank until the pressure from the water inside the
    tank equals the pressure from the pipe. In other
    words, without a pump, the water will drain out until
    there is the same amount of water in the tank as in
    the pipe The water pressure depends on the depth of the water, not the volume. So once the depth of the water inside the pipe reaches the same depth as the water inside the tank it will stop flowing. This will never be above the height of the tank.
    I found this applet which demonstrates our problem. If you run it you can drag the guy up to the top, when water in his hose reaches the level of the water in the tank it will stop flowing out.

  • Basic Java Program help needed urgently.

    I have posted the instructions to my project assignment on here that is due tomorrow. I have spent an extremely large amount of time trying to get the basics of programming and am having some difficulty off of the bat. Someone who has more experience with this and could walk me through the steps is what I am hoping for. Any Help however will be greatly appreciated. I am putting in a lot of effort, but I am not getting the results I need. Thank you for the consideration of assisting me with my issues. If you have any questions please feel free to ask. I would love to open up a dialogue.
    CIS 120
    Mathematical Operators
    Project-1
    Max possible pts 100
    Write a program “MathOperators” that reads two integers, displays user’s name, sum, product,
    difference, quotients and modulus of the two numbers.
    1. Create a header for your project as follows:
    * Prgrammer: Your Name (1 pt) *
    * Class: CIS 120 (1 pt) *
    * Section: (1 pt) *
    * Instructor: (1 pt) *
    * Program Name: Mathematical Operators (1 pt) *
    * Description: This java program will ask the user to enter two integers and *
    display sum, product, difference, quotients and modulus of the two numbers
    * (5 pts) *
    2. Display a friendly message e.g. Good Morning!! (2 pts)
    3. Explain your program to the user e.g. This java program can add, subtract, multiply,
    divide and calculate remainder of any two integer numbers entered by you. Let’s get
    started…. (5 pts)
    4. Prompt the user- Please enter your first name, store the value entered by user in a
    string variable name. Use input.next() instead of input.nextLine(). (8 pts)
    5. Prompt the user- name, enter first integer number , store the value entered by user in
    an integer variable num1.(5 pts)
    6. Prompt the user- name, enter second integer number , store the value entered by user in
    an integer variable num2.(5 pts)
    7. Display the numbers entered by the user as: name has entered the numbers num1and
    num2.(5 pts)
    8. Calculate sum, product, difference, quotients and modulus of the two numbers. ( 30 pts)
    9. Display sum, product, difference, quotients and modulus of the two numbers. ( 10 pts)
    10. Terminate your program with a friendly message like- Thanks for using my program,
    have a nice day!!(2 pts)

    Nice try. You have not demonstrated that you've at least TRIED to do something. No one is going to do your homework for you. Your "urgency" is yours alone.

  • Basic Java programs.....Please read

    I just need some links to where i can dowload some some basic toolboxes and kits. (to make basic programs and practice)
    Please porvide links, i've been searching. Since I'm so unfamiliar with Java programming i haven't has much luck.

    JSE 1.5 download: http://java.sun.com/javase/downloads/index.jsp
    vim download: http://www.vim.org/download.php
    kind regards,
    Jos

  • Java program problem

    I'm doing this to practise for a competition on Tuesday, if someone can show me how it works, it would be great. I have been stuck on this for a long time. Thank you very much.
    When a share of common stock of some company is sold, the capital gain (or, sometimes loss) is the difference between the share's selling price and the price originally paid to buy it. This rule is easy to understand for a single share, but if we sell multiple shares of stock bought over a long period of time, then we must identify the shares actually being sold. A standard accounting principle for identifying which shares of a stock were sold in such a case is to use a FIFO protocol (i.e., the shares sold are the ones that have been held the longest). Indeed, this is the default method built into several personal finance software packages. Note, however, that it is also possible to use a LIFO protocol (i.e., the shares sold are the ones that were most recently purchased). As an example, suppose we buy 100 shares at $20 each on day 1, 20 shares at $24 on day 2, 200 shares at $36 on day 3, and then sell 150 shares on day 4 at $30 each. Then applying the FIFO protocol means that of the 150 shares sold, 100 were bought on day 1, 20 were bought on day 2, and 30 were bought on day 3. The capital gain for the LIFO case would therefore be 100(30 - 20) + 20(36 - 30) + 30(30 - 36) or $940. Applying the LIFO protocol, on the other hand, means that of the 150 shares sold, all 150 were bought on day 3. The capital gain (or loss in this case) for the LIFO case would therefore be 150(30 - 36) or -$900.
    Create a class named Stock that implements the Tradable interface:
    public interface Tradable {
    public void buy(int numberShares, int pricePerShare);
    public void sell(int numberShares, int pricePerShare);
    public int getCapitalGain();
    Write a Java program that takes as input a sequence of transactions of the form:
    buy x share(s) of stock y at $z each
    -or-
    sell x share(s) of stock y at $z each
    Assume the transactions occur on consecutive days (with respect to each stock). The values of x and z are integers, and the value of y is a string representing the name of the stock. Given this input, the output should be the total capital gain (or loss) for the entire sequence (i.e., all of the activity on all of the client's stocks) using the LIFO protocol to identify shares. Assume that no more than 10 transactions occur for any given stock.
    Modify your code so Stock is observable. Notifications should be sent whenever there is a negative capital gain (i.e., loss) that occurs as the result of the sale of some stock.
    There are two types of observers, traders and their spouses. Create a class named Trader that implements the Observer interface. Both traders and spouses should be instances of Trader. When the trader receives a notification about a capital loss, he/she should output the string "Oh no, what is my spouse going to think!". The spouse should give his/her spouse three chances for each stock (i.e., output "That's your first chance", "That's your second chance", and then finally "That's enough of that!"). After the third chance, the spouse should stop observing the trading activity. Note that traders can observe at most 2 stocks simultaneously.
    Create 5 instances of Stock and 8 instances of Trader that are inter-related and defined in the following table:
    Stock Trader Spouse(s)
    Microsoft Bill Linda
    HP Linda Bill
    IBM Joe
    Dell Susy Jack
    Bob
    Gateway Jack Susy
    Beth
    Mary
    Test your program on various combinations of trading activity.

    I'm doing this to practise for a competition on Tuesday, if someone can show me how it worksUnless I've missed something in your post, there is nothing to show. You've only posted a set of requirements. It works when someone writes code that fulfills the requirement. What are you having trouble with?

  • Java program problems

    Hello all. I've posted for help on this exact same program before, but I'm just having a heck of a time with this.
    Basically, the output should look sometime like this:
    Name Item Value No.Sold Amount
    Joe 1 $2.00 2 $4.00
    2 $3.00 2 $6.00
    Total Amount: $10.00
    Then you should get an option to add another employee using sentinel controlled repetition. So far, this is the code I've got. I came up with most of it, but one of the helpful users here helped me with the rest...
    import javax.swing.*;
    import javax.swing.JOptionPane;
    import javax.swing.JTextArea;
    import java.text.NumberFormat;
    import java.util.Locale;
    public class Pay1 {
    public static void main( String args[] )
    JTextArea outputArea = new JTextArea( 20, 40 );
    JScrollPane scroller = new JScrollPane( outputArea );
    String header = outputArea.getText();
    outputArea.setText(
    "Employee \tItem \tItem Value \tNumber Sold \tDollar Amount" );
    String output, employeeName, itemNumber, itemValue, numberItemsSold;
    int item, sold;
    double value, dollaramount;
    boolean whileLoop = true;
    while ( whileLoop )
    employeeName = JOptionPane.showInputDialog(
    "Enter an employee name" + "\nPress Enter to keep entering data"
    + "\ntype \"exit\" to quit" );
    if ( employeeName.equalsIgnoreCase( "exit" ) )
    break;
    itemNumber = JOptionPane.showInputDialog( "Item number" );
    numberItemsSold = JOptionPane.showInputDialog( "Number of items sold" );
    itemValue = JOptionPane.showInputDialog( "Item value" );
    item = Integer.parseInt( itemNumber );
    sold = Integer.parseInt( numberItemsSold );
    value = Double.parseDouble( itemValue );
    NumberFormat mf = NumberFormat.getCurrencyInstance( Locale.US );
    dollaramount = sold * value;
    output = employeeName + "\t" + item + "\t"
    + mf.format( value ) + "\t" + sold
    + "\t" + mf.format( dollaramount );
    String tmp = outputArea.getText();
    outputArea.setText( tmp + "\n" + output );
    JOptionPane.showMessageDialog( null, scroller, "Payroll Data",
    JOptionPane.PLAIN_MESSAGE );
    System.exit ( 0 );
    I spoke with the instructor in the class, and thought I understood how to do this, but I really just can't get it. If I saw how somebody else did it, then I think I would understand it alot better. So anybody could please help me with this, I would sooo greatly appreciate it. Thanks in advance.

    yep, but slight change,
    import javax.swing.*;
    import javax.swing.JOptionPane;
    import javax.swing.JTextArea;
    import java.text.*;
    import java.util.*;
    public class Pay1 {
          public static void main( String args[] ) {
          JTextArea outputArea = new JTextArea( 20, 40 );
          JScrollPane scroller = new JScrollPane( outputArea );
          outputArea.setText("Employee \tItem \tItem Value \tNumber Sold \tDollar Amount");
          String output, employeeName, itemNumber, itemValue, numberItemsSold;
          int item, sold;
          double value, dollaramount,total=0;
          boolean whileLoop = true;
          String prev = "";
          while (whileLoop ) {
             employeeName = JOptionPane.showInputDialog("Enter an employee name" +
                                         "\nPress Enter to keep entering data" +
                                         "\ntype \"exit\" to quit" );
             if (employeeName.equalsIgnoreCase( "exit" ) ) break;
             if( prev.equalsIgnoreCase( employeeName ) )
                employeeName = "";
             else
                prev = employeeName;
             itemNumber = JOptionPane.showInputDialog( "Item number" );
             numberItemsSold = JOptionPane.showInputDialog( "Number of items sold" );
             itemValue = JOptionPane.showInputDialog( "Item value" );
             item = Integer.parseInt( itemNumber );
             sold = Integer.parseInt( numberItemsSold );
             value = Double.parseDouble( itemValue );
             NumberFormat mf = NumberFormat.getCurrencyInstance( Locale.US );
             dollaramount = sold * value;
             total+=dollaramount;
             String tmp = outputArea.getText();
             int i=tmp.indexOf("Total Amount")-4;  // get rid of total line if present
             if (i<0) i=tmp.length()-1;
             output = employeeName + "\t" + item + "\t" + mf.format( value ) + "\t" +
                sold + "\t" +  mf.format( dollaramount ) +
                "\n\t\t\tTotal Amount:\t"+mf.format (total);   // add total line
             outputArea.setText( tmp.substring(0,i) + "\n" + output );
             JOptionPane.showMessageDialog( null, scroller, "Payroll Data", JOptionPane.PLAIN_MESSAGE );
          System.exit (0 );
    }

  • Multi-lingual Java program/problem

    Hi,
    The following program from the Sun books, is supposed to work with different languages. Except it doesn't!
    It has a problem finding the Properties files (?)
    It gives the following Exception:
    Exception in thread "main" java.util.MissingResourceException: Can't find bundle
    for base name MessagesBundle, locale en_GB
    here is the Sun program:
    import java.util.*;
    public class I18NSample {
    static public void main(String[] args) {
    String language;
    String country;
    if (args.length != 2) {
    language = new String("en");
    country = new String("GB");
    } else {
    language = new String(args[0]);
    country = new String(args[1]);
    Locale currentLocale;
    ResourceBundle messages;
    currentLocale = new Locale(language, country);
    messages =ResourceBundle.getBundle("MessagesBundle",currentLocale);
    System.out.println(messages.getString("greetings"));
    System.out.println(messages.getString("inquiry"));
    System.out.println(messages.getString("farewell"));
    and I have created several properties file (English, French, German, Arabic) as text files. Maybe I have problems with the properties files.
    I have followed the steps from the Java Tutorial book from Sun.
    Any help would be most welcome.
    Akz

    First save a java file "MessageBundle.java" in your current directory, for the moment. Then save java files "MessagesBundle_en_GB.java", "MessagesBundle_fr_FR", "MessagesBundle_de_DE" or "MessagesBundle_ar_EG" for example. Compile them to class files.
    Then try using your code with various locales.

  • Need help with basic Java programming

    I'm having a little bit of trouble with my code. For the sake of argument, I've removed the code I'm having trouble with, because I know it was inaccurate. I'm trying to create a loop so that this program will keep going through and through until the user enters an invalid variable. I thought the default after the case statements was supposed to make the system exit and output my message. Those two problems, the loop and the default, are what I'm really having problems with. My code is posted below.
    import javax.swing.JOptionPane;
    import java.util.Locale;
    import java.text.NumberFormat;
    public class Retail
    public static void main(String args[])
    String firstNum;
    String secondNum;
    String result;
    int prodNum;      //first number to input
    double quantity; //second number to input
    double total = 0.0;     //total of Prod * Quantity Sold for all items
    // To use American Dollar
    NumberFormat moneyFormat = NumberFormat.getCurrencyInstance( Locale.US );
    // first number entered as string
    firstNum = JOptionPane.showInputDialog( "Enter product number 1-5" );
    // second number entered as string
    secondNum = JOptionPane.showInputDialog( " Enter quantity of items sold" );
    // convert values to type double or int from type string
    prodNum = Integer.parseInt( firstNum );
    quantity = Double.parseDouble( secondNum);
    result="";
    if ( prodNum >=1 && prodNum <=5 ) {
    switch (prodNum)
    case 1: // 1st product
    total = 2.98 * quantity;
    break;
    case 2: // 2nd product
    total = 4.50 * quantity;
    break;
    case 3: // 3rd product
    total = 9.98 * quantity;
    break;
    case 4: //4th product
    total = 4.49 * quantity;
    break;
    case 5:
    total = 6.87 * quantity;
    break;
    default: JOptionPane.showMessageDialog( null, "Wrong product number entered" );
    JOptionPane.showMessageDialog( null, moneyFormat.format(total), "Total Price of Items Purchased", JOptionPane.INFORMATION_MESSAGE );
    System.exit(0);
    ***I know I need to put something in the user input message to state that any value other than 1-5 entered will cause the program to skip to the output, I'll put that in later.***

    When you post code, please use [code] and [/code] tags as described in Formatting Help on the message entry page. It makes it much easier to read and prevents accidental markup from array indices like [i].

  • JAVA�@Program Problems�iMemory Copy�j

    ���L���R�[�h�����s������
    The Result of Execute
    ��
    import java.util.HashMap;
    import java.util.Map;
    public class Test {
         * @param args
        public static void main(String[] args) throws Exception{
            Map map = new HashMap();
            Map in1 = new HashMap();
            in1.put("1", "test1");
            in1.put("2", "test2");
            in1.put("3", "test3");
            map.put("1", in1);
            Map in2 = new HashMap();
            in2 = ((HashMap)map.get("1"));
            map.put("2", in2);
            HashMap out1 = (HashMap)map.get("1");
            out1.put("2","testusotukijin");
            map.put("1", out1);
            System.out.println(map);
    }       ��RESULT�F{2={3=test3, 2=testusotukijin, 1=test1}, 1={3=test3, 2=testusotukijin, 1=test1}}
    I want result of
    ��
    RESULT�F{2={3=test3, 2=test2, 1=test1}, 1={3=test3, 2=testusotukijin, 1=test1}}�@�@�@
    Help me!

    hi
    in that program finally in1,in2,out1 has same
    reference.
    values "test1" "test2" "test3" (strings) will be
    stored in string pool.whenever we do something in any
    one object ,it will reflect in string pool
    so only we are getting that resultThis has nothing to do with the string pool. It has to do with the fact that both "1" and "2" reference the same HashMap.
    (S)He does the following:
    HashMap map = new HashMap();
    HashMap in1 = new HashMap();
    // assignments into in 1
    map.put("1", in1);
    HashMap in2 = new HashMap();
    in2 = map.get("1");  // this throws away the previously (in2) created HashMap
    /* in2 now references the same HashMap as in1.  Changes to the
    * object (HashMap) referenced by either one of these variables
    * affects the object (HashMap) referenced by both variables because
    * they are THE SAME OBJECT.
    */

  • Basic java program wont quit

    I'm in a java class and I'm stuck on this issue. I cant figure out where I went wrong. Any help will be most welcome. I found two examples on how to do this. I used a little from both in order to make mine. The program is suppose to loop back and mine does however when I press Q or q to quit I get a few errors. Below is my code. Thanks
    http://pastebin.com/T74XC07D

    import java.util.*;
    public class xxxxxx
        public static void main(String[] args)
            System.out.println("PHONE NUMBER DISSECTOR");
            displayQuestion();
            getNumber();
         public static void displayQuestion()
              System.out.println();
            System.out.println("Enter a phone number in the form cc-area-local,");
            System.out.println("where cc = country code digits, area = area code digits,");
            System.out.println("and local = local phone digits.");
            System.out.print("Or enter q to quit:");
            getNumber();
         public static void getNumber()
            Scanner scan = new Scanner(System.in);
            String strChoice = scan.next(); //gets the users input for program
            String countryCode, areaCode, phoneNum;  //Phone Number vars cc,area,local
            String[] phoneNumber = strChoice.split("-"); //searches for "-"
             if (!strChoice.equals("q") && !strChoice.equals("Q"));
                countryCode = phoneNumber[0];
                areaCode = phoneNumber[1];
                phoneNum = phoneNumber[2];
                System.out.println("");
                System.out.println("country code = " + countryCode);
                System.out.println("area code = " + areaCode);
                System.out.println("local phone number = " + phoneNum);
                System.out.ptintln("Press any key to contine.");
              else if (!strChoice.equals (""));
                       System.out.println();
                        System.out.println("Enter a phone number in the form cc-area-local,");
                        System.out.println("where cc = country code digits, area = area code digits,");
                        System.out.println("and local = local phone digits.");
                        System.out.print("Or enter q to quit:");
                      getNumber();
            System.exit(1);
    }C:\jdk6\bin>javac -g xxxxxx.java
    xxxxxx.java:35: 'else' without 'if'
    else if (!strChoice.equals (""));
    ^
    Edited by: RadarG on Apr 18, 2010 1:27 AM

  • Basic Java Program

    I just started my second Java course and my program has no compilation errors but doesn't run right.
    First Class: class Star{
         String name;
         Star(){
    //          name = "Star";
         public void setName(String name){
              this.name = name;
         public String getName() {
              return name;
    }With my main class I declare an Star object as an array with different values, but during execution it only displays the last item i added into the array.
    public class TestStar {
    public static void main (String [] args) {
         Star [] array = new Star[10];
         for(int i =0; i<10; i++) {
              array[i] = new Star();
              array.setName("The Sun");
              array[i].setName("Polaris");
              array[i].setName("Sagittarius");
              array[i].setName("Pisces");
              array[i].setName("Pegasus");
              array[i].setName("Orion");
              array[i].setName("Omega");
              array[i].setName("Draco Sigma");
              array[i].setName("Chamaeleon");
              array[i].setName("Aquarius");
              System.out.println(array[i].getName());
    }My professor couldn't even help, (which scares me) but I believe I only have a small error since it still prints on 10 items but only the last item I added to the array.
    Any insight on how to fix this will be much appreciated.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    but during execution it only displays the last item i added into the array.No, you're setting every star in the array with the name "Aquarius". Each time through the loop, you create a Star object, rename that same star with a bunch of different values, finally ending up with "Aquarius". Here is one possible way to fix it: public class TestStar {
        public static void main (String [] args) {
            String[] starNames = {
                "The Sun",
                "Polaris",
                "Sagittarius",
                "Pisces",
                "Pegasus",
                "Orion",
                "Omega",
                "Draco Sigma",
                "Chamaeleon",
                "Aquarius"};
            Star[] array = new Star[starNames.length];
            for(int i = 0; i < starNames.length; i++) {
                array[i] = new Star();
                array.setName(starNames[i]);
    System.out.println(array[i].getName());
    }~                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Should I upgrade to Lion from 10.6.8 to improve stability of Java program i am running?

    I have a Java program problem, it's unstable and losing connection and freezing. Will an upgrade to Lion from 10.6.8 help?
    thanks

    they don't claim it but it is. I have never had a problem with the 2008 macbook, just the desktop. Narrowed it down to this after trying everything else speaking with Scottrade, Oracle and Apple.
    I tried to downgrade but got lost at the utilitoes terminal part. any easier way? Apple wont help me downgrade through my care program and I have no idea.
    Thanks

  • Can I write and run simple java programs in Xcode

    I need to write and run basic java programs on my mac. I would like to run it in Xcode, but I don't know how to set it up? Is there a way?

    Read the following discussion from last month on here:
    Can Xcode 4.5.1 compile/run java?

  • Problems running a java program

    Hello,
    I have absolutely no java experience whatsoever, and I need to fix a program that suddenly stopped running properly after several years without problems. Basically, I have a perl script that calls a java program. Everytime I run this perl script from the web browser, the java program returns an internal error:
    # # HotSpot Virtual Machine Error, Internal Error # Please report this error at # http://www.blackdown.org/cgi-bin/jdk # # Error ID: 5649525455414C53504143450E4350500024 # # Problematic Thread: prio=5 tid=0x804e680 nid=0x6d16 runnable #
    However, when I run the perl script command line, it runs fine. I added the -verbose option to the java call, and I discovered that the program stops running after it opens the .jar files but before it loads them .... these files have full read permissions, so I don't think that's the problem. Any ideas?
    Thanks!

    ...fix a program that suddenly stopped running properly after several years without problems.Which means either the program changed or the environment changed. I would guess the environment. The most likely possibilities: new version of the operating system, new version of perl, new version of java. Also possible: new version installed of any of the previous without removing older versions, new software not associated with the first, new mapped drives and/or changed env vars.

  • Knight tour programming with only basic java

    i had this assignment from school which ask us to create a program to calculate how many posssibilities to complete knight's tour from a position using basic java and not using applet. So far i can only create an incomplete program which can only go a speccific way and is also incomplete. i am trying to understand the jaava applet type of knight tour program but got too confused as i have just started learning this. Please help me with this.
    here's my code:
    public class uk16638_a3{
         public static void main(String[] args){
         int horizontal[] = {2,1,-1,-2,-2,-1,1,2};
         int vertical[] = {-1,-2,-2,-1,1,2,2,1};
         int chessBoard[][]=new int[8][8];
         int move, currentRow = 0, currentCol= 0, move_count = 0, new_vert, new_horz;
    for(int i=0; i<8; i++)
         for(int j =0; j<8; j++)
              chessBoard[i][j] = 0;
    chessBoard[0][0] = 1;
    do{
    for(move=0;move<8;move++){
    new_vert = currentRow + vertical[move];
    new_horz = currentCol + horizontal[move];
    if ( (new_vert>=0) && (new_vert < 8) )
    if( (new_horz>=0) && (new_horz < 8) )
    if( chessBoard[new_horz][new_vert]==0 ) {
    chessBoard[new_horz][new_vert] = 1;
    move_count++;
    currentRow = new_vert;
    currentCol = new_horz;
    }}}while(move<8);}}

    Sorry with the inconvenience cause i am new with this forum so i am causing many problems to all of you. here's the full code i put but i would really like to ask someone to teach me on creating a backtrack and let the knight moves following a different sequence from the one i already set.
    public class uk16638_a3{
    public static void main(String[] args){
    //the movements of a knight horizontally and vertically
    int horizontal[] = {2,1,-1,-2,-2,-1,1,2};
    int vertical[] = {-1,-2,-2,-1,1,2,2,1};
    int chessBoard[][]=new int[8][8];
    int move, currentRow = 0, currentCol= 0, move_count = 0, new_vert, new_horz;
    //setting all elements in the array to 0
    for(int i=0; i<8; i++)
    for(int j =0; j<8; j++)
    chessBoard[i][j] = 0;
    //the knight starts here
    chessBoard[0][0] = 1;
    //using do while loop, i try to move the knight following the sequence i had already set in the array above. But because its moving at the same direction all the time, it gets stuck.
    do{
    for(move=0;move<8;move++){
    //setting the new coordinates for it to move to
    new_vert = currentRow + vertical[move];
    new_horz = currentCol + horizontal[move];
    if ( (new_vert>=0) && (new_vert < 8) )
    if( (new_horz>=0) && (new_horz < 8) )
    //new position check if its already occupied or not, if occupied it will move on to the next part of the move sequence i set
    if( chessBoard[new_horz][new_vert]==0 ) {
    chessBoard[new_horz][new_vert] = 1;
    move_count++;
    //current coordinate of the new knight position
    currentRow = new_vert;
    currentCol = new_horz;
    }}}while(move<8);}}
    Edited by: Mikki88 on Mar 2, 2009 1:53 AM

Maybe you are looking for