Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: please help me find errors on my code,please give me reasons why i keep getting errors

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default please help me find errors on my code,please give me reasons why i keep getting errors

    [B]class Accounts
    {
    int principal; // Data members of the class
    int interest;
    int time;
    int amt;
    public Accounts ()
    {
    principal = 50000;
    interest = 5;
    time = 3;
    return principal, interest, time;
    }
    public void calc()
    {
    amt= principal*interest*time/100;
    System.out.println(“The amount is :+ amt);
    }
    public static void main(String args[])
    {
    Accounts l1= new Accounts ();
    l1.calc();
    }
    }[/B]


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,290
    My Mood
    Mellow
    Thanks
    252
    Thanked 777 Times in 762 Posts

    Default Re: please help me find errors on my code,please give me reasons why i keep getting errors

    Welcome to the Forum! Thanks for taking the time to learn to post code correctly, and if you haven't already, please read this topic to see other useful info for newcomers.

    Though you managed to post your code in code tags (a good thing for a first post), either the formatting was lost or you don't indent your code (which is not a good thing). If you do indent your code, please copy your indented code as it appears at your end and replace the code you've posted with properly indented code. The bolding inside the code tags is unnecessary and may be contributing to loss of formatting, but I'm not sure.

    Post the errors you'd like help with.

  3. #3
    Junior Member
    Join Date
    May 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help me find errors on my code,please give me reasons why i keep getting errors

    Hi. You are getting errors because you have a return statement in the constructor.
    If you remove the return it should be ok.
    PS: In future, add a private identifier to your instance variables.

  4. #4
    Junior Member
    Join Date
    May 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help me find errors on my code,please give me reasons why i keep getting errors

    Can you please be at least more specific because m kind of beginner in java?

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,290
    My Mood
    Mellow
    Thanks
    252
    Thanked 777 Times in 762 Posts

    Default Re: please help me find errors on my code,please give me reasons why i keep getting errors

    // this is a constructor (notice no return type, not even void)
    public Accounts ()
    {
        principal = 50000;
        interest = 5;
        time = 3;
     
        // this is a return statement. constructors don't have return types.
        // constructors can't return values. methods that have a void
        // return type can't return values.
        return principal, interest, time;
     
    }
    You should know the basic names of the essential elements of a Java program; class, method, constructor, variable/field; what they mean, and how to find them in code.

    Other problems:

    The quotes you posted are not accepted by all editors compilers. Be sure to use a plain text editor or an IDE that uses the correct characters.

    You will be a victim of "integer math." Your equations will provide integer results, sometimes zero, when you might be expecting other results.

  6. #6
    Junior Member
    Join Date
    May 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help me find errors on my code,please give me reasons why i keep getting errors

    Quote Originally Posted by GregBrannon View Post
    // this is a constructor (notice no return type, not even void)
    public Accounts ()
    {
        principal = 50000;
        interest = 5;
        time = 3;
     
        // this is a return statement. constructors don't have return types.
        // constructors can't return values. methods that have a void
        // return type can't return values.
        return principal, interest, time;
     
    }
    You should know the basic names of the essential elements of a Java program; class, method, constructor, variable/field; what they mean, and how to find them in code.

    Other problems:

    The quotes you posted are not accepted by all editors compilers. Be sure to use a plain text editor or an IDE that uses the correct characters.

    You will be a victim of "integer math." Your equations will provide integer results, sometimes zero, when you might be expecting other results.
    how should it be?

  7. #7
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,290
    My Mood
    Mellow
    Thanks
    252
    Thanked 777 Times in 762 Posts

    Default Re: please help me find errors on my code,please give me reasons why i keep getting errors

    See post #3 and apply the advice given there. We won't rewrite your code for you.

  8. #8
    Junior Member
    Join Date
    May 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: please help me find errors on my code,please give me reasons why i keep getting errors

    Thanks

Similar Threads

  1. Can't find the solution to errors in code
    By ahuang1031 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 29th, 2014, 03:05 AM
  2. Cannot find symbol errors
    By UM68 in forum Object Oriented Programming
    Replies: 9
    Last Post: September 26th, 2013, 03:41 PM
  3. Program errors because it cannot find something it shouldnt be looking for
    By CrazyCrinkle in forum Object Oriented Programming
    Replies: 3
    Last Post: July 3rd, 2013, 02:11 PM
  4. Java Program Help! Cant find errors
    By frenchsasha in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 6th, 2013, 11:30 AM
  5. Cannot Find Variable/Symbol Errors... why?
    By bgroenks96 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 9th, 2011, 05:12 AM