Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Thanked 0 Times in 0 Posts

    Question Programming beginner stuck on simple

    I have a simple project that is getting me stuck. The current submission is included. The question is:
    Write a class named Acc2 containing:
    An instance variable named sum of type integer, initialized to 0.
    A method named getSum that returns the value of sum .

    This is my current sumbission:
    public class Acc2
    private int sum = 0;
    public int getSum (){method sum;}

    The system says that the only thing wrong with it is the bold word method. I have tryed many things in place of it however I am unable to move on.

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Thanked 508 Times in 502 Posts
    Same problem as your last post. Wrong forum.

    Are you sure you took the right class?

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,749 Times in 4,711 Posts
    A method named getSum that returns the value of sum .
    And that didn't give you any clues?

    Are you sure you have read the first two chapters of your course material?

    And, yes, that answer would be true in JavaScript as much as it is in Java, but then it would be true in PHP, C, C++, C# and a raft of other languages. So aside from syntax similarities, it is still the case that Java and JavaScript are most similar in that their names start with the same 4 letters.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


    Posting Permissions

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