General Java Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Steel546
    New Member
    • Mar 2009
    • 25

    General Java Help

    Heyyy, I'm back. Getting the hang of this java thing. Anyways, I have a few questions, I'll leave my hardest for last.

    So, I believe I'm having an overloading method issue here.

    Code:
    public static boolean closeAccount (double acctBalance, int checksLeft) {
        // returns true if acctBalance is less than zero or checksLeft is less than or equal to zero.
    
        if (acctBalance < 0 || checksLeft <= 0){
            return true;}
            else{
                return false;
            }
        }
    
    }
    *public static boolean closeAccount (int acctBalance, int checksLeft) {
        // returns true if acctBalance is less than zero or checksLeft is less than or equal to zero.
    
        if (acctBalance < 0 || checksLeft <= 0 ){
     *       return true;}
        else{
     *       return false;
        }
    
    }
    I'm getting a "class, interface, or enum expected" error on the lines with asterisks. I'm creating overloading methods, but I believe that as long as the arguments are different, then I'm okay. I have a double/int in the first (fine) and a int/int in the second. Little confused.

    And lastly... how do you launch a browser? I've been searching, and there seems to be no basic answer to this.

    Code:
    import com.apple.mrj.MRJFileUtils;
    import java.io.*;
    
    public class Main {
    
      String url = "http://www.google.com/";
        
        public static void main(String[] args) {new
    Open();
        }
    Open() {
    try {
    MRJFileUtils.openURL(url);
    } catch (IOException ex) {}
      }
    
    
        }
    Man... that's ugly. Anyways, but that's for a Mac. Instead, I'm trying to make a method to call instead of putting it under the main argument. Anywho, I'll keep working on that one. As always, any suggestion is greatly appreciated.
  • Steel546
    New Member
    • Mar 2009
    • 25

    #2
    Wait, found something.

    Code:
    URLDisplayer.getDefault().showURL(URL url);

    Comment

    • Steel546
      New Member
      • Mar 2009
      • 25

      #3
      Nevermind, fixed it.

      Code:
      import java.io.*;
      
      public class KyleTaylorToolBox {
      
          public static void printEveryXtoY (int x, int y) {
         // this method prints every xth integer from 0 to y that is less than or equal to y.
         // example output when passed (4,14): 0  4  8  12
         // example output when passed (2, 14): 0  2  4  6  8  10  12  14
      int count = 0;
                while (count <= y) {
                     System.out.println( + count);
                     count = count + x;
                }
      
      
          }
      
       public static void launchBrowser ( ) throws IOException {
          // this method starts a web browser like Internet Explorer. Search the Internet for help.
       String url="http://www.cse.unt.edu";
       Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
       
      
       }
      
      public static boolean isOdd (int x) {
          // this method returns true if x is odd and false if x is even.
          if (x % 2 == 0){
              return false;}
              else{
                  return true;
              }
          }
      
      //Create two overloaded methods called closeAccount:
      
      public static boolean closeAccount (double acctBalance, int checksLeft) {
          // returns true if acctBalance is less than zero or checksLeft is less than or equal to zero.
      
          if (acctBalance < 0 || checksLeft <= 0){
              return true;}
              else{
                  return false;
              }
          }
      
      public static boolean closeAccount (int acctBalance, int checksLeft) {
          // returns true if acctBalance is less than zero or checksLeft is less than or equal to zero.
      
          if (acctBalance < 0 || checksLeft <= 0 ){
              return true;}
          else{
              return false;
              }
      
          }
      }

      Okay. Now I'm having problems calling the methods in a different class. Says "cannot find symbol".

      Comment

      • sukatoa
        Contributor
        • Nov 2007
        • 539

        #4
        You forgot to import KyleTaylorToolB ox class in other class

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by Steel546
          Okay. Now I'm having problems calling the methods in a different class. Says "cannot find symbol".
          I'm sure 'it' said a lot more, e.g. the symbol it couldn't find and where it couldn't find it (including the line number). That should give you some clues.

          kind regards,

          Jos

          Comment

          Working...