Write the following codes on Netbeans IDE 81 1 Write a java

Write the following codes on Netbeans IDE 8.1

1. Write a java program that creates 3 bank account objects. Each object contains the name of the account owner, the account number, and the current balance. For example, my first account object would be created as follows:bankAccount = new bankAccount(\"John Doe\", 1200, 350.00). Then, allow each account owner to enter a deposit. Then, calculate the interest in each account after the deposit. Decide on your own the interest rate. Then allow each account owner to withdraw some money from the account after the interest is applied. Then print out the account balance for each of the three users after the withdrawal.

2. Find and correct the errors in the following code and make sure it works properly.

public class Test{

public static method1(int n, m) {

n += m;

method2(3.4);

}

public static int method2(int n) {

if (n > 0) return 1;

else if (n == 0) return 0;

else if (n < 0) return –1;

}

}

Solution

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chegg;

public class BankAccount {
private String owner;
private int number;
private double balance;
private static double interestRate = 0.1; //10%
  
public BankAccount(String owner,int number,double balance)
{
this.owner = owner;
this.balance = balance;
this.number = number;
}
  
public void deposit(double amount)
{
this.balance = this.balance+amount;
}
  
public void applyInterest()
{
this.balance = this.balance+interestRate*balance;
}
  
public void withdraw(double amount)
{
this.balance = this.balance-amount;
}
  
public double accBalance()
{
return this.balance;
}
  
public String toString()
{
return this.owner + \" has a balance of \" + this.balance;
}

public static void main(String[] args)
{
BankAccount b1 = new BankAccount(\"John Doe\", 1200, 350.00);
BankAccount b2 = new BankAccount(\"John1\", 1201, 350.00);
BankAccount b3 = new BankAccount(\"John2\", 1202, 350.00);

b1.deposit(100);
b2.deposit(200);
b3.deposit(300);

b1.applyInterest();
b2.applyInterest();
b3.applyInterest();

b1.withdraw(100);
b2.withdraw(200);
b3.withdraw(300);

System.out.println(b1);
System.out.println(b2);
System.out.println(b3);
}
  
}

public static method1(int n, int m) {
n += m;
method2((int) 3.4);
}
  
public static int method2(int n) {
if (n > 0)
return 1;
else if (n == 0)
return 0;
return -1;
}

Write the following codes on Netbeans IDE 8.1 1. Write a java program that creates 3 bank account objects. Each object contains the name of the account owner, t
Write the following codes on Netbeans IDE 8.1 1. Write a java program that creates 3 bank account objects. Each object contains the name of the account owner, t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site