Need help with project (calling methods) please!!

Hi there i have a project for uni requiring me to create a java program that creates a random No. and lets the user have three guesses to find the No. When the users guesses correct he gets a message telling him hes won and if he doesnt get it correct he gets a message telling him the correct No then terminates.
The code has to call an outside method called[b] Public Static Boolean CheckGuess
I have tried to create this and got it to compile with no errors (eventually) but i keep getting a message saying i have whenever i type any number in. I think the problem is the way i am calling the method i havnt got much experience this is all pretty new to me any help would be really appreciated. Thanks.
import javax.swing.*;
import java.util.*;
public class Coursework1{
     public static void main(String args[]){
          int randomnumber,usersguessint,checkguess,guessvalid,attempts;
          String usersguess,output;
          boolean match;
          //create random number generator
          Random numGenerator = new Random();
          //generate a random number between 1 & 10 inclusive
          randomnumber = Math.abs(numGenerator.nextInt(9))+1;
          //initialize variable attempts
          for ( attempts = 0; attempts < 3; attempts++ ) {
               //ask user for his first guess
               usersguess=JOptionPane.showInputDialog("Please enter your guess between 1 & 10");
               //convert users guess to integer
               usersguessint = Integer.parseInt(usersguess);
                    //validate input
                    while (usersguessint<1||usersguessint>10){
                    usersguess=JOptionPane.showInputDialog("You entered an incorrect number \nPlease enter a numberbetween 1 & 10");
                     //convert users guess to integer
                    usersguessint = Integer.parseInt(usersguess);
                    } //end while loop
                         //call boolean method
                         if (match=true){
                         //display text area in JoptionPane
                         output="You won";
                         JOptionPane.showMessageDialog(null,output,"You Won",JOptionPane.INFORMATION_MESSAGE);
                         break;}
                         else{
                         output="Try again";     
                         JOptionPane.showInputDialog("Try again");
                              }     //end if
               } //end for
          }//end main
                         //user defined method
                         public static boolean checkGuess(int usersguessint,int randomnumber){
                         boolean match = false;
                         if (usersguessint == randomnumber){
                         match = true;
                         return match;
                         }//end method
     }//endclass

Thank you very much that worked a treat the program is working better now. I have just realised that my for loopcontaining my counter may be in the wrong place as the program is running though both messages 3 times e.g
"Please enter your guess between 1 & 10"
"Try again"
"Please enter your guess between 1 & 10"
"Try again"
"Please enter your guess between 1 & 10"
"Try again"
"Please enter your guess between 1 & 10"
"Try again"
I want my program to run like
"Please enter your guess between 1 & 10"
"Try again"
"Try again"
"Try again"
Do u think if i placed my for stament (counter) in between the two messages it would eliminate this problem.

Similar Messages

  • NEED HELP WITH USING STATIC METHOD - PLEASE RESPOND ASAP!

    I am trying to set a value on a class using a static method. I have defined a servlet attribute (let's call it myAttribute) on my webserver. I have a serlvet (let's call it myServlet) that has an init() method. I have modified this init() method to retrieve the attribute value (myAttribute). I need to make this attribute value accessible in another class (let's call it myOtherClass), so my question revolves around not knowing how to set this attribute value on my other class using a static method (let's call it setMyStuff()). I want to be able to make a call to the static method setMyStuff() with the value of my servlet attribute. I dont know enough about static member variables and methods. I need to know what to do in my init() method. I need to know what else I need to do in myServlet and also what all I need in the other class as well. I feel like a lot of my problems revolve around not knowing the proper syntax as well.
    Please reply soon!!! Thanks in advance.

    class a
    private static String aa = "";
    public static setVar (String var)
    aa = var;
    class b
    public void init()
    a.aa = "try";
    public static void main(String b[])
    b myB = new b ();
    b.init();
    hope this help;
    bye _drag                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Need Help with a getText method

    Gday all,
    I need help with a getText method, i need to extract text from a JTextField. Although this text then needs to converted to a double so that i can multiply a number that i have already specified. As you may of guessed that the text i need to extract already will be in a double format.e.g 0.1 or 0.0000004 etc
    Thanks for your help
    ps heres what i have already done its not very good though
    ToBeConverted.getText();
    ( need help here)
    double amount = (and here)
    total = (amount*.621371192);
    Converted.setText("= " + total);

    Double.parseDouble( textField.getText() );

  • Need help with threads?.. please check my approach!!

    Hello frnds,
    I am trying to write a program.. who monitors my external tool.. please check my way of doing it.. as whenever i write programs having thread.. i end up goosy.. :(
    first let me tell.. what I want from program.. I have to start an external tool.. on separate thread.. (as it takes some time).. then it takes some arguments(3 arguments).. from file.. so i read the file.. and have to run tool.. continously.. until there are arguments left.. in file.. or.. user has stopped it by pressing STOP button..
    I have to put a marker in file too.. so that.. if program started again.. file is read from marker postion.. !!
    Hope I make clear.. what am trying to do!!
    My approach is like..
    1. Have two buttons.. START and STOP on Frame..
    START--> pressed
    2. check marker("$" sign.. placed in beginning of file during start).. on file..
         read File from marker.. got 3 arg.. pass it to tool.. and run it.. (on separate thread).. put marker.. (for next reading)
         Step 2.. continously..
    3. STOP--> pressed
         until last thread.. stops.. keep running the tool.. and when last thread stops.. stop reading any more arguments..
    Question is:
    1. Should i read file again and again.. ?.. or read it once after "$" sign.. store data in array.. and once stopped pressed.. read file again.. and put marker ("$" sign) at last read line..
    2. how should i know when my thread has stopped.. so I start tool again??.. am totally confused.. !!
    please modify my approach.. if u find anything odd..
    Thanks a lot in advance
    gervini

    Hello,
    I have no experience with threads or with having more than run "program" in a single java file. All my java files have the same structure. This master.java looks something like this:
    ---master.java---------------------------------------------------
    import java.sql.*;
    import...
    public class Master {
    public static void main(String args []) throws SQLException, IOException {
    //create connection pool here
    while (true) { // start loop here (each loop takes about five minutes)
    // set values of variables
    // select a slave process to run (from a list of slave programs)
    execute selected slave program
    // check for loop exit value
    } // end while loop
    System.out.println("Program Complete");
    } catch (Exception e) {
    System.out.println("Error: " + e);
    } finally {
    if (rSet1 != null)
    try { rSet1.close(); } catch( SQLException ignore ) { /* ignored */ }
    connection.close();
    -------end master.java--------------------------------------------------------
    This master.java program will run continuously for days or weeks, each time through the loop starting another slave process which runs for five minutes to up to an hour, which means there may be ten to twenty of these slave processes running simultaneously.
    I believe threads is the best way to do this, but I don't know where to locate these slave programs: either inside the master.java program or separate slave.java files? I will need help with either method.
    Your help is greatly appreciated. Thank you.
    Logan

  • Need help with flash player installation please !!!!

    Hello,
    I need help with my flash player installation because every time I access a movie this is the message I receive. 
    This content on Xfinity TV is not available for viewing with Chrome's "Incognito" mode. To play this video using Chrome, please view this page without "Incognito" mode.
    Still having problems? Try resetting your Flash player license.

    Incognito mode is a Google Chrome setting when you open a new window (Cmd+Shift+N on a Mac Ctrl+Shift+N on Windows) It opens a "private" window with no cookies and no tracking. The problem with it is that when you disable cookies, your license files are not sent to the site (whetehr it's YouTube or xFinity or any other that uses license files for paid content)  and it treats you as if you're a first time visitor. Paid videos won't play wihtout the cookies sending the license file info.
    This isn't a Flash Player setting. It's in Chrome. I did some research and according to Google, "Incignito" mode is off by default, and can ONLY be activate by the keyboard shortcut. There IS a way to disable it from the registry http://dev.chromium.org/administrators/policy-list-3#IncognitoModeAvailability

  • I need help with printing labels.  please

    I need help with printing labels.  thanks in advance

    Welcome to Apple Support Communities.
    In Address Book, first select a name or group of names to print.
    Then File, Print, select Style, Mailing Labels, then Layout to select a specific target label (such as an Avery number), or define your own...

  • Need help with project

    Hi all I'm working on a project and need help.
    I want the "New" button to clear all the fields.
    Any help?
    =======================================================
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Message extends JFrame implements ActionListener {
         public Message() {
         super("Write a Message - by Kieran Hannigan");
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         setSize(370,270);
         FlowLayout flo = new FlowLayout(FlowLayout.RIGHT);
         setLayout(flo);
         //Make the bar
         JMenuBar bar = new JMenuBar();
         //Make "File" on Menu
         JMenu File = new JMenu("File");
         JMenuItem f1 = new JMenuItem("New");
         JMenuItem f2 = new JMenuItem("Open");
         JMenuItem f3 = new JMenuItem("Save");
         JMenuItem f4 = new JMenuItem("Save As");
         JMenuItem f5 = new JMenuItem("Exit");
         File.add(f1);
         File.add(f2);
         File.add(f3);
         File.add(f4);
         File.add(f5);
         bar.add(File);
         //Make "Edit" on menu
         JMenu Edit = new JMenu("Edit");
         JMenuItem e1 = new JMenuItem("Cut");
         JMenuItem e2 = new JMenuItem("Paste");
         JMenuItem e3 = new JMenuItem("Copy");
         JMenuItem e4 = new JMenuItem("Repeat");
         JMenuItem e5 = new JMenuItem("Undo");
         Edit.add(e5);
         Edit.add(e4);
         Edit.add(e1);
         Edit.add(e3);
         Edit.add(e2);
         bar.add(Edit);
         //Make "View" on menu
         JMenu View = new JMenu("View");
         JMenuItem v1 = new JMenuItem("Bold");
         JMenuItem v2 = new JMenuItem("Italic");
         JMenuItem v3 = new JMenuItem("Normal");
         JMenuItem v4 = new JMenuItem("Bold-Italic");
         View.add(v1);
         View.add(v2);
         View.add(v3);
         View.addSeparator();
         View.add(v4);
         bar.add(View);
         //Make "Help" on menu
         JMenu Help = new JMenu("Help");
         JMenuItem h1 = new JMenuItem("Help Online");
         JMenuItem h2 = new JMenuItem("E-mail Programmer");
         Help.add(h1);
         Help.add(h2);
         bar.add(Help);
         setJMenuBar(bar);
         //Make Contents of window.
         //Make "Subject" text field
         JPanel row2 = new JPanel();
         JLabel sublabel = new JLabel("Subject:");
         row2.add(sublabel);
         JTextField text2 = new JTextField("RE:",24);
         row2.add(text2);
         //Make "To" text field
         JPanel row1 = new JPanel();
         JLabel tolabel = new JLabel("To:");
         row1.add(tolabel);
         JTextField text1 = new JTextField(24);
         row1.add(text1);
         //Make "Message" text area
         JPanel row3 = new JPanel();
         JLabel Meslabel = new JLabel("Message:");
         row3.add(Meslabel);
         JTextArea text3 = new JTextArea(6,22);
         messagearea.setLineWrap(true);
         messagearea.setWrapStyleWord(true);
         JScrollPane scroll = new JScrollPane(text3,
                                  JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                                  JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
         row3.add(scroll);
         add(row1);
         add(row2);
         add(row3);
         setVisible(true);
         public static void main(String[] arguments)  {
         Message Message = new Message();
    }

    Ok, given that I may have not been the kindest to you on the other thread (and I'm still annoyed that you went and cross-posted this), and that you did actually use code tags, I'm going to post some code here:
    Please take the following advice onboard though.
    1. When you are naming your artifacts, please use the java coding standard as your guide. So if you are naming a class you use a capital letter first, and use camel case thereafter. All method names begin with a lower case letter, and all variable names begin with a lower case letter (and again camel case after that)
    2. Please use self explanitory names (for everything), so no more row1, row2, or text1, text2, etc.
    3. The example I am giving below makes use of a single class to handle all actions, this is not really the best way to do this, and a better way would be to have a class to handle each action (that would remove the massive if() else if() in the action handler class.
    4. When you are using class variables they should be private (no exceptions, ever!), if you need to access them from other classes use accessors (eclipse and other IDE tools can generate these methods for you in seconds)
    5. Notice the naming convention for my constants (final statics), they are all upper case (again from the java coding standards document, which you are going to look for with google right?)
    6. I have hived some of the creation work to helper methods (the getSubjectTextField() etc), although it isn't advisable to be calling other methods from the constructor, since this is a GUI, and you want it to appear as soon as you create the class, we won't worry about this, but perhaps as an execrise you could work out a better way to do this?
    7. Personally, I don't like classes that implement listeners, unless they are specifically designed to do that job. So a Frame that is set up as an action listener is fine, provided the actions it listens for are associated with the frame, not its contents. If the actions are related to its contents, then a dedicated class is better.
    8. Another personal opinion, but I feel it makes code clearer, but others may disagree. If you are creating a variable solely to hold the result of a calculation, to be passed to a method in the very next line, then don't create the variable, just pass the method as the argument to the method (feel free to ignore this advice if the method call is extremely long, and a local would make it easier to read)
    Anyway, here is the code. I have removed most of the menu items, and leave this as an exercise for you. Also I have only created 2 methods (new and exit), I'll again leave it as an exercise for you to complete this.
    package jdc;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import javax.swing.AbstractAction;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.ScrollPaneConstants;
    public class Message extends JFrame {
        /** Constant for the new action command. */
        private static final String NEW_COMMAND = "New";
        /** Constant for the exit action command. */
        private static final String EXIT_COMMAND = "Exit";
        /** Subject text field. */
        private JTextField subjectTextField;
        /** Recipient text field. */
        private JTextField toTextField;
        /** Message text area. */
        private JTextArea messageTextArea;
        public Message() {
            super("Write a Message - by Kieran Hannigan");
            setSize(370, 270);
            FlowLayout flo = new FlowLayout(FlowLayout.RIGHT);
            setLayout(flo);
            setJMenuBar(createMenuBar());
            // Add "Subject" text field
            JPanel subjectRow = new JPanel();
            subjectRow.add(new JLabel("Subject:"));
            subjectRow.add(getSubjectTextField());
            // Add "To" text field
            JPanel toRow = new JPanel();
            toRow.add(new JLabel("To:"));
            toRow.add(getToTextField());
            // Make "Message" text area
            JPanel messageRow = new JPanel();
            JScrollPane scroll = new JScrollPane(getMessageTextArea(), ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            messageRow.add(scroll);
            add(toRow);
            add(subjectRow);
            add(messageRow);
            setVisible(true);
         * Clear all the fields.
        public void createNewMessage() {
            getSubjectTextField().setText("");
            getToTextField().setText("");
            getMessageTextArea().setText("");
         * Exit the application.
        public void exitApplication() {
            if (JOptionPane.showConfirmDialog(this, "Are you sure you would like to exit now?", "Exit",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                System.exit(0);
         * @return The subject text field, (creates a new one if it doesn't already exist)
        private JTextField getSubjectTextField() {
            if (this.subjectTextField == null) {
                this.subjectTextField = new JTextField("RE:", 24);
            return this.subjectTextField;
         * @return The to text field, (creates a new one if it doesn't already exist)
        private JTextField getToTextField() {
            if (this.toTextField == null) {
                this.toTextField = new JTextField(24);
            return this.toTextField;
         * @return The message text area, (creates a new one if it doesn't already exist
        private JTextArea getMessageTextArea() {
            if (this.messageTextArea == null) {
                this.messageTextArea = new JTextArea(6, 22);
                this.messageTextArea.setLineWrap(true);
                this.messageTextArea.setWrapStyleWord(true);
            return this.messageTextArea;
         * Helper method to create the menu bar.
         * @return Menu bar with all menus and menu items added
        private JMenuBar createMenuBar() {
            JMenuBar bar = new JMenuBar();
            JMenu fileMenu = new JMenu("File");
            fileMenu.add(new JMenuItem(new MenuItemAction(this, NEW_COMMAND)));
            fileMenu.add(new JMenuItem(new MenuItemAction(this, EXIT_COMMAND)));
            bar.add(fileMenu);
            // TODO add all other menu's and menu items here....
            return bar;
         * Private static class to handle all menu item actions.
        private static class MenuItemAction extends AbstractAction {
            /** Instance of the message class. */
            private Message message;
             * @param actionName
            public MenuItemAction(Message messageFrame, String actionName) {
                super(actionName);
                this.message = messageFrame;
             * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
            public void actionPerformed(ActionEvent e) {
                if (e.getActionCommand().equals(NEW_COMMAND)) {
                    this.message.createNewMessage();
                } else if (e.getActionCommand().equals(EXIT_COMMAND)) {
                    this.message.exitApplication();
                // TODO Add the other event handlers here
        public static void main(String[] arguments) {
            Message messageFrame = new Message();
            messageFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }If you have any questions, please let me know, as there are a number of new areas introduced that you may not have come across before.

  • Need help with Project Pro

    Hi,
    I recently purchased few licenses for Project pro from office 365 (online version). When I log in to office 365 and go to my apps I can not see Project Pro app there? Where it might be?
    Also when I create a project with desktop app, where is the option to sync that project to server? The license already included with
    Project Online and Project server Sync.
    Any Help solving my issues will be greatly appreciated.
    Thanks in advance..

    Hi,
    Please see this
    article for starting a project with Project Pro for Project Online.
    Don't forget to use in Project Pro the email adress used for creating your O365 account.
    Hope this helps,
    Guillaume Rouyre, MBA, MVP, P-Seller |

  • I need help with the https class please.

    Hello, i need add an authentication field in my GET request using HTTPS to authenticate users. I put the authentication field using the setRequestProperty method, but it doesn't appear when i print all properties using the getRequestProperties method. I wrote the following code:
    try{
    URL url = new URL ("https://my_url..");
    URLConnection conexion;
    conexion = url.openConnection();
    conexion.setRequestProperty("Authorization",my_urlEncoder_string);
    conexion.setRequestProperty("Host",my_loginServer);
    HttpsURLConnection httpsConexion = (HttpsURLConnection) conexion;
    httpsConexion.setRequestMethod("GET");
    System.out.println("All properties\r\n: " + httpsConexion.getRequestProperties());
    }catch ....
    when i run the program it show the following text:
    All properties: {Host=[my_loginServer]}
    Only the Host field is added to my HttpsURLConnection. The authentication field doesnt appear in standar output. How can i add to my HttpsURLConnection an Authentication field?
    thanks

    I have moved this to the main Dreamweaver forum, as the other forum is intended to deal with the Getting Started video tutorial.
    The best way to get help with layout problems is to upload the files to a website and post the URL in the forum. Someone can then look at the code, and identify the problem. Judging from your description, it sounds as though the Document window is narrow, which would result in the final menu tab dropping down to the next row. Try turning on Live view or previewing the page in a browser. Design view gives only an approximate idea of the final layout. Live view renders the page as it should look in a browser.

  • Need Help with Migration...Please

    Hello,
    I need help!  I just bought a new MacBook Pro.  In house, I have a two year old iMac running Mavericks (all updated) and an iPhone and iPad (both running the most current OS).  I also have the iMac connected to a Time Capsule.  Here are my questions:
    1.  As I am not replacing the iMac, but rather adding a MacBook Pro to the mix, should I migrate the software, settings, files, etc. from the iMac to the MacBook?  Is there an issue running computers which are clones in the same environment?  Is it a bad idea to migrate?
    2.  Assuming # 1 is okay to migrate, what is the best way?  Is it best directly from the iMac or from the Time Capsule?  I do have a Thunderbolt to Ethernet adapter on hand. 
    3.  Is there a link that would help me navigate the migration?
    4.  How long should the migration in #2 take?
    5.  Will I need to change any settings on the iMac, iPhone, or iPad afterwards?
    6.  Will my contacts and calendar sync with iCloud automatically, or do I have to change a setting on the MacBook to make that happen?
    7.  Also, as I'm leaving town tomorrow and want to take the MacBook Pro with me and I'm unsure I've the time to Migrate and tweak, can I jus turn on the MacBook (still not turned on), use it as it is, and then migrate when I get back home?
    Any help would greatly be appreciated.  Thank you!

    Hello,
    I need help!  I just bought a new MacBook Pro.  In house, I have a two year old iMac running Mavericks (all updated) and an iPhone and iPad (both running the most current OS).  I also have the iMac connected to a Time Capsule.  Here are my questions:
    1.  As I am not replacing the iMac, but rather adding a MacBook Pro to the mix, should I migrate the software, settings, files, etc. from the iMac to the MacBook?  Is there an issue running computers which are clones in the same environment?  Is it a bad idea to migrate?
    2.  Assuming # 1 is okay to migrate, what is the best way?  Is it best directly from the iMac or from the Time Capsule?  I do have a Thunderbolt to Ethernet adapter on hand. 
    3.  Is there a link that would help me navigate the migration?
    4.  How long should the migration in #2 take?
    5.  Will I need to change any settings on the iMac, iPhone, or iPad afterwards?
    6.  Will my contacts and calendar sync with iCloud automatically, or do I have to change a setting on the MacBook to make that happen?
    7.  Also, as I'm leaving town tomorrow and want to take the MacBook Pro with me and I'm unsure I've the time to Migrate and tweak, can I jus turn on the MacBook (still not turned on), use it as it is, and then migrate when I get back home?
    Any help would greatly be appreciated.  Thank you!

  • Need Help with new site glitches PLEASE!!!

    I need help trouble shooting a website. The site is
    www.farrowandwatkins.com. Nav buttons on Mac they display correctly
    which is aligned at top and bottom of content to left on Home page.
    However, when viewed on PC, the buttons spread to fill the
    distance of the "Patients" Page. All the pages spread to this
    length also, but are not suppose to.
    Nav buttons have padding of 10 on bottom, except last one.
    Please help if you can

    First guess would be that there doesn't seem to be a fixed
    height or width on the cell for the 'patients' button.

  • I need help with this recursion method

         public boolean findTheExit(int row, int col) {
              char[][] array = this.getArray();
              boolean escaped = false;
              System.out.println("row" + " " + row + " " + "col" + " " + col);
              System.out.println(array[row][col]);
              System.out.println("escaped" + " " + escaped);
              if (possible(row, col)){
                   System.out.println("possible:" + " " + possible(row,col));
                   array[row][col] = '.';
              if (checkBorder(row, col)){
                   System.out.println("check border:" + " " + checkBorder(row,col));
                   escaped = true;
              else {
                    System.out.println();
                    escaped = findTheExit(row+1, col);
                    if (escaped == false)
                    escaped = findTheExit(row, col+1);
                    else if (escaped == false)
                    escaped = findTheExit(row-1, col);
                    else if (escaped == false)
                    escaped = findTheExit(row, col-1);
              if (escaped == true)
                   array[row][col] = 'O';
              return escaped;
         }I am having difficulties with this recursion method. What I wanted here is that when :
    if escaped = findTheExit(row+1, col);  I am having trouble with the following statement:
    A base case has been reached, escaped(false) is returned to RP1. The algorithm backtracks to the call where row = 2 and col = 1 and assigns false to escaped.
    How do I fix this code?
    I know what's wrong with my code now, even though that if
    if (possible(row, col))
    [/code[
    returns false then it will go to if (escaped == false)
                   escaped = findTheExit(row, col+1);
    how do I do this?

    Okay I think I got the problem here because I already consult with the instructor, he said that by my code now I am not updating my current array if I change one of the values in a specific row and column into '.' . How do I change this so that I can get an update array. He said to me to erase char[][] array = getArray and replace it with the array instance variable in my class. But I don't have an array instance variable in my class. Below is my full code:
    public class ObstacleCourse implements ObstacleCourseInterface {
         private String file = "";
         public ObstacleCourse(String filename) {
              file = filename;
         public boolean findTheExit(int row, int col) {
              boolean escaped = false;
              //System.out.println("row" + " " + row + " " + "col" + " " + col);
              //System.out.println(array[row][col]);
              //System.out.println("escaped" + " " + escaped);
              if (possible(row, col)){
                   //System.out.println("possible:" + " " + possible(row,col) + "\n");
                   array[row][col] = '.';
                   if (checkBorder(row, col)){
                   escaped = true;
                   else {
                    escaped = findTheExit(row+1, col);
                    if (escaped == false)
                    escaped = findTheExit(row, col+1);
                    else if (escaped == false)
                    escaped = findTheExit(row-1, col);
                    else if (escaped == false)
                    escaped = findTheExit(row, col-1);
              if (escaped == true)
                   array[row][col] = 'O';
              return escaped;
         public char[][] getArray() {
              char[][] result = null;
              try {
                   Scanner s = new Scanner(new File(file));
                   int row = 0;
                   int col = 0;
                   row = s.nextInt();
                   col = s.nextInt();
                   String x = "";
                   result = new char[row][col];
                   s.nextLine();
                   for (int i = 0; i < result.length; i++) {
                        x = s.nextLine();
                        for (int j = 0; j < result.length; j++) {
                             result[i][j] = x.charAt(j);
              } catch (Exception e) {
              return result;
         public int getStartColumn() {
              char[][] result = this.getArray();
              int columns = -1;
              for (int i = 0; i < result.length; i++) {
                   for (int j = 0; j < result[i].length; j++) {
                        if (result[i][j] == 'S')
                             columns = j;
              return columns;
         public int getStartRow() {
              char[][] result = this.getArray();
              int row = -1;
              for (int i = 0; i < result.length; i++) {
                   for (int j = 0; j < result[i].length; j++) {
                        if (result[i][j] == 'S')
                             row = i;
              return row;
         public boolean possible(int row, int col) {
              boolean result = false;
              char[][] array = this.getArray();
              if (array[row][col] != '+' && array[row][col] != '.')
                   result = true;
              return result;
         public String toString() {
              String result = "";
              try {
                   Scanner s = new Scanner(new File(file));
                   s.nextLine();
                   while (s.hasNextLine())
                        result += s.nextLine() + "\n";
              } catch (Exception e) {
              return result;
         public boolean checkBorder(int row, int col) {
              char[][] array = this.getArray();
              boolean result = false;
              int checkRow = 0;
              int checkColumns = 0;
              try {
                   Scanner s = new Scanner(new File(file));
                   checkRow = s.nextInt();
                   checkColumns = s.nextInt();
              } catch (Exception e) {
              if ((row + 1 == checkRow || col + 1 == checkColumns) && array[row][col] != '+')
                   result = true;
              return result;
    I thought that my problem would be not to read the file using the try and catch everytime in the method. How do I do this?? Do I have to create an array instance variable in my class?

  • I need help with website can you please

    Need help
    Message was edited by: Liam Dilley - Phone number in here is a bad idea

    Hi,
    I removed your phone number as you will just get cold called
    BC support does not call you for help and people here can help you here. Just saying "need help" is not much use though, we need to know what kind of help you need.

  • I need help with my wifi sync, please?

    I am trying to sync a single band from my laptop to my iPhone. This is my new laptop and I have no transfered all my music from my old computer onto here, so I can not sync through the cable or else I will have to remove all my exsisting information on my phone, I do not have all my music on my laptop yet. All I want is to simply transfer a few songs from my iTunes to my phone wirelessly and I can't. I enabled the button when I plug in my phone that tells me I can sync wirelessly but when I disconnect it refuses to work. Please I need help.

    Dear friend, by the moment Blackberry playbook is just for USA/Canada users, in a very short time RIM will announce the release of the product for the rest of countries.
    Be patient when you can use it at 100%, you will be amazed!

  • I just bought my MacBook Pro 13" and I tried to install an anti virus but then it went into a grey folder with a question mark I need help with restoring the iOS please

    I need help taking out the grey folder with the question mark and I've try everything except the CD thing because my MacBook didn't come with one so I really need help please

    What anti-virus software did you install? Although there's a lot of bad anti-virus software out there, no anti-virus software should cause such a problem. A gray screen with a flashing question mark on a folder means that no bootable system could be found, which means that the system was badly damaged or corrupt. Even installing bad software would not normally cause that, so either there was something badly wrong with the system already or the anti-virus software you tried to install was really, really bad!
    As mende1 says, you need to reinstall the system at this point. After your system is back up and running, read my Mac Malware Guide. If, after reading that, you want anti-virus software, use one of the programms recommended in that guide.

Maybe you are looking for

  • Photoshop CC crashes when I try to open a file. CS6 is working fine?

    When I go to open a file (any file, jpeg, psd, tif) Photoshop CC launches and begins the process of starting up. The file image appears for a brief moment then the program closes (aka crashes) and that's it. I then try CS6 and it opens the file just

  • Running a Java application from web browser

    Hi, I'm not sure if this is the right place to put this, and it probably isn't, but I don't really know what else to do at the moment. I have a problem. I've written all these nice and pretty Java applications that do all this complicated junk that m

  • VSAN properties best practice

    Hi all, I would like to know the best way to configure the next properties (bolded and underlined): show zone status:                               VSAN: 1 default-zone: deny distribute: active only Interop: default                                  

  • Intel 320 160gb SSD any issues with mac pro 2008?

    Hi there. I have a mac pro 2008.  and Install Intel 320 160gb ssd. and boot... It's shows black screen... is any one has that issue? I tested that SSD with my old quad mac pro 2007, it works fine... Please help me....

  • Need help updating CC Media Encoder

    I have tried installing the Oct 31 update and get error messages "Download failed, try again later" or "Download appears corrupted". I had similar problems with PP CC update but that finally worked. Using Windows 7 Professional 64bit. Thanks!