-
BanKaCCoUnt
whats wrong with this???
**methods**
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bankaccount;
public class BankAccount {
private double balance;
private int transactions;
private String id;
public BankAccount(){
}
public BankAccount(double balance, String id) {
this.balance = balance;
this.id = id;
}
public double getBalance() {
System.out.println("Your balance is " + balance);
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public String getId() {
System.out.println(id);
return id;
}
public void setId(String id) {
this.id = id;
}
public boolean deposit(double amount){
if(amount > 0){
this.balance = this.balance + amount;
this.transactions++;
return true;
}
else{
return false;
}
}
public boolean withdraw(double amount){
if(this.balance >= amount){
this.balance = this.balance - amount;
this.transactions++;
return true;
}
else{
return false;
}
}
public boolean transfer(double amount, BankAccount acc){
if(this.balance >= (amount + 5)){
this.balance -= (amount + 5);
this.transactions++;
acc.balance += amount;
acc.transactions++;
return true;
}
else{
return false;
}
}
public boolean transactionfee(double fee){
if(this.balance > (this.balance - fee * this.transactions)){
this.balance = this.balance - fee * this.transactions;
return true;
}
else{
return false;
}
}
@Override
public String toString() {
return "BankAccount{" + "balance=" + balance + ", transactions=" + transactions + ", id=" + id + '}';
}
}
****testing main???
public class BankAccount {
private double balance;
private String name;
private int transaction;
public int newfee;
public BankAccount(){
}
public BankAccount(String name, double balance) {
this.name = name;
this.balance = balance;
}
public void setName(String name) {
this.name = name;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void setTransaction(int transaction) {
this.transaction = transaction;
}
public String getName() {
return name;
}
public double getBalance() {
return balance;
}
public int getTransaction() {
return transaction;
}
public void deposit(int amount) {
if (amount >= this.balance) {
amount += this.balance;
}
transaction++;
}
public void withdraw(int amount) {
if (balance > amount) {
this.balance -= amount;
transaction++;
} else if (amount > balance) {
System.out.print("You have insufficient balance!!!!!!!");
transaction++;
}
}
public void transactionFee(double fee){
int x;
double newfee;
for(x=1;x<=transaction;x++){
newfee=newfee=(fee*x);
if (balance>=fee){
balance-=newfee;
}
else
balance=0;
}
}
public void transfer(BankAccount a , double amount){
balance -= amount;
a.setBalance(amount);
}
public String toString(){
return "Name:"+name+" Balance:"+balance+" Transaction:"+transaction;
}
}
public class TestBankAccount {
public static void main(String[] args) {
BankAccount b = new BankAccount("jerave",500);
b.deposit(500);
System.out.println(b);
b.withdraw(10000);
System.out.println(b);
b.transactionFee(1);
System.out.println(b);
}
}
-
Re: BanKaCCoUnt
Quote:
whats wrong with this???
You tell us...does it compile? Are there exceptions? Does it misbehave, and if so, what do you expect and what do you get? You can't expect us to guess, nor read that code, so please read the forum rules for instructions on how to properly format your code, as well as suggestions for how to make the most of these forums