Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Method Help

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Method Help

    I am trying to create methods for each of my assigned task. The first there work without any problems since they don't pull Strings or ints. When I try to pull positiveTriangle or negativeTriangle it gives me an error in NetBean. Any help would be great.

    Thanks


     
     
    import java.util.Scanner;
    public class main {
     
     
        public static void main(String[] args) {
     
        purpose();
     
        gettingPrintCharacter();
     
        gettingVarifyingInputs();
     
     
        }
     
        public static void purpose() {.....
            }
     
        public static void gettingPrintCharacter(){.....
        }
     
        public static void gettingVarifyingInputs(){....
        }
     
        public static void positiveTriangle(String aChar, int amount){....
        } 
     
        public static void negativeTriangle(String aChar, int amount, int opposite) {...
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Method Help

    Welcome to the forum! Please read this topic to learn how to post code correctly and other useful info for new members.

    Post the error.

    Also, use common terminology. I don't know what you mean by "pull." In Java, methods can either return a result of a specific type, or they can return nothing and be 'void' methods.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Method Help

    what you mean by pull? one error could be the parameters you have in positiveTriangle and negativeTriange methods, in main when you call them you have to pass arguments.. you can create Striing and int variable and pass them to the methods..

  4. #4
    Junior Member
    Join Date
    Mar 2014
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Method Help

    I am trying to create methods for each of my assigned task. The first there work without any problems since they don't pull Strings or ints. When I try to pull positiveTriangle or negativeTriangle it gives me an error in NetBean. Any help would be great.

    Thanks

    positiveTriangle();

    negativeTriangle();
    dont work
     
    import java.util.Scanner;
    public class main {
     
     
        public static void main(String[] args) {
     
        purpose();
     
        gettingPrintCharacter();
     
        gettingVarifyingInputs();
     
        positiveTriangle();
     
        negativeTriangle();
     
     
        }
     
        public static void purpose() {  
                System.out.print("This program will print a right triangle. \nThe "
                   + "character that is entered at the prompt will be used to print"
                   + " a right triangle.  \nThe value that is entered at the prompt "
                   + "will be the right triangle's height and width.  \nIf the value "
                   + "is negative only an outline of the triangle will be printed "
                   + "else a filled in triangle will be printed.\n\n");
           //displays purpose of program 
            }
     
        public static void gettingPrintCharacter(){
        Scanner keyboard = new Scanner (System.in);
        System.out.print("Enter the character to be used: ");
            String triangle = keyboard.next();
            //converts character(s) entered into string
           char aChar = triangle.charAt(0);
            //slects only the first character of the string
           //the string above is to "idiot" or accident prof if they enter 
           //more than one character
        }
     
        public static void gettingVarifyingInputs(){
           Scanner keyboard = new Scanner (System.in);
           int amount;
           boolean valid= false;
           while (!valid)//first loop unitl uers inputs correct value
            {// starts the main loop
         System.out.print("Enter a non-zero integer length (+/-1 through +/-16): ");
         amount = keyboard.nextInt();// length and width of triangle
         while(amount == 0 || amount >16 || amount <-16)// invalid input tester
        {// starts second loop for user to input correct value
         System.out.print("Input value outside of range");
         System.out.print("\nEnter a non-zero integer length (+/-1 through +/-16): ");
         amount = keyboard.nextInt();// length and width of triangle
        }// ends loop
        valid = true;// end user input loop
        }
        }
     
        public static void positiveTriangle(String aChar, int amount){
     
         int i = 1;
            int j = i;
    do { //first do loop
        do{//second do loop
            System.out.print(aChar);
            j++;
        }while (j<=i);//second while loop end
        System.out.println();
              i++;
         j=1;
    }while(i<=amount);//first while loop end
        }//ends last else 
     
        public static void negativeTriangle(String aChar, int amount, int opposite) {
     
         opposite = Math.abs(amount);//finds absolute value
    for (int i = 0; i <= opposite; i++) {// first negative loop
          for (int j = 0; j <= i; j++) { // second negative loop  
            if (i == opposite) { 
              for (int k = 0; k<= opposite; k++)// third negative loop
                System.out.print("*");//prints for right outside of triangle
              break;//  ends third negative loop
    } 
              else if (i > 1) {
              System.out.print("*");          
              for (int k = 0; k < i - 1; k++)// fourth negative loop
                System.out.print(" ");
              System.out.print("*"); 
              break;// end fouth negative loop                  
     } else //else to print outside of triangle
              System.out.print("*");//prints for right outside of triangle
          } // restarts the negative  second loop
          System.out.println();
        }// restarts the negative first loop
    }// ends loop
     
     
     
     
     
     
        }

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Method Help

    dont work
    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Mar 2014
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Method Help

    I am trying to create methods for each of my assigned task. The first there work without any problems since they don't pull Strings or ints. When I try to pull positiveTriangle or negativeTriangle it gives me an error in NetBean. Any help would be great.

    Thanks

    positiveTriangle();

    negativeTriangle();
    don't work

    Screen Shot 2014-03-09 at 2.30.53 PM.jpgScreen Shot 2014-03-09 at 2.30.27 PM.jpgScreen Shot 2014-03-09 at 2.30.35 PM.jpg





     
    import java.util.Scanner;
    public class main {
     
     
        public static void main(String[] args) {
     
        purpose();
     
        gettingPrintCharacter();
     
        gettingVarifyingInputs();
     
        positiveTriangle();
     
        negativeTriangle();
     
     
        }
     
        public static void purpose() {  
                System.out.print("This program will print a right triangle. \nThe "
                   + "character that is entered at the prompt will be used to print"
                   + " a right triangle.  \nThe value that is entered at the prompt "
                   + "will be the right triangle's height and width.  \nIf the value "
                   + "is negative only an outline of the triangle will be printed "
                   + "else a filled in triangle will be printed.\n\n");
           //displays purpose of program 
            }
     
        public static void gettingPrintCharacter(){
        Scanner keyboard = new Scanner (System.in);
        System.out.print("Enter the character to be used: ");
            String triangle = keyboard.next();
            //converts character(s) entered into string
           char aChar = triangle.charAt(0);
            //slects only the first character of the string
           //the string above is to "idiot" or accident prof if they enter 
           //more than one character
        }
     
        public static void gettingVarifyingInputs(){
           Scanner keyboard = new Scanner (System.in);
           int amount;
           boolean valid= false;
           while (!valid)//first loop unitl uers inputs correct value
            {// starts the main loop
         System.out.print("Enter a non-zero integer length (+/-1 through +/-16): ");
         amount = keyboard.nextInt();// length and width of triangle
         while(amount == 0 || amount >16 || amount <-16)// invalid input tester
        {// starts second loop for user to input correct value
         System.out.print("Input value outside of range");
         System.out.print("\nEnter a non-zero integer length (+/-1 through +/-16): ");
         amount = keyboard.nextInt();// length and width of triangle
        }// ends loop
        valid = true;// end user input loop
        }
        }
     
        public static void positiveTriangle(String aChar, int amount){
     
         int i = 1;
            int j = i;
    do { //first do loop
        do{//second do loop
            System.out.print(aChar);
            j++;
        }while (j<=i);//second while loop end
        System.out.println();
              i++;
         j=1;
    }while(i<=amount);//first while loop end
        }//ends last else 
     
        public static void negativeTriangle(String aChar, int amount, int opposite) {
     
         opposite = Math.abs(amount);//finds absolute value
    for (int i = 0; i <= opposite; i++) {// first negative loop
          for (int j = 0; j <= i; j++) { // second negative loop  
            if (i == opposite) { 
              for (int k = 0; k<= opposite; k++)// third negative loop
                System.out.print("*");//prints for right outside of triangle
              break;//  ends third negative loop
    } 
              else if (i > 1) {
              System.out.print("*");          
              for (int k = 0; k < i - 1; k++)// fourth negative loop
                System.out.print(" ");
              System.out.print("*"); 
              break;// end fouth negative loop                  
     } else //else to print outside of triangle
              System.out.print("*");//prints for right outside of triangle
          } // restarts the negative  second loop
          System.out.println();
        }// restarts the negative first loop
    }// ends loop
     
     
     
     
     
     
        }

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Method Help

    Please copy the text of the error messages and paste it here. No images.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Mar 2014
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Method Help

    method negativeTriangle in class method cannot be applied to given types;
    required: String, int, int
    found: no arguments
    reason: actual and formal arguments list differ in length




    method positiveTriangle in class method cannot be applied to given types;
    required: String, int
    found: no arguments
    reason: actual and formal arguments list differ in length





    ")" expected
    ";" expected
    not a statement
    ";" expected
    cannot find symbol
    symbol: variable String
    location: class main

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Method Help

    method negativeTriangle in class method cannot be applied to given types;
    required: String, int, int
    found: no arguments
    reason: actual and formal arguments list differ in length
    The compiler was complaining that the call to the negativeTriangle method was wrong.
    It found: no arguments were used in the call
    But the method required: these three arguments: String, int, int

    Change the call to the method to pass the method a String and two int values.
    Look at the code for the method's definition to see what should be in those variables.

    ")" expected
    ";" expected
    not a statement
    ";" expected
    cannot find symbol
    symbol: variable String
    location: class main
    Those error messages are useless because they do not show where the errors are located.

    The compiler's message should show the source with a ^ under the location of the error.
    Here is a sample from the javac compiler:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Mar 2014
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Method Help

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: main.positiveTriangle
    	at main.main(main.java:29)
    Java Result: 1

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Method Help

    Can you use the javac compiler to get the error messages. I don't know what that error message from the IDE means.

    What is the code at line 29?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 6
    Last Post: December 29th, 2013, 03:34 PM
  2. Replies: 4
    Last Post: December 9th, 2013, 10:40 AM
  3. Replies: 1
    Last Post: January 23rd, 2013, 07:29 AM
  4. [SOLVED] How to create a Java generic method, similar to a C++ template method?
    By Sharmeen in forum Object Oriented Programming
    Replies: 3
    Last Post: October 18th, 2012, 02:33 AM
  5. Replies: 3
    Last Post: October 31st, 2011, 12:42 AM

Tags for this Thread