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 10 of 10

Thread: Need help with parameter passing in my project? (Beginner)

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Need help with parameter passing in my project? (Beginner)

    For my Computer Science class, I was instructed to use Parameter passing to edit a project I recently created. I was supposed to have no global variables other than the ones needed for file reading. Using local variables, I was able to run the program successfully but when I used parameter passing for certain Strings and an int, the following error always pops up and I cannot find out how to solve it:

    error: method isVowel in class VowelsRUs cannot be applied to given types;
    isVowel();
    ^
    required: String,String,String,String,int
    found: no arguments
    reason: actual and formal argument lists differ in length

    This is my actual code:

    //let's first import the classes we need
    import java.io.*;
    import java.util.StringTokenizer;
    import java.util.HashSet;
     
    public class VowelsRUs
    {
    //method variables
    private static FileInputStream inFile;
    private static InputStreamReader inReader;
    private static BufferedReader reader;
    private static StringTokenizer strTkn;
     
    //class to get file and read it from the .txt
    public static void main (String args[]) throws IOException
    {
     
     
    initFile();
    isVowel();
    inFile.close();
     
    }
     
    public static void initFile() throws IOException
    {
    //data-file input
    inFile = new FileInputStream ("b:\\School\\!!AP Computer Science\\!!VHSAPCSDATA\\vowels.txt");
    inReader = new InputStreamReader (inFile);
    reader = new BufferedReader (inReader);
    }
     
    public static boolean isVowel(String suffixR, String wordR, String wordPlural, String wordSuffix, int leftmostIndex) throws IOException //Beggining of a gigantic method, this is where I can declare most of my local variables
    {
     
    String line, suffix, firstLetter, lastLetter, testLetter, vowelSeries, consonantSeries;
    String word;
    HashSet vowels = null;
     
    //line can't be null for the while loop to work
    line = "start";
     
    while (line != null) {
     
    //data file -> strings
    line = reader.readLine(); //instructs it to read each line
     
    if (line == null) {
    break;
    }
     
     
     
    strTkn = new StringTokenizer(line);
     
    word = strTkn.nextToken();
    suffix = strTkn.nextToken();
     
     
     
    //adding vowels for comparison later
    vowels = new HashSet();
    vowels.add("A");
    vowels.add("C");
    vowels.add("S");
    vowels.add("L");
     
     
     
    //setting output variables
    wordPlural = word;
    wordSuffix = word;
     
     
     
    //reverse word for testing of the rules
    for (int i = 0; i < word.length(); i++) {
    wordR = word.substring(i, i+1) + wordR;
    }
     
    //reverse suffix for testing of the rules
    for (int i = 0; i < suffix.length(); i++) {
    suffixR = suffix.substring(i, i+1) + suffixR;
    }
     
     
    //Rule if wordR ends in a consonant
    if (vowels.contains(wordR.substring(0,1)) == false) {
     
     
    //Rule if wordR ends in more than one consonant
    if (vowels.contains(wordR.substring(1,2)) == false) {
     
     
    //Double the last letter, then add ‘H’
    lastLetter = wordR.substring(0,1);
    wordPlural = wordR.concat(lastLetter);
    wordPlural = wordR.concat("H");
    System.out.print("plural: " + wordR);
     
    //Rule if suffix ends in a consonant
    if (vowels.contains(suffixR.substring(1,2)) == false) {
    //drop the leftmost letter of the final sequence of either vowels or consonants, then add the suffix
     
    vowelSeries = word.substring(word.length()-leftmostIndex, word.length());
    vowelSeries = vowelSeries.substring(1, vowelSeries.length());
    wordSuffix = wordSuffix.substring(0, leftmostIndex);
    wordSuffix = wordSuffix.concat(vowelSeries);
    wordSuffix = wordSuffix.concat(suffix);
    System.out.println("Suffix: " + wordSuffix);
     
    //Rule if suffix ends in vowel
    }else{
    //add the first letter of the suffix, then add the suffix
    firstLetter = suffix.substring(0,1);
    wordSuffix = suffix.concat(firstLetter).concat(word);
    System.out.println("Suffix: " + wordSuffix);
    }
     
     
    //Rule if wordR ends in 1 consonant
    }else{
     
     
    //original string
    System.out.println("Original String: " + line);
    //add “GH”
    wordPlural = word.concat("GH");
    System.out.println("Plural: " + wordPlural);
    //add the suffix
    wordSuffix = word.concat(suffix);
    System.out.println("Suffix: " + wordSuffix);
    }
     
    //Rule if wordR ends in a vowel
    }else{
     
    //Rule if wordR ends in more than 1 vowel
    if (vowels.contains(wordR.substring(1,2)) == true) {
     
     
     
    //Index of leftmost of vowel series
    for (int i = 0; i < wordR.length(); i++) {
    if (vowels.contains(wordR.substring(i, i+1))) {
    leftmostIndex++;
    }else{
    break;
    }
    }
     
     
    //original String
    System.out.println("Original String: " + line);
     
    //double the last letter, then add ‘H’
    lastLetter = wordR.substring(0,1);
    wordPlural = word;
    wordPlural = wordPlural.concat(lastLetter);
    wordPlural = wordPlural.concat("H");
    System.out.println("Plural: " + wordPlural);
     
    //Rule if suffix ends in consonant
    if (vowels.contains(suffixR.substring(1,2)) == false) {
    //drop the leftmost letter of the final sequence of either vowels or consonants, then add the suffix
    vowelSeries = word.substring(word.length()-leftmostIndex, word.length());
    vowelSeries = vowelSeries.substring(1, vowelSeries.length());
    wordSuffix = wordSuffix.substring(0, leftmostIndex);
    wordSuffix = wordSuffix.concat(vowelSeries);
    wordSuffix = wordSuffix.concat(suffix);
    System.out.println("Suffix: " + wordSuffix);
    //Rule if suffix ends in vowel
    }else{
    //add the first letter of the suffix, then add the suffix
    firstLetter = suffix.substring(0,1);
    wordSuffix = suffix.concat(firstLetter).concat(word);
    System.out.println("Suffix: " + wordSuffix);
    }
     
    }else{
     
     
     
    System.out.println("Original String: " + line);
     
    //drop the final vowel and add ‘G’
    wordPlural = word.substring(0, word.length()-1);
    wordPlural = wordPlural.concat("G");
    System.out.println("Plural: " + wordPlural);
     
    //Rule if suffix ends in consonant
    if (vowels.contains(suffixR.substring(1,2)) == false) {
    //add the first letter of the suffix and then add the suffix
    firstLetter = suffix.substring(0,1);
    wordSuffix = wordSuffix.concat(firstLetter);
    wordSuffix = wordSuffix.concat(suffix);
    System.out.println("Suffix: " + wordSuffix);
     
    //Rule if suffix ends in vowel
    }else{
    //drop the first letter of the suffix and add the rest of the suffix
    suffix = suffix.substring(1, suffix.length());
    wordSuffix = word;
    wordSuffix = word.concat(suffix);
    System.out.println("Suffix: " + wordSuffix);
     
    }
    }
    } //line
     
        } //End of loop
         } //End of Method "doStuff()"
                              } //end of class "VowelsRUs" (Finally)


    I am a new member to this forums, and I am also a beginner at Java so be nice! Can anyone help me solve this problem? I've been working on this project for hours. Thanks in advance!


  2. #2
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Need help with parameter passing in my project? (Beginner)

    Here is the declaration of your method:

    isVowel(String suffixR, String wordR, String wordPlural, String wordSuffix, int leftmostIndex)

    It requires these parameters: String, String, String, String, int

    Here is how you use it:

    isVowel();

    You don't pass any parameters, so there's an error because the method requires five parameters and you aren't giving it any.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  3. The Following User Says Thank You to snowguy13 For This Useful Post:

    xlFireman (January 12th, 2012)

  4. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Need help with parameter passing in my project? (Beginner)

    I tried what you said and gave it some parameters

    isVowel(String, String, String, String, int);

    but I now get the error:

    error: '.class' expected
    isVowel(String, String, String, String, int);


    Thanks for your help btw. I really appreciate it.
    Last edited by xlFireman; January 12th, 2012 at 06:49 PM.

  5. #4
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Need help with parameter passing in my project? (Beginner)

    The parameters you pass can't just be classes or data types, you actually have to put variables into those spaces. You are getting the error because "String" is not a variable, but a class, and it cannot be used as a variable in and of itself.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  6. #5
    Junior Member
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Need help with parameter passing in my project? (Beginner)

    Should I format it like this:
    isVowel(String someVariable, String someVariable, String someVariable, String someVariable, int someInteger);

    or like this:

    isVowel(someVariable, someVariable..., someInteger);
    Thanks for your help. Could you just show me the correct way to do it?

  7. #6
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Need help with parameter passing in my project? (Beginner)

    isVowel(someVariable, someVariable..., someInteger);
    Yes! Something like that!

    Could you just show me the correct way to do it?
    Ehhh... No. That'd be no fun for you! I can't tell you how to think about this, you have to develop the understanding of this concept. Sorry. :p
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  8. The Following User Says Thank You to snowguy13 For This Useful Post:

    xlFireman (January 12th, 2012)

  9. #7
    Junior Member
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Need help with parameter passing in my project? (Beginner)

    I am still a little confused about where to place it. Should I place it underneath the method isVowel? And you said to enclose it in brackets, do you mean like this?

    public static void isVowel(String suffixR, String wordR, String wordPlural, String wordSuffix, int leftmostIndex) throws IOException

    {
    isVowel(String suffixR, String wordR, String wordPlural, String wordSuffix, int leftmostIndex);
    }

    Because right now when I place it like this, it gives me an error, could you use the program block I provided you and show me where to place it?

  10. #8
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Need help with parameter passing in my project? (Beginner)

    No, don't do that.

    Hmm... Okay, your method asks for String, String, String, String, int. When you call the method, you have to put values into the method that match the parameter list. So, for example, you could do something like this:

    isVowel("text", "otherText", "another string", "and one more", 5);

    I don't know what your program does with all these parameters, so my inputs might not work for your program.

    When the method asks for a String, you have to give it an instance of a String, like "coast", "this is a string too", or "..;soi43p9823 silly string".

    If it asks for an integer, GIVE it an integer, like 6, 2, 70, or 99. These can also be variables.

    So for example, let's say you have these variables:

    String a="", b="", c="", d="";
    int num = 6;

    You could call isVowel() like this:

    isVowel(a, b, c, d, num);

    Because a, b, c, and d are all Strings, and num is an int.

    Does that make a little more sense (hopefully)?
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  11. #9
    Junior Member
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with parameter passing in my project? (Beginner)

    you must have to pass the argument in your method. for example ..

    isVowel("suffixR","wordR","wordPlural","wordSuffix ",5);

  12. #10
    Junior Member
    Join Date
    Jan 2012
    Location
    Mumbai
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with parameter passing in my project? (Beginner)

    you must have to pass the argument in your method. for example ..

    isVowel("suffixR","wordR","wordPlural","wordSuffix ",5);
    Yes i agree with this statement.
    The function declaration must have to match the parameter while calling that particular function.

Similar Threads

  1. Beginner Project
    By Saberunna in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 9th, 2011, 08:49 PM
  2. [SOLVED] sending a parameter to a new JDialog
    By luisp88 in forum AWT / Java Swing
    Replies: 4
    Last Post: October 5th, 2011, 09:31 AM
  3. Passing JTextField as String parameter
    By Christophe in forum Java Theory & Questions
    Replies: 3
    Last Post: April 11th, 2010, 05:32 AM
  4. Passing objects as a constructor parameter
    By derky in forum Object Oriented Programming
    Replies: 2
    Last Post: October 27th, 2009, 04:31 AM
  5. Best beginners project in Java
    By Fendaril in forum Java Theory & Questions
    Replies: 3
    Last Post: February 10th, 2009, 08:52 AM