Results 1 to 2 of 2

Thread: Debit Card

  1. #1
    dana180 is offline Member
    Join Date
    Nov 2009
    Posts
    1
    Rep Power
    0

    Default Debit Card

    Hi All,

    I am a first year University student, and as part of my course I study java programming,

    We use Blue J to compile the code.

    For my first assignment, I was given a short scenario, for a credit card processing application.

    I have managed to write the code for most part and it compiles fine and error free. However one section of the code is giving me a lot of grief. After a long research and experimentations I have now given in.

    I need some help to understand what I am doing wrong in the following code.

    The part that I am having problem with I have highlighted in blue colour


    Any help will be greatly appreciated.

    Regards
    dana180


    Here is the code:

    Java Code:
    /**
     * A DebitCard object models a Debit Card from a Bank or Building Society.
     * Details of how the card can be used are shown in the comments below.
     * There is an overdraft facility which is agreed with a new card. 
     * 
     * @author Asingh 
     * @version 1.0
     */
    public class DebitCard
    {
        private String name;  //Name of Customer
        private int number =  987654321;   //Account Number
        private int transactions; //Number of Transactions done
        private double credit;     //Amount of money available to spend
        private double agreedOverdraft;   //Overdraft limit
        private double overdraft;    //Amount of actual overdraft used
        private double deposit; //Amount deposited in the account
        private double totalSpend; //Total amount of money spent
      
    
        /**
         * Constructor to initialise a new DebitCard object with an Account name,
         * an AUTOMATIC Account number - incremented for each new object
         * and an overdraft limit. It also initialises other fields.
         */
        public DebitCard(String accntName,  double initialCredit, double initialOverdraft)
        { 
            name = accntName;
            credit = initialCredit;
            agreedOverdraft = initialOverdraft;
            overdraft = agreedOverdraft;
            deposit = 0;
            transactions = 0;
            number = number + 1;
            totalSpend = 0;
           
    
          
        }
    
        /**
         * This method returns the debit cardholder's name
         */
        public String getName()
        {
            return name;  
        }
        
        /**
         * This method returns the debit cardholder's Account Number
         */
        public int getAccountNumber()
        {
             return number;  
        }
        
        /** This method returns the Account's current credit. */
        public double getCredit()
        {
             return credit;  
        }
        
         /** This method returns the Account's current overdraft. */
        public double getOverdraft()
        {
            return agreedOverdraft;  
        } 
        
        /** Method to add a given amount  to the available credit.
         *  If the deposit is 100 or more, an extra 2% of the deposit amount 
         *  is added to the credit. Total Deposit is calculated, number of transactions 
         *  is incremented and appropriate message is printed.
         *  
         *  If overdraft have been used, it is reduced by the deposit amount. 
         *  If the deposit is greater than overdraft used, new credit and new overdraft is calculated.
         *  The deposit, available overdraft and new credit available are displayed.
         *  
         *  If the deposit is less than the overdraft used, new overdraft is calculated.
         *  The deposit, available overdraft and new credit available are displayed.
         *  
         *  If the overdraft has not been used, credit is updated.
         *  The deposit, available overdraft and new credit available are displayed.
         *  
         *  @param  amount     the amount deposited
         */
        public void deposit(double amount)
        {
            if (deposit >= 100)
            {
                deposit = deposit + 2% + credit;
                System.out.println ("#  total + transaction  #");
            }
          else if (overdraft == 0 )
            {
                overdraft -= deposit;
            }
            if (deposit > overdraft)
            {
                credit += overdraft;
            }
            else {
                System.out.println (" #  deposit + availble overdraft + credit # ");
            }
            if (deposit < overdraft)
            {
                overdraft = overdraft + deposit + credit;
            }
            if (overdraft > 0)
            {
                System.out.println("# deposit + overdraft + credit  #");
            }
                          
        }
        
        /** This method is called whenever the debit card is used to buy grocery.
         *  Card can be used unless the account does not have enough credit or remaining overdraft
         *  to cover the cost of the grocery.
         *  
         *  If the amount spent is less than or equal to the credit, the credit remaining is reduced by the amount spent,
         *  number of transactions and total amount spent are updated.Appropriate message is displayed.
         *  
         *  If the overdraft amount is used, credit, number of transactions and total amount spent are updated and
         *  appropriate message is displayed.
         *  
         *  If  the card cannot be used due to less credit or no overdraft left, a message is displayed.
         *  
         *  @param  grocerySpend    amount spent on grocery
         */
        public void buyGrocery(double grocerySpend)
        {
           totalSpend = grocerySpend;
      
      if (totalSpend <= credit)
      {
          credit = credit - totalSpend;
          System.out.println ("transaction completed..");
          System.out.println ("# transactions + credit - totalspend  #");
        }
        if (overdraft <=0)
        {
            overdraft = overdraft - credit + transactions+ totalSpend;
              System.out.println("# your transaction has been processed, current balance is#");
        }
        
       
        if (credit <= 0)
        {
          
            System.out.println("# Transaction can not be completed due to insufficent credit and no overdraft #");
        }
        if (agreedOverdraft <= 0)
        {
            System.out.println("# you do not have any overdraft left  #");
        }
        
        
          
          
            
        }
        
       [COLOR="Blue"]  /** This method is called whenever the debit card is used to pay bills.
         *  Card can be used unless the account does not have enough credit or overdraft allowed 
         *  for the cost of the bills.
         *  
         *  If the amount spent is less than or equal to the credit, the credit remaining is reduced by the amount spent,
         *  number of transactions and total amount spent are updated.Appropriate message is displayed.
         *  
         *  If the overdraft amount is used, credit, number of transactions and total amount spent are updated and
         *  appropriate message is displayed.
         *  
         *  If  the card cannot be used due to less credit or no overdraft left, a message is displayed.
         *  
         *  @param  billName    name of the bill paid
         *  @param  billAmount  amount paid for the bill
         */
       public void payBills(String billName, double billAmount)
        
        {
     
            if (totalSpend<= credit)
      {
          credit = credit - totalSpend + transactions;
          System.out.println ("transaction completed..");
          System.out.println ("# transactions + credit - totalspend  #");
        }
                
        if    (overdraft == 0)
        {
            
             credit = credit + transactions + totalSpend;
            System.out.println("# you do not have any overdraft left  #");
        }
        
        if ((credit == 0)&&(overdraft == 0))
        {   
           credit = credit - overdraft;
            System.out.println("# Transaction can not be completed due to insufficent credit and no overdraft #");
        }
    
               
        }[/COLOR]
      
    
        
        /** Method to display a report on the usage of the Debit Card, comprising:
         *      Account number
         *      current credit  
         *      the total number of transactions done
         *      the total amount of money deposited
         *      the total amount of money spent
         *      Overdraft available
         *      Overdraft used
         */
        public void showUsage()
        {
        System.out.println("###################");
         System.out.println("# Account number: #");
         System.out.println("#current credit:#");
         System.out.println("#transactions:#");
         System.out.println("#deposit:#");
         System.out.println("#totalSpend:");
         System.out.println("#agreedOverdraft #");
         System.out.println("#overdraft:#");
         
         credit = credit - totalSpend;
           
        }
        
    }
    Last edited by Fubarable; 11-08-2009 at 07:04 PM. Reason: code tags added to improve code readability

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

    Default

    Looking at your code, I have a few suggestions:

    1) Do you need both a static and a non-static accountNumber variable (with different names of course)? The static variable would allow the creation of a new unique account number for each new debit card object and would be incremented with each creation of a new DebitCard object, and the non-static variable would hold the current account number for this DebitCard object.

    2) Should getOverdraft return the overdraft, not the agreedOverdraft?

    3) This is broken:
    Java Code:
      public void deposit(double amount) {
        if (deposit >= 100) {
          deposit = deposit + 2% +credit;
          System.out.println("#  total + transaction  #");
        }
    For one it doesn't change the credit as the instructions say to do, for another, that + 2% doesn't make sense. The % character has a special meaning in Java as the modulus operator and does not calculate a percent for you. You'll have to calculate that yourself.

    4) There are many other errors, but this is all I've gotten to so far.

    Finally, please use code tags when posting code to allow your code to remain readable. I hope you don't mind that I've edited your post to add them this time around. For details, please see my signature and its link below.

    Much luck.

Similar Threads

  1. Can we access sim card from computer
    By rajasekharpv in forum Sun Java Wireless Toolkit
    Replies: 3
    Last Post: 09-03-2009, 03:22 PM
  2. Card
    By hedonist in forum New To Java
    Replies: 3
    Last Post: 08-13-2009, 02:20 PM
  3. card game Rummy
    By javafox in forum New To Java
    Replies: 4
    Last Post: 03-14-2009, 03:53 PM
  4. Card Layout
    By Gilbee in forum NetBeans
    Replies: 3
    Last Post: 03-03-2009, 09:37 PM
  5. Card program , need help thanks.
    By carlos123 in forum New To Java
    Replies: 2
    Last Post: 12-31-2007, 07:23 AM

Posting Permissions

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