Results 1 to 7 of 7
  1. #1
    Hamodi18 Guest

    Default Fast Help Plz ..

    hi everyone ....
    I have two classes ,, Customer class is done ,, but the problem is with Account class im not be able to include
    +setOwner(newOwner: Customer): void
    +getOwner(): Customer
    +setAccountNo(newAccNo: int): void
    +getAccountNo(): int

    and after puting those things I have to Edit the Bank class ... I hope somebody can help me ..

    The Question:

    You are required to declare the classes below:

    ------------------------------------------------------
    Account:
    ------------------------------------------------------
    -owner: Customer
    -accountNo: int
    -balance: double
    ------------------------------------------------------
    +Account()
    +setOwner(newOwner: Customer): void
    +getOwner(): Customer
    +setAccountNo(newAccNo: int): void
    +getAccountNo(): int
    +setBalance(newBal:double): void
    +getBalance(): double
    +deposit(amt:double):boolean
    +withdraw(amt:double):boolean
    ------------------------------------------------------



    ----------------------------------------------------
    Customer:
    ----------------------------------------------------
    -name: String
    -icNo: String
    ----------------------------------------------------
    +Customer ()
    +setName(newName: String): void
    +getName(): String
    +setIC(newIC:String):void
    +getIC():String
    ----------------------------------------------------


    The following are the requirements needed:
    1. Deposit method:
    a. Do a checking on the amount given. Perform the update on current balance only if the amount is greater than zero. Return true if deposit is successful and false otherwise.
    2. Withdraw method:
    a. Do a checking on the amount given. Deduct from current balance only if the amount is less than the balance and the balance after deduction should not be less than RM10.00. Return true if withdrawal is successful and false otherwise.

    Then create a Bank class that will instantiate an object of type Account and Customer. Request the user to enter the information for the newly created Customer object and Account object.

    Your Bank class then should allow the following options:

    1 – Deposit
    2 – Withdraw
    3 – Check Balance
    0 – Exit

    These options should be displayed repeatedly until the user enters 0. Once option 0 is chosen, display a “Thank you” message and terminate from the application.

    The solution :
    Java Code:
    public class Account {
    
            Customer owner;
            int accountNo;
            double balance;
    
            public Account(Customer _owner){
                setOwner(_owner);
            }
            public void setOwner(Customer _c){
                owner = _c;
            }
            public void setBalance(double newBal){
                balance = newBal;
            }
            public double getBalance(){
                return balance;
            }
            public boolean deposit(double amt){
                boolean result = true;
                if(amt > 0)
                    balance += amt;
                else
                    result = false;
                
                return result;
            }
            public boolean withdraw(double amt){
                boolean result = true;
                if((amt < balance)&&((balance - amt) >= 10.00))
                    balance -= amt;
                else
                    result = false;
                
                return result;   
            }
     }
    Java Code:
    public class Customer {
    	String name;
    	String icNo;
    	
    	public Customer (){
    		
    	}
    	public void setName(String newName){
    		name = newName;
    	}
    	public String getName(){
    		return name;
    	}
    	public void setIC(String newIC){
    		icNo = newIC;
    	}
    	public String getIC(){
    		return icNo;
    	}
    
    }
    Java Code:
    import java.util.Scanner;
    
    public class Bank {
    	static Account _account;
    	static Customer _customer;
    	private static Scanner scan = new Scanner (System.in);
    	
    	static void initData(){
    		// the customer object
    		System.out.print("Enter the Customer name : ");
    		String name = scan.nextLine();
    		System.out.printf("Enter the icNo of %s : ",name);
    		String icNo = scan.nextLine();
    		_customer = new Customer();
    		_customer.setName(name);
    		_customer.setIC(icNo);
    		
    		// the Account object
    		System.out.format("Enter the initial balance of %s's account : ",_customer.getName());
    		double balance = Double.parseDouble(scan.nextLine());
    		_account = new Account(_customer);
    		_account.setBalance(balance);
    	}
    	public static void Menu(){
    		
    		System.out.println("1 – Deposit.");
    		System.out.println("2 – Withdraw.");
    		System.out.println("3 – Check Balance.");
    		System.out.println("0 – Exit.");
    		
    		System.out.print("Your choice : ");
    		
    	}
    	
    	public static void main(String[] args){
    		
    		int choice;
    		double _amt;
    		System.out.println("$$---------------- Banking System -------------------$$");
    		// create the Account & customer Objects
    		initData();
    		do {
    			// Show Menu
    			Menu();
    			// read input
    			choice = Integer.parseInt(scan.nextLine());
    			switch(choice){
    			case 1:
    				System.out.print("deposit >> Enter the amount : ");
    				_amt = Double.parseDouble(scan.nextLine());
    				if(_account.deposit(_amt))
    					System.out.println("Succes !");
    				else
    					System.out.println("Failure !");
    				break;
    			case 2:
    				System.out.print("withdraw >> Enter the amount : ");
    				_amt = Double.parseDouble(scan.nextLine());
    				if(_account.withdraw(_amt))
    					System.out.println("Succes !");
    				else
    					System.out.println("Failure !");
    				break;
    			case 3:
    				System.out.printf("The current balance of %s's account is : %.2f.\n",_customer.getName() ,_account.getBalance());
    				break;
    			case 0:
    				System.out.println("Thank you !");
    				break;
    			}
    		}while(choice != 0);
    	}
    
    }

  2. #2
    Hamodi18 Guest

    Default

    hmm I need the answer now guys ..

  3. #3
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Quote Originally Posted by Hamodi18 View Post
    hmm I need the answer now guys ..
    Cripes, you're bumping this less than one hour after posting it! Sorry, but your time management issues are not our emergencies.

    Next time, actually study the material and start on your assignment earlier.
    Last edited by curmudgeon; 07-16-2010 at 04:33 AM.

  4. #4
    Hamodi18 Guest

    Default

    Quote Originally Posted by curmudgeon View Post
    Cripes, you're bumping this less than one hour after posting it! Sorry, but your time management issues are not our emergencies.
    im not saying I need the answer ,, just something wont take 5 mint from the professional java ...

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Hamodi, I remember you from the other day. I think that your cheating yourself asking this question without showing us your attempts first and telling us specifically what is confusing you. If all you do is thrown in the towel and ask others to do your work for you, you will never understand programming. Please show some effort.

  6. #6
    Hamodi18 Guest

    Default

    hmm Guys well .. F*** u all of u .. U not useful all of useless you dont have the manners about to replay to others ... F*** off
    Last edited by Fubarable; 07-16-2010 at 05:23 AM. Reason: obscenities removed

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. how fast?
    By abdullahansari in forum New To Java
    Replies: 4
    Last Post: 06-30-2010, 03:17 AM
  2. Extremely fast applet
    By FerretSpy440 in forum Java Applets
    Replies: 0
    Last Post: 07-17-2009, 04:12 AM
  3. Help me fast!
    By Manikyr in forum New To Java
    Replies: 4
    Last Post: 03-16-2009, 07:43 AM
  4. HELP FAST!!----Interest Calculator
    By Coop33 in forum New To Java
    Replies: 8
    Last Post: 10-15-2008, 01:44 PM
  5. pls help me fast!
    By rexson98 in forum New To Java
    Replies: 10
    Last Post: 10-15-2008, 12:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •