Results 1 to 5 of 5
  1. #1
    r1b
    r1b is offline Member
    Join Date
    Jan 2012
    Posts
    31
    Rep Power
    0

    Default method not working correctly

    Hi all

    can you tell me why I cant call the getmonthlyInterestRate method in this code.


    import java.util.*;

    public class Account {


    private int id;
    private String name;
    private double balance;
    private int pinNumber;
    private boolean isActive;
    Date dateCreated = new Date();
    private double annualInterestRate;


    // constructor
    public Account (int a, String b, double c) {

    int id = a;
    String name = b ;
    double balance = c ;
    int pinNumber = 1386;
    boolean isActive = false;
    Date dateCreated = new Date();
    double annualInterestRate = 4.4;

    }

    // no agr constructor
    public Account (){};



    protected void setpinNumber (int input) {
    pinNumber = input; }


    protected int getpinNumber () {
    return pinNumber;
    }


    protected boolean testpinNumber ( int entry) {

    if ( pinNumber == entry ) {
    isActive = true ;
    }
    else
    {
    System.out.println (" Please re-enter your PIN number");
    isActive = false;

    }
    return isActive;

    }


    protected int getid () {
    return id;}


    protected String getname () {
    return name;}


    protected void setBalance ( double c) {
    balance = c;}

    protected double getbalance () {
    return balance;}

    protected boolean isActive () {
    return isActive;}

    protected void deposit( double amount )
    {
    balance += amount;
    }

    public double withdraw( double amount )
    {
    // See if amount can be withdrawn
    if (balance >= amount)
    {
    balance -= amount;
    return amount;
    }
    else
    // Withdrawal not allowed
    return 0.0;
    }

    protected void setannualInterestRate( double rate) {

    annualInterestRate = rate ;
    }

    // int for the 12 months of the year

    public double m = 12;

    protected double getmonthlyInterestRate ( double pr) {


    pr = annualInterestRate / m ;

    return pr;
    }


    }

    class TestAccountClass {


    public static void main (String [] args)

    {


    // create the object

    Account test = new Account ();


    test.setannualInterestRate (6.6);

    // set balance of test


    test.setBalance (20000.00);

    // Deposit money
    test.deposit (3000.00);

    // Print current balance
    System.out.println ("Current balance " +
    test.getbalance());

    // Withdraw money
    test.withdraw(2500.00);

    // Print remaining balance
    System.out.println ("Remaining balance " +
    test.getbalance());

    System.out.println ("your current monthly interest rate is " +
    test.getmonthlyInterestRate () );



    // Print date of account creation
    System.out.println ("Your account was created on " +
    test.dateCreated.toString());

    }}

  2. #2
    eRaaaa is online now Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: method not working correctly

    protected double getmonthlyInterestRate(double pr)
    ->
    test.getmonthlyInterestRate() //the double is missing!

  3. #3
    r1b
    r1b is offline Member
    Join Date
    Jan 2012
    Posts
    31
    Rep Power
    0

    Default Re: method not working correctly

    Hi eRaaaa

    When you say the double is missing , where should I put it?

  4. #4
    eRaaaa is online now Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: method not working correctly

    Into the brackets(the method call)?

    Building a Java Application, Part I: Calling Methods

    But the parameter makes no sense in your method, so maybe you have to rewrite your method and delete the argument "double pr" !

  5. #5
    r1b
    r1b is offline Member
    Join Date
    Jan 2012
    Posts
    31
    Rep Power
    0

    Default Re: method not working correctly

    Thanks for this , my head has gone blank :)

Similar Threads

  1. Applet not working correctly?
    By Beavotropper2 in forum Java Applets
    Replies: 2
    Last Post: 04-18-2011, 06:32 AM
  2. drawString() method not working correctly
    By tnixon22 in forum New To Java
    Replies: 2
    Last Post: 02-25-2011, 08:57 PM
  3. Error Checking not working correctly
    By RickAintree in forum New To Java
    Replies: 1
    Last Post: 12-15-2010, 01:54 PM
  4. My rotate 2d pos method isnt working correctly..
    By Addez in forum New To Java
    Replies: 5
    Last Post: 12-01-2009, 09:04 AM
  5. [SOLVED] \t not working correctly?
    By Gakusei in forum New To Java
    Replies: 5
    Last Post: 05-06-2008, 04:45 PM

Posting Permissions

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