Answer to Question #269488 in Java | JSP | JSF for Candy

Question #269488

Write a Java program that creates an Account object with an account ID of 1122, a balance of $20,000, and an annual interest rate of 4.5%. Use the withdraw method to withdraw $2,500, use the deposit method to deposit $3,000, and print the balance, the monthly interest, and the date when this account was created.

Demonstration and Viva will be carried out in week 13 during your respective seminar session.

You will be assessed on the working of the code as well as on your ability to explain the code.


1
Expert's answer
2021-11-22T09:54:42-0500


public class Main
{
	public static void main(String[] args) {
		Account a=new Account(1122,20000,4.5);
		a.withdraw(2500);
		a.deposit(3000);
		
		System.out.println("Balance: "+a.getBalance());
		System.out.println("Monthly Interest: "+(a.getInterestrate()/12)*a.getBalance());
		System.out.println("Date created: "+a.getdate());
	}
}


class Account{
    private float balance;
    private int accountID;
    private double anual_interest_rate;
    private String date="22/11/2021";
    
    public Account(float b, int id, double rate){
        balance=b;
        accountID=id;
        anual_interest_rate=rate;
    }
    
    public String getdate(){
        return date;
    }
    public double getInterestrate(){
        return anual_interest_rate;
    }
    public float getBalance(){
        return balance;
    }
    public void withdraw(int amount){
        balance =balance-amount;
    }
    public void deposit(int amount){
        balance=balance+amount;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS