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 6 of 6

Thread: How to Compute Interest

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to Compute Interest

    I am supposed to create an Interest Class that accepts values for principal, interest, years to produce outcome accumulation. I am just learning Java and using BlueJ, this is what I have so far. It compiles with no syntax errors but does not perform the function. Help?

    public class Interest {
          private  int rate;
          private int principal;
          private int years;
          private int interest;
     
        public int inputRate(int rate) {
            return rate;
        }
     
        public int inputPrincipal(int principal) {
            return principal;
        }
     
        public int inputYears(int years) {
            return years;
        }
     
        public int getInterest() {
            System.out.println("Interest is : " + interest );
            interest = rate*principal*years/100;
            {
                return interest;
            }
        }
    Last edited by jps; November 11th, 2012 at 05:00 PM. Reason: added code tags and corrected indentation


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: How to Compute Interest

    It compiles with no syntax errors but does not perform the function.
    Looks like what is posted does not compile. Perhaps a bracket was missed while copying to the forum. In either case, draw your attention to the bracket that should close the class.

    The three methods: inputRate inputPrincipal inputYears do nothing special. They take in a value and spit it right back to where it come from without modifying or saving the value. Not very useful. All three method names are not very descriptive to their purpose (once they have a purpose). The methods should accept a value and set the variables being used in the getInterest method.

    Related search terms: "Java class fields" "getters and setters" "java naming conventions"

    On the way out the door, I have never touched BlueJ, and know nothing about it (except I heard BlueJ handles the main method). There may be problems related to BlueJ specific requirements I am unaware of so take my advice knowing I know nothing about BlueJ.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to Compute Interest

    heheh, no worries, even the instructor doesn't know how to work Bluej, much less how to program in Java. He gave an assignment on something he has NEVER taught, and when I came up with the code above that didn't work he told me to google the correct way... At least now I know for a fact that my methods need more attention.Will try again and repost

  4. #4
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to Compute Interest

    i guess the simple code to execute this would be this;
    ...
    Last edited by copeg; December 4th, 2012 at 11:09 AM. Reason: removed spoonfed code

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How to Compute Interest

    @bhavesh, please read the forum rules and the following: http://www.javaprogrammingforums.com...n-feeding.html

  6. #6
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to Compute Interest

    buddy i was just trying to explain you da logic now if you are completely relied on learning java on the basis of blueJ den wish u luck, but hardly people prefers it.. Dont just learn the creamy layers of programming by these tools, understand it instead, dat will be more helpful.
    Happy coding

Similar Threads

  1. Interest calculator applet
    By bruizer in forum Java Applets
    Replies: 4
    Last Post: September 22nd, 2012, 08:38 PM
  2. Working on a code to calculate interest rates...
    By ColeTrain in forum Java Theory & Questions
    Replies: 7
    Last Post: September 20th, 2012, 06:49 AM
  3. Compute the average image value
    By IAmHere in forum Object Oriented Programming
    Replies: 3
    Last Post: January 17th, 2012, 12:07 AM
  4. investment interest display problem
    By df75douglas in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 4th, 2011, 07:32 AM
  5. Program to compute powers
    By Shyamz1 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 25th, 2010, 04:51 PM

Tags for this Thread