Okay here is the just of my assignment: Write a test program that creates an Account object with an account ID of 1122, a balance of 20000, and an annual interest rate of 4.5%. Use the withdraw method to withdraw $2500, use the deposit method to deposit $3000, and print the balance, the monthly interest, and the date when this account was created.

Here is my code:

public class Account {
  private int accountNumber;
  private double balance;
  private double annualInterestRate;
  private java.util.Date dateCreated;
  
  //Default Constructor//
  public Account() {
    this(1122, 20000, 4.5);
  }
  
  public Account(int accountNumber, double balance, double annualInterestRate){
    this.accountNumber = accountNumber;
	 this.balance = balance;
	 this.annualInterestRate = annualInterestRate;
	 dateCreated = new java.util.Date();
  }
  
  // Accesor for ID number //
  public int getAccountNumber() {
    return accountNumber;
  }
  
  // Mutator for ID number //
  public void setAccountNumber(int accountNumber) {
    this.accountNumber = accountNumber;
  }
  
  // Accesor for balance //
  public double getBalance() {
    return balance;
  }
  
  // Mutator for balance //
  public void setBalance(double balance) {
    this.balance = balance;
  }
  
  // Accesor for Annual Interest Rate //
  public double getAnnualInterestRate() {
    return annualInterestRate;
  }
  
  // Mutator for Annual Interest Rate //
  public void setAnnualInterestRate( double annualInterestRate) {
    this.annualInterestRate = annualInterestRate;
  }
  
  // Accesor for date created //
  public java.util.Date getDateCreated() {
    return dateCreated;
  }
  
  // Get the monthly interest rate //
  public double getMonthlyInterestRate() {       
    double monthlyInterestRate = annualInterestRate/12;  
	 return monthlyInterestRate;   
  }
  
  // Withdraw from account //
  public double withDraw (double ammountWithdrawn, double balance) {
    double newBalance = balance - ammountWithdrawn;
	 System.out.println("Your withdrawl has processed. New balance: " + newBalance);
	 balance = (int) newBalance;
	 return newBalance;
  }
  
  //  Deposit into account //
  public double deposit(double amountDeposited, int balance) {
    double newBalance = balance + amountDeposited;
	 System.out.println("Your deposit has processed. New Balance is: " + newBalance);
	 balance = (int) newBalance;
	 return newBalance;
  }
  
  // Main Method //
  public static void main (String[] args) {
    double withDraw = 2500;
	 double deposit = 3000;
	 System.out.println("Your balance is: " + balance);
	 System.out.println(monthlyInterestRate);
	 System.out.println(dateCreated);
  }
  }

Here is my problem:

1.It says it can't find the monthlyInterestRate symbol in the main.
2.If I delete the monthlyInterestRate print line in the main it compiles fine, but when it runs, I get:

java.lang.NoSuchMethodError: main
Exception in thread "main"
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

Any help would be appreciated.

Trey

The exception shown say it can't find main. The main method needs to have the following signature if you intend to use it to start your program

public static void main (String[] args) {

yours is

public void main (String[] args) {

I fixed the above problem and it still wont run. See anything else?

Well, what is wrong now? We can't read your mind, and I am not going to play both compiler and JVM and try to reconstruct it.

I was referring to that same problems in my first post. I am having issues invoking my other methods (withDraw, deposit, etc.) in the main. I know I am not calling them right, I just dont know how.

Instantiate your class in the main method and access those values through the reference

pulic class Bogus {
    public int x;
    public static void main (String[] args) {
        Bogus b = new Bogus();
        b.x = 5;
        System.out.println(b.x);
    }
}

Here is my new main method:

public static void main (String[] args) {
    Account account = new Account (1122, 20000, 4.5);
	 System.out.println("Monthly interest rate is " + account.getMonthlyInterestRate());
	 System.out.println("The account was created on " + account.getDateCreated());
	 
	   }
  }

I am still not sure of how to use the withDraw and deposit methods to make a deposit and withdraw. Any help?

Thanks

The same way you're using the other methods.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.