lesson 9

paul meade
2009-08-31
2013-04-09
  • paul meade
    paul meade
    2009-08-31

    Hi Mark,
    thanks for the vids real help! But in lesson 9 we import a array list (java.util) I have followed the steps you make, and all looks ok, but when I go to use the new command I do not get any options when I press ctrl+space, so I cannot create a new object. Please help as I have been looking at this for many hours trying to find whats wrong, I even repeated all steps from the start to no avail.
    Cheers Paul

     
    • Mark Dexter
      Mark Dexter
      2009-09-01

      Hi Paul. Can you please attach a complete copy of the source file for the program you are trying to run? Then I can try it here and see what the problem is. Thanks. Mark

       
    • paul meade
      paul meade
      2009-09-01

      Hi Mark,
      This is all the code I have written, when you have a moment please have a look.
      More comments at the end.  Sorry it is so long.
      Cheers
      Paul

                  Book.java                 

      package org.totalbeginner.tutorial;

      public class Book {

          String title;
          String author;
          Person person;

          public Book(String string) {
              this.title = string;
              this.author = "unknown author";
             
             
          }

          public String getAuthor() {
              return author;
          }

          public void setAuthor(String author) {
              this.author = author;
          }

          public String getTitle() {
              return title;
          }

          public void setPerson(Person p2) {
              this.person = p2;
                     
          }

          public Person getPerson() {
              return this.person;
          }

      }
                  Peson.java

      package org.totalbeginner.tutorial;

      public class Person {
          // fields
          private String name; // name of person
          private int maximumBooks; // most books a person can check out
         
          // constructors
          public Person() {
              name = "unknown name";
              maximumBooks = 3;       
          }
          // methods
          public String getName() {
              return name;
          }
         
          public void setName(String anyName) {
              name = anyName;
          }
          public int getMaximumBooks() {
              return maximumBooks;
          }
          public void setMaximumBooks(int maximumBooks) {
              this.maximumBooks = maximumBooks;
          }
         
          public String toString() {
              return this.getName() + " (" + this.getMaximumBooks() + " books)";
          }
             
          }

                  PersonTest.java

      package org.totalbeginner.tutorial;

      import junit.framework.TestCase;

      public class PersonTest extends TestCase {

          public void testPerson() {
              Person p1 = new Person();
              assertEquals("unknown name", p1.getName());
              assertEquals(3, p1.getMaximumBooks());
             
          }

          public void testSetName() {
              Person p2 = new Person();
              p2.setName("Fred");
              assertEquals("Fred", p2.getName());
             
          }

          public void testSetMaximumBooks() {
              Person p3 = new Person();
              p3.setMaximumBooks(10);
              assertEquals(10, p3.getMaximumBooks());
          }
         
          public void testToString() {
              Person p4 = new Person();
              p4.setName("Fred Flintstone");
              p4.setMaximumBooks(7);
              String testString = "Fred Flintstone (7 books)";
              assertEquals(testString, p4.toString());
             
          }

      }
                  BookTest.java

      package org.totalbeginner.tutorial;

      import junit.framework.TestCase;

      public class BookTest extends TestCase {
         
          public void testBook() {
              Book b1 = new Book("Great Day");
              assertEquals("Great Day", b1.title);
              assertEquals("unknown author", b1.author);
             
          }
         
          public void testGetPerson() {
              Book b2 = new Book("War And Peace");
              Person p2 = new Person();
              p2.setName("Elvis");
             
              // method to say book is loaned to this person
              b2.setPerson(p2);
             
              // get the name of the person who has the book
      //        Person testPerson = b2.getPerson();
      //        String testName = testPerson.getName();
             
              String testName = b2.getPerson().getName();       
              assertEquals("Elvis", testName);
             
          }
         
             

      }

                  AllTest.java

      package org.totalbeginner.tutorial;

      import junit.framework.Test;
      import junit.framework.TestSuite;

      public class AllTests {

          public static Test suite() {
              TestSuite suite = new TestSuite("Test for org.totalbeginner.tutorial");
              //$JUnit-BEGIN$
              suite.addTestSuite(PersonTest.class);
              suite.addTestSuite(BookTest.class);
              //$JUnit-END$
              return suite;
          }

      }

                  Myscrapbook.jpage
      new

      At this point the NEW will not allow me to add or create a object because there are no options under the Ctrl+space.

      I am following your Java-TotalBeginner Video course and this is the start of lesson 9 up until this point everything has gone as you explained it would, I have had zero problems and am using eclipse version "Eclipse IDE for Java Developers" downloaded last week from official site, my os is Xp.

      Please note I have "sets the import declarations for running code" and am seeing java.util in the java snippets imports wizard.

      I will be happy to sent you the project to review but am new to forums and have no idea how to send you the files without an email address.

      Mark I thank you for your time and hope this rather long post helps me find a solution to this. Your efforts are fully appreciated.

      All the best
      Paul

       
      • Mark Dexter
        Mark Dexter
        2009-09-06

        Hi Paul. I tried your code here and it works correctly. So there must be something about your environment (platform or Eclipse setup). There are some other posts about issues with the Eclipse scrapbook having issues. I don't know what your issue might be, but your code looks fine to me and all the tests run correctly. Good luck with the tutorials and with Java. Mark

         
  • Varun Boodram
    Varun Boodram
    2009-11-02

    Hello, Paul: This was driving me mad for a couple days, too. I fixed it by going under Preferences>Java>Editor>Templates, selecting "new" from the list, and editing the context to Java, and checking the "Automatically Insert" box. Hope that helps you out

     

  • Anonymous
    2009-11-06

    Thank you very much, varuboodram! I encountered absolutely the same problem with code assist in scrapbook. And your solution works fine.

     
  • bra1ntank
    bra1ntank
    2010-03-14

    I have the exact same problem, but could not solve it so far.Varuboodram, what did you call the new Template? I simply called it java/Java, didn't work both times. any more ideas?

     
  • Rick Sparza
    Rick Sparza
    2010-04-07

    Hi Mark, and everybody,

    How can obtain the complete video lessons?

    thnk a lot

     
  • Mark Dexter
    Mark Dexter
    2010-04-07

    I'm not sure I understand the question. You download the lessons from this site and then play them on your computer. Mark

     
  • Rick Sparza
    Rick Sparza
    2010-04-07

    Hi,

    i found it !

    Thnx

     
  • Janet
    Janet
    2010-04-11

    I have experienced the same problem with this lesson.  Up until now everything was going along without a hitch. Suddenly in lesson 9 the control/shift stopped working.  I tried varunboodram's suggestion but it didn't work for me.  Has anyone else come up with a reasonable explanation for this?

     
  • Janet
    Janet
    2010-04-11

    After some searching, I foiund a site that discusses this problem.  I had an error on the Book class that said, "type not resolved". That is what lead me to find this site.  http://philip.yurchuk.com/2008/12/03/eclipse-cannot-be-resolved-to-a-type-error/  I tried all of the suggestions there but it didn't solve my problem.  I am posting this in hopes that someone else will be helped by their suggestions.

     
  • Rudy
    Rudy
    2010-04-15

    Mark:
    I am having problems with the end of lesson 9.  I am trying to execute the statement:
    list.get(0).getPperson()
    I get an error that says "The method getPerson() is undefined for the type Object".  Also, the code assist for "list.get(0).get" only gives the getClass option, not getPerson, getAuthor or getTitle.  The code for the Person and Book classes is included below.  Any help you can provide is appreciated.

    The code I have for Person.java is:

    package org.totalbeginner.tutorial;

    public class Person {
    //fields
    private String name; //name of person
    private int maximumBooks; //most books person can check out

    //constructors
    public Person() {
    name = "unknown name";
    maximumBooks =3;
    }
    //methods
    public String getName() {
    return name;
    }
    public void setName(String anyName) {
    name = anyName;
    }

    public int getMaximumBooks() {
    return maximumBooks;
    }

    public void setMaximumBooks(int maximumBooks) {
    this.maximumBooks = maximumBooks;
    }
    //public String toString() {
    // // TODO Auto-generated method stub
    // return super.toString();
    //}
    public String toString() {
    return this.getName()+ " (" + this.getMaximumBooks()+ " books)";
    }
    }

    The code for Book.java is:

    package org.totalbeginner.tutorial;

    public class Book {

    String title;
    String author;
    Person person;

    public Book(String string) {
    this.title = string;
    this.author = "unknown author";
    }

    public String getAuthor() {
    return author;
    }

    public void setAuthor(String author) {
    this.author = author;
    }

    public String getTitle() {
    return title;
    }

    public void setPerson(Person p2) {
    this.person = p2;

    }

    public Person getPerson() {
    return this.person;

    }
    }

     
  • Mark Dexter
    Mark Dexter
    2010-04-15

    Hi. It sounds like you haven't imported the Book and Person classes into the scrapbook. You might want to go back through that process and make sure it worked ok. Good luck. Mark

     
  • Hi Everyone!
    At the begin please forgive me some language bugs, my english is not perfect.
    I have the exact same problem (as Paulpokerman), but could not solve it so far…
    Solution from Varunboodram at the beginning didn't work for me but… I do something more:
    Fallow this:

    Go to menu: Windows->Preferences->Java->Editor->Templates

      on the list on the right find "new" in Name column
      press Edit button and check the "Automatically Insert" box
      and more: open the "Content" list and use "Java" setting, (not "Java statement").

    This was help me too use Eclipse Content Assist mechanism in new object creating in ScrapBook.

    But it wasn't resolve next problem, when the list object was created
         ArrayList<strint> list = new ArrayList<strint>();
    the "list." type is not run the Content Assist in this pleace (Ctrl+Space not work) - any ideas?

    My Eclipse is: 1.3.0 Build id: 20100617-1415

     
  • Hi again,

      so my last question (any ideas?) was a solution…
    My mistake, the string type should start on the capital letter String - sorry.

     
  • icarus0
    icarus0
    2011-06-08

    @jhcarter60 and @Mark,

    Mark's method works in order to solve the "type not resolved: Book", you just have to add the classes 'Person' and 'Book' as follows:
    1) Click the "Set Import Declarations" button right next to red square "Stop evaluation" button.
    2) Select "org.totalbeginner.tutorial* "-> click the "Add Type" button
    3) Search for class 'Book' and 'Person' and add them to your MyScrapbook.jpage

    That's all…

    icarus0

     
  • yf.x
    yf.x
    2011-06-12

    I have tested the way of 15 ( duchnowski) and 17(icarus0). they're correct.

     
  • Dave
    Dave
    2011-08-17

    I had the same problem.  I found that I was simply not highlighting all of the lines in teh scrapbook.  Consequently, the declaration of the variable was apparently not in the contecxt of what was being inspected, so it could not be resolved.

    Highlight the entire set of lines and you should not see this error.

     
  • Yun Mao
    Yun Mao
    2011-08-27

    I had the same problem.  I was able to fix it by following the instruction provided by varuboodram.  Thank you varuboodram!
    Btw, the best java video tutorial I have found from internet so far.  Thank you Mark!  Great job.  Nicely done.

     
  • Kev Man
    Kev Man
    2012-03-15

    Thank you varunboodram!!!
    Users are best when it comes to fixing a tutorial's fails!!!!

     

  • Anonymous
    2012-07-02

    Thank you Varunboodram!!!