8 Replies - 11125 Views - Last Post: 16 December 2012 - 11:09 AM Rate Topic: -----

#1 u_haluk   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-December 12

type does not take parameters, Java Beginner Question

Posted 16 December 2012 - 08:59 AM

I'm getting en error that says: type Bag does not take parameters, what would be the error?
Here is the code:

public class ConsonantCounter implements Bag<String>
{
    private Bag<String> letters;
    private Bag<String> vowels;
    private Bag<String> consonants;
    
    
    public ConsonantCounter()
    {
        letters = new Bag<String>();
        vowels = new Bag<String>();
        consonants = new Bag<String>();
    }
    
    public Bag<String> getConsonants(String str)
    {
     String upStrings = str.trim().toUpperCase();
    
     
      vowels.add("A");
      vowels.add("E");
      vowels.add("I");
      vowels.add("O");
      vowels.add("U");
      
    
     for(int index=0; index < str.length(); index++)
      {
     String characterString = upStrings.substring(index, index + 1);
     Character character = characterString.charAt(0);
     if (Character.isLetter(character))
     {
         String newchar = character.toString();
         letters.add(newchar);
    
     }
      }
     
     for(int index2 = 0; index2< letters.getCurrentSize(); index2++)
     {
         
     }
     
     
        
        
    }
    public String toUpperCase()
    {
    }
    /**
     * getFrequency returns the frequency of the given consonant 
     * 
     * @param    true
     * @return   frequency of a consonant in the string  
     */
    public int getFrequency(String consonant)
    {
       
        
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: type does not take parameters, Java Beginner Question

#2 GregBrannon   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2250
  • View blog
  • Posts: 5,340
  • Joined: 10-September 10

Re: type does not take parameters, Java Beginner Question

Posted 16 December 2012 - 09:04 AM

There are many errors. Can you describe what this bit of code is supposed to be (or become)? Start with describing what Bag is.
Was This Post Helpful? 0
  • +
  • -

#3 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2770
  • View blog
  • Posts: 4,429
  • Joined: 21-June 11

Re: type does not take parameters, Java Beginner Question

Posted 16 December 2012 - 09:05 AM

The error would be that you defined the Bag interface without type parameters (i.e. interface Bag {...}, not interace Bag<T> {..}), but you're using it with type parameters. That's what the error message is saying anyway.

This post has been edited by sepp2k: 16 December 2012 - 09:08 AM
Reason for edit:: s/class/interface/g

Was This Post Helpful? 0
  • +
  • -

#4 u_haluk   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-December 12

Re: type does not take parameters, Java Beginner Question

Posted 16 December 2012 - 09:19 AM

View PostGregBrannon, on 16 December 2012 - 09:04 AM, said:

There are many errors. Can you describe what this bit of code is supposed to be (or become)? Start with describing what Bag is.


This method will create a bag containing all of the consonants in the String str, converted to upper case. Note that str may contain characters that are not letters as well as lower-case letters. As an example, str could be “The quick brown fox, named Red Tail, jumped over the lazy dachshund, named Weiner.”
Was This Post Helpful? 0
  • +
  • -

#5 u_haluk   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-December 12

Re: type does not take parameters, Java Beginner Question

Posted 16 December 2012 - 10:58 AM

any other replies appreciated.
Was This Post Helpful? 0
  • +
  • -

#6 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2770
  • View blog
  • Posts: 4,429
  • Joined: 21-June 11

Re: type does not take parameters, Java Beginner Question

Posted 16 December 2012 - 10:59 AM

View Postu_haluk, on 16 December 2012 - 06:58 PM, said:

any other replies appreciated.


Why? Did I not answer your question?
Was This Post Helpful? 0
  • +
  • -

#7 u_haluk   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-December 12

Re: type does not take parameters, Java Beginner Question

Posted 16 December 2012 - 11:03 AM

View Postsepp2k, on 16 December 2012 - 10:59 AM, said:

View Postu_haluk, on 16 December 2012 - 06:58 PM, said:

any other replies appreciated.


Why? Did I not answer your question?


I didn't want to be mean. I need to know more about it like how would I implement it correctly? I don't really know how to define its parameter and can't really find what to do. :)
Was This Post Helpful? 0
  • +
  • -

#8 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2770
  • View blog
  • Posts: 4,429
  • Joined: 21-June 11

Re: type does not take parameters, Java Beginner Question

Posted 16 December 2012 - 11:05 AM

View Postu_haluk, on 16 December 2012 - 07:03 PM, said:

I didn't want to be mean. I need to know more about it like how would I implement it correctly?


How did you implement it now? You never showed us the definition of your Bag interface.

Anyway, if you want to use your interface as Bag<String>, you'll have to define it as interface Bag<T> and then use T in the signatures of your methods.

Wait... after reading your code again, I'm suddenly no longer even sure whether Bag is an interface or a class. You use it like a class in some cases (e.g. you instantiate it with new), but at the beginning you say that your class is implementing ]Bag<String>, which would certainly imply that it's an interface. However none of your class's methods actually look like they'd be specified by the Bag interface (if it is one).

This post has been edited by sepp2k: 16 December 2012 - 11:09 AM

Was This Post Helpful? 0
  • +
  • -

#9 u_haluk   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-December 12

Re: type does not take parameters, Java Beginner Question

Posted 16 December 2012 - 11:09 AM

View Postsepp2k, on 16 December 2012 - 11:05 AM, said:

View Postu_haluk, on 16 December 2012 - 07:03 PM, said:

I didn't want to be mean. I need to know more about it like how would I implement it correctly?


How did you implement it now? You never showed us the definition of your Bag interface.

Anyway, if you want to use your interface as Bag<String>, you'll have to define it as interface Bag<T> and then use T in the signatures of your methods.


Thanks again for the reply. If you still are interested knowing the definition, it is:
/**
* ConsonantCounter is a program that takes in a string, discards the vowels in the string,
* counts the number of consonants in the string and displays them.
*/

I will try what you have said. Thanks again!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1