Close

Results 1 to 6 of 6
  1. #1
    DF VIP Member Nikki's Avatar
    Join Date
    Dec 2002
    Location
    Walsall
    Posts
    12,413
    Thanks
    559
    Thanked:        148
    Karma Level
    899

    Attention Any Java Coders In The DF House?

    I am in need of a hand if anyone has time to have a look

    (a) Develop a class called Module that describes a module at a university. The Module class has instance variables as follows:
    • code is a reference to the code of the module, a String e.g. a valid code would be "P101"
    • title is a reference to the title of the module, a String e.g. "Feeding fish"
    • points stores the number of points the module is worth, an int.
    The Module class will require the following methods, which other classes should be able to access.
    • Standard getter and setter methods for the instance data (code, title and points); that is, the getters return the instance data values and the setters set the instance data values to received arguments.
    • String toString returns a string containing the full details of the module, giving the module code, title and number of points in parentheses, for example P101, Doing Neat Stuff (20 points).
    • boolean equals(Object o) returns true if the module referenced by o has the same instance variable values as the object on which this method is invoked; otherwise the method returns false. (Note, you do not have to worry about the case when the string instance data is null.)
    • boolean isCode(String aCode) returns true if the aCode string is a valid module code. For this scenario this means that it begins with a capital letter and has exactly four characters. Otherwise the method returns false. This method is a class method, not an instance method.
    Also add the following constructor to the Module class:
    • a three-argument constructor receiving a code, a title string, and a number of points, which sets the code, title and points data of the created object to the received values.


    I have developed my class called module and inputted my setter and getter methods, it is the toString and Boolean one i am having difficulty with.

    I have inputted

    public String toString ()

    return "Module" + myCode + "Points" + myPoints;
    }

    Module o = new myCode ("example");
    System.out.println (o);
    }


    Seem to get the enum / class interface expected error?

    many thanks

  2. #2
    DF VIP Member mysterym's Avatar
    Join Date
    May 2002
    Location
    90210
    Posts
    1,615
    Thanks
    70
    Thanked:        59
    Karma Level
    346

    Default Re: Any Java Coders In The DF House?

    I'm not a java programmer, but i am an asp.net dev. Do you code in a development enviroment? and does it actually tell you which line of your code is falling over?

    Also, System.out.println(o); is dumping the whole object o out, are you sure you don't mean System.out.println(o.toString); as i'm guessing you are trying to either dump the contents of a method or property?

    Edit: Shoud also add, your object instatiation is passing through a string ("example")

    Module o = new myCode ("example");

    I'm guessing you've got a contructor in place to accept that string parameter.
    Last edited by mysterym; 18th December 2011 at 07:37 PM.

  3. #3
    DF VIP Member Nikki's Avatar
    Join Date
    Dec 2002
    Location
    Walsall
    Posts
    12,413
    Thanks
    559
    Thanked:        148
    Karma Level
    899

    Default Re: Any Java Coders In The DF House?

    Yeah it should be the contents of the strings added to together within the system.out.println.

    i am coding in Netbeans IDE

  4. #4
    DF VIP Member blacksheep's Avatar
    Join Date
    Jun 2006
    Location
    Manchester
    Posts
    3,877
    Thanks
    87
    Thanked:        265
    Karma Level
    546

    Default Re: Any Java Coders In The DF House?

    will possibly depend on the java version you're using (google for int autoboxing). An int is a primitive and not an object and doesn't have a toString() method. Use Integer.toString(myPoints) in your toString method.

  5. #5
    DF VIP Member Mobius's Avatar
    Join Date
    Jun 2001
    Location
    The Internet
    Posts
    170
    Thanks
    3
    Thanked:        9
    Karma Level
    285

    Default Re: Any Java Coders In The DF House?

    Autoboxing isn't an issue when concatinating Strings and primatives. Nikki are these snippets of your code or is this all you have. If theres more please post the whole thing.

  6. #6
    DF VIP Member Ynox's Avatar
    Join Date
    Dec 2003
    Location
    Cardiff/Cov
    Posts
    191
    Thanks
    0
    Thanked:        0
    Karma Level
    261

    Default Re: Any Java Coders In The DF House?

    Bit late to the party on this one.

    But does myCode exist? That error is usually thrown if it can't find what you're trying to instantiate. As said above, post the full source and it should be simple to show you where you're going wrong.

Similar Threads

  1. Moving house - can I take my dsl with me?
    By bugnote in forum Internet Connections & VPNs
    Replies: 5
    Last Post: 9th October 2002, 06:18 PM
  2. Java console??
    By Jaffa in forum PC Problems
    Replies: 3
    Last Post: 26th September 2002, 02:14 AM
  3. Java Idea?
    By Roo in forum Unlocking Questions & Solutions
    Replies: 0
    Last Post: 8th September 2002, 06:55 PM
  4. coders lunch box - web site dev
    By wadgey in forum Forum Bug & Error Reports
    Replies: 1
    Last Post: 30th August 2002, 05:10 AM

Social Networking Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •