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: Help for write Bank application in Java

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help for write Bank application in Java

    Hi.
    I'm a student and I need write a programe bank application in java .
    I must write a program that the customer could withdraw and deposit from his account.I wrote this program.
    but I need to use several classes for this program (object oriented). for exemple:
    BankAccount which has an instance variable amount
    and has methods:
    withDraw which takes a parameter -> amountToWithDraw
    deposit -> amountToAdd
    checkBalance -> which takes no parameters, but which returns the value in the instance variable amount.
    but i dont know how use of several classes.
    you can help me?


    import java.util.Scanner;
     
    public class BankAccount {
    public static void main(String[] args) {
     
    Scanner clapton=new Scanner(System.in);
    int x;
    float balance = 0;
    boolean quit=false;
    do {
    System.out.println("1. Deposit money");
     
    System.out.println("2. Withdraw money");
     
    System.out.println("3. Check balance");
     
    System.out.print(" 0 to quit: ");
     
    System.out.println("enter your choice :");
     
    x=clapton.nextInt();
    if (x==1) {
     
    float amount;
    System.out.println(" Amount to deposit :");
    amount=clapton.nextFloat();
    if (amount>=0) {
    balance += amount;
    }
    else {
    System.out.println("system can't reply your request");
    }
     
    }
    else if (x==2) {
    float amount;
    System.out.println(" Amount to withdraw :");
    amount =clapton.nextFloat();
    if (amount<=0 || amount > balance) {
    System.out.println("system can't reply your request ");
     
    }
    else {
    balance -= amount;
    }
    }
    else if (x==3) {
    System.out.println("your balance :" + balance );
    }
    else if (x==0) {
    quit=true;
    }
    else {
    System.out.println("wrong choice");
    }
    }
    while (!quit);
    System.out.println("bye");
    }
    }


  2. #2
    Member
    Join Date
    Feb 2012
    Posts
    58
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: Help for write Bank application in Java

    but i dont know how use of several classes.
    you can help me?
    Don't worry, hang on... To use a class from another class, create a new instance of the class using new keyword, then use dot operator on the instance to invoke methods of the class. For example:

    class A {
        void foo() {}
    }
     
    class B {
        // invoke foo() method of class A:
        public void useA() {
            A a = new A();
            a.foo();
        }
    }

Similar Threads

  1. How to write a simple automated reservation JAVA application
    By thekongss in forum Java Theory & Questions
    Replies: 3
    Last Post: November 30th, 2011, 12:31 AM
  2. Bank Application Project please help
    By mbouster in forum Paid Java Projects
    Replies: 2
    Last Post: January 5th, 2011, 06:50 AM
  3. Pls Help me run bank java application
    By chukster in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 20th, 2010, 07:28 PM
  4. [SOLVED] How to write to an application
    By straw in forum Java Theory & Questions
    Replies: 4
    Last Post: June 19th, 2010, 10:17 AM
  5. Please help - Bank account application
    By brandonssss in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 2nd, 2010, 03:10 PM