The Java Library Comments


  • public Note(String bericht)
    //complete this accessor method
    public String getContent()
    {return content;
    public int noteLength(){
        return content.length();
  • I'm having trouble with the BlueJ task. I've managed to get the tests to succeed for TheStringClassTest, but when I run the tests for TheStringMethodsTest, it fails. This is the code I've written for the addToNote and summarize methods:

  • When you click on the test result in BlueJ, it will show you what your method returned and what it expected. This can help you find your error.

    Look at the definition of substring. What number do you want to go up to (but not including) to get the first 20 characters? (Remember that the first index is 0.)

  • This is my code for third BONUS task. But it did not pass test. What is wrong ?

    public int wordCount()
    String[] words = content.split(" ");
    int i = words.length;
    return i;

  • How does it handle words separated by one or more spaces?

  • This bonus task could be solved in different ways, but the simplest (though not covered) would be to split the text on a regex pattern for one or more white spaces.

  • It's a pity you can't get the answer somewhere on the site.

    I try
    String[] snacks = words.replace('x' , 'c').split(",");

    and it is not correct, but how would I ever find out what I'm doing wrong?

  • Ok the [] were bad, because it's not an array, of course. But I'm still stumped.

  • Your answer was very close but do you want to split the strings by commas or spaces?

  • Let's not go there, OK?

    (Kidding. Of course. Thank you for the hint.)

  • Hi. There is diference between code here in article and code in BlueJ project. What is the right code ?

    private ArrayList notes;

    public Notebook()
  • The answer is in next node. Sory for question.

  • i cant figure it out at all, can anyone help me and just give the right awnsers?

  • I must be missing something obvious.... why do neither of these work:

    fruit.add(String orange);

  • Strings need quotes.

  • Wow... so apparently I don't know what I'm doing here:

    private ArrayList fruit = new ArrayList();

    doesn't work. I understand that would only work INSIDE a class.

    Maybe I just answered my own question.
    Please confirm, why can't I call it private?

  • That's correct. When you're inside a method, every variable you declare can only be accessed inside the method, so you don't use the private modifier.

  • Can't get this to work:

    import java.util.ArrayList;

    public class Notebook

    private ArrayList notes;

    public Notebook()
  • Sorted!

  • "Modify the ArrayList notes in the Notebook class so that it only takes in String Objects."

    Is it just me, or do you actually want the ArrayList notes to be taking Note Objects rather than String Objects...?

  • @Jason, thanks, corrected.

  • Can someone help me this code wont compile and I have no idea why.
    public String getNote(int p){
    String n = notes.get(p);
    return notes.get(p);

  • // getNote
    public Note getNote(int pos){
    Note gottenNote = notes.get(pos);
    return gottenNote;

  • So - there's no kind of feedback on the Tasks, right? Nor on whether they've been completed at all? I never do anything unless I have to, alas. That's why I come to this website to learn Java, instead of reading a book.

  • As mentioned in The String Class, you can download a provided BlueJ project and run test cases on your own computer after completing the code. This way you can get the benefit of coding in on your own computer and still get the feedback after completing your code.

  • I know. That's a very good thing. It's just, I'm the sort of person who never does that. I only complete something if, otherwise, you can't go on to the next page.
    Sad but true!

    Thanks for your answer.

  • java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 means that it tried to access the first element in the ArrayList but the ArrayList was empty.

  • Can I have some help? For some reason I cannot add notes to notebook.

    import java.util.ArrayList;

    public class Notebook

    private ArrayList notes;

  • @BentheMuffin, you'll want to set a type when you create the ArrayList. See ArrayList Type.

  • BlueJ do not want to compile "switch(input)" because input is String. What should I do ?

  • If you're using Java 6, you should use an if-else statement instead.

  • Is it normal to initialize your Notebook in a menu class? Should I put it somewhere else? Would it be smart to create an Initialize class?

  • In this case I think it's fine. In a larger program it's true that it might make sense to create the Notebook separately.

  • A user asked why doesn't this code work? It just prints out 7.

    public static void main(String[] arguments) {
        Scanner sc = new Scanner(;
        int sum = doStuff(sc.nextInt(), sc.nextInt());
  • Look at the input format carefully: "The first line of input will contain the number of test cases t. t lines will follow, with each line containing the 2 numbers to be summed." You need to first get the number of lines, and then call doStuff that number of times with the remaining input.

  • My code its like this and it just prints out 7. why input is 5 2 3?
    public static int doStuff(int a, int b){
    int sum=0;
    return sum;

  • Hi. My program is doing this:

    Explanation: After entering input "quit" the notebook start once again. I must enter again "quite" and after that the program really ends

Contact Us
Sign in or email us at [email protected]