Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: BanKaCCoUnt

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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);

    }

    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: BanKaCCoUnt

    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

Similar Threads

  1. Threads in BankAccount program
    By ben-der in forum What's Wrong With My Code?
    Replies: 22
    Last Post: March 15th, 2012, 10:19 AM
  2. BankAccount assignment problem
    By ddonn in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 6th, 2011, 01:04 PM