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 me with this code.

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Location
    Dhaka, Bangladesh
    Posts
    4
    My Mood
    Inspired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help me with this code.

    I am a beginner. This is an assignment given my class teacher. I have designed a class named Bank. Here I want to OPEN ACCOUNT, DEPOSIT MONEY, WITHDRAW MONEY and PRINT STATEMENT. My problem is in the PRINT STATEMENT method. I want to show, TIME, DATE, and last OPERATION(withdraw or deposit) and OPERATION AMOUNT. Now, I don't understand how I can get the last operation (whether it is withdraw or deposit?) and amount. Please see my code and do please help me. I have to submit it anyway, it will give me 10 marks. Do please help me.

    Thanks in advance.

    ]//************************************************************************************************************************
    // Lab Performance: 23 March 2011, Sec: C, Name: Ahamed Md. Faysal, ID: 09-14363-2, Email: [email]faysal40@gmail.com[/email], 01912120400
    //************************************************************************************************************************
     
     
    //***************************************** Class: Bank ***************************************************
    class Bank
    {
    	public String name;
    	public static int accountNumber = 1000;
    	public int balance;
     
    	Bank()
    	{
    		name = "A";
    		accountNumber = accountNumber + 1;
    		balance = 50000;
    	}
     
    	Bank(int moreThan50)
    	{
    		if(moreThan50>50000) //
    		{
    			name = "B";
    			accountNumber = accountNumber + 1;
    			balance = moreThan50;
    		}
     
    		else
    		{
    			System.out.println("Error !!! Initial depository amount must be more than 50000.");
    		}
    	}
     
     
    	//************************************ withdraw: Withdraw money from the account **************************
    	public void withdraw(int wAmount)
    	{
    		balance = balance - wAmount;
    		System.out.println(wAmount + " Taka has been successfully withdrawn.");
    	}
     
     
     
    	//************************************ dposit: Depositing money in the account ******************************
    	public void deposit(int dAmount)
    	{
    		balance = balance + dAmount;
    		System.out.println(dAmount + " Taka has been successfully deposited");
    	}
     
     
    	//********************************** checkBalance: Checking the current balance *****************************
    	public void checkBalance()
    	{
    		System.out.println("Your current balance is: " + balance);
    	}
     
     
    	//****************************************** Main Method ***************************************
    	public static void main(String args [])
    	{
    		System.out.println("\t\t\tWelcome to Touch Mangla Bank Limited\n\t\t=================================");
     
    		/*
    		//Bank a1 = new Bank();
    		//Bank a1 = new Bank(40000);
    		Bank a1 = new Bank(60000);
     
    		a1.withdraw(50000);
    		a1.checkBalance();
    		a1.deposit(120000);
    		a1.checkBalance();
    		*/
     
    		BankStatement b1 = new BankStatement(40000);
    		BankStatement b2 = new BankStatement(65000);
    		b2.checkBalance();
    		b2.deposit(450000);
    		b2.printStatement("25 March 2011", "2:00 am");
     
     
    		System.out.println();
    	}
    }
     
    //************************************* Class: BankStatement ******************************************
    class BankStatement extends Bank
    {
    	public String date;
    	public String time;
    	public String operation;
    	public int amount;
     
    	BankStatement()
    	{
    		super();
    	}
     
    	BankStatement(int mT50)
    	{
    		super(mT50);
    	}
     
     
    	//***************************** printStatement: Printing the bank statement ******************************
    	public void printStatement(String d, String t)
    	{
    		date = d;
    		time = t;
     
    		System.out.println("\t\t\tBank Statement\n_____________________________________");
    		System.out.println("Date: " + date + "\t\tTime: " + time);
    		System.out.println("Operation: " + operation + "\t\t\tAmount: " + amount);
     
    	}
    }


  2. #2
    Junior Member
    Join Date
    Mar 2011
    Posts
    17
    Thanks
    1
    Thanked 6 Times in 6 Posts

    Default Re: Help me with this code.

    Why not add another instance variable to track the previous operation, you could use booleans or strings to accomplish it