Link to home
Start Free TrialLog in
Avatar of basgen
basgen

asked on

enhance the funtionality of a credit-card program

You are required to take an existing program for managing a credit card and to enhance the functionality of
the program.  
• README – a text file describing these files
• CardInterface.java – the interface to be used for the credit card classes
• CreditCard.java – an initial implementation of CardInterface
• Calendar.java – a skeleton to be used for the Calendar class (see below)
• Test.java – a test program for the CreditCard class
• Test.out – the expected output from the Test program
• AuditedTest.out – the expected output from the AuditedTest program (see below)


1. Compile and run the Test.java program and make sure its output corresponds with the file Test.out.

Under Unix you can redirect the output to a temporary file using the command java Test > tmp
and then check for differences using the command diff tmp Test.out.

2. Write a Java class called Calendar which fills in the skeleton provided in the file Calendar.java. In
other words, it has a static Date method called getDate() to return the current date, and a static void
method called tock(int days) to advance the date by the specified number of days. This means that the
class will need to have a static variable of type Date (initialised to the 1st January 2005),
(Note that you are asked to use the class java.util.Date which the compiler will flag as deprecated. This
means that the class should not be used for production software because it is not guaranteed to be
retained in later revisions of Java. The specific problem is that the class Date is not amenable to
internationalization. Therefore, other Calendar classes have been introduced. Unfortunately, the
generalization embodied in these Calendar classes makes them excessively complex for the purposes of
this simple assignment, and hence the advice to use the class Date.)

3. Write a Java class called Transaction (in a file called Transaction.java), which records the information
about a credit card transaction, i.e. the date, the kind of transaction (which is one of the strings “new”,
“credit”, “debit” or “fee”), and the amount.

4. Write a Java class called AuditedCard (in a file called AuditedCard.java), which extends the class
CreditCard so that it still implements the same interface, but now records the transactions performed on
the card. (Note that creating a card and making a charge or a payment are all considered to be
transactions, but getting the balance is not.) You should use a Java ArrayList or a Vector to record the
transactions. The method void print( ) should now print all the transactions for the card in addition to
the account details and current balance.

5. Write a Java class called AuditedTest (in a file called AuditedTest.java), which is the same as Test
except that it creates instances of class AuditedCard rather than CreditCard, and advances the calendar
by 7 days after every transaction (on every card), and prints the transactions for each card following all
the payments. The proposed output is given in file AuditedTest.out. (Note that the format for the date
is obtained using the toString method for class Date.)

6. You should also develop your own test programs for class AuditedCard. You should use the same
naming convention as above, i.e. xyzTest.java for the test program xyzTest.out for the expected output.
These files should be documented in the README file.

Note that this assignment should not employ a graphical user interface – the program should perform all
input/output through the console window (i.e. use System.in and System.out). You need to use the naming conventions which have been specified, including the file names and interfaces.

cardinterface.java
public interface CardInterface {
 
  // Accessor methods
  public String getNumber();
  public String getName();
  public String getBank();
  public double getBalance();
  public int getLimit();
 
  // Action methods
  public boolean chargeIt(double price);
  public void makePayment(double payment);
  public void print();
}


test.java : public class Test {
  public static void main(String[] args) {
    CardInterface wallet[] = new CardInterface[10];
    wallet[0] = new CreditCard("5391 0375 9387 5309", "John Bowman",
                             "California Savings", 0.0, 2500);
    wallet[1] = new CreditCard("3485 0399 3395 1954", "John Bowman",
                             "California Federal", 0.0, 3500);
    wallet[2] = new CreditCard("6011 4902 3294 2994", "John Bowman",
                             "California Finance", 0.0, 5000);
    for (int i=1; i<=16; i++) {
      wallet[0].chargeIt((double) i);
      wallet[1].chargeIt(2.0 * i);            // implicit cast
      wallet[2].chargeIt((double) 3 * i);      // explicit cast
    }
    System.out.println("Card payments:");
    for (int i=0; i<3; i++) {
      wallet[i].print();
      while (wallet[i].getBalance() > 100.0) {
        wallet[i].makePayment(100.0);
      }
      wallet[i].print();
      System.out.println();
    }
  }
}
 test.out
Card payments:
Number = 5391 0375 9387 5309
Name = John Bowman
Bank = California Savings
Balance = 136.0
Limit = 2500
Number = 5391 0375 9387 5309
Name = John Bowman
Bank = California Savings
Balance = 36.0
Limit = 2500

Number = 3485 0399 3395 1954
Name = John Bowman
Bank = California Federal
Balance = 272.0
Limit = 3500
Number = 3485 0399 3395 1954
Name = John Bowman
Bank = California Federal
Balance = 72.0
Limit = 3500

Number = 6011 4902 3294 2994
Name = John Bowman
Bank = California Finance
Balance = 408.0
Limit = 5000
Number = 6011 4902 3294 2994
Name = John Bowman
Bank = California Finance
Balance = 8.0
Limit = 5000

calandar.java
public class Calendar {
  private static Date today;
  public static Date getDate() {
    return today;
   
   
   
    static{date1 = 01012005();    
    for(int cnt = 0; cnt < var2; cnt++){      var3 += var1;
       } //end for loop    
       System.out.println("End first static init: "                                   ());  
       } //end first static initializer block
      
  }
  public static void tock(int days) {
  }
}

creditcard.java
public class CreditCard implements CardInterface {
 
  // Instance variables;
  private String number;
  private String name;
  private String bank;
  protected double balance;
  private int limit;
 
  // Constructor
  CreditCard(String no, String nm, String bk, double bal, int lim) {
    number = no;
    name = nm;
    bank = bk;
    balance = bal;
    limit = lim;
  }
 
  // Accessor methods
  public String getNumber()      { return number; }
  public String getName()      { return name; }
  public String getBank()      { return bank; }
  public double getBalance()       { return balance; }
  public int getLimit()       { return limit; }
 
  // Action methods
  public boolean chargeIt(double price) {       // Make a charge
    if (price + balance > (double) limit)
      return false;      // Not enough money left to charge it
    balance += price;
    return true;      // The charge is accepted
  }
  public void makePayment(double payment) {      // Make a payment
    balance -= payment;
  }
  public void print() {                        // Print a card's info
    System.out.println("Number = " + getNumber());
    System.out.println("Name = " + getName());
    System.out.println("Bank = " + getBank());
    System.out.println("Balance = " + getBalance());
    System.out.println("Limit = " + getLimit());
  }
}
   
auditedtest.out
public class CreditCard implements CardInterface {
 
  // Instance variables;
  private String number;
  private String name;
  private String bank;
  protected double balance;
  private int limit;
 
  // Constructor
  CreditCard(String no, String nm, String bk, double bal, int lim) {
    number = no;
    name = nm;
    bank = bk;
    balance = bal;
    limit = lim;
  }
 
  // Accessor methods
  public String getNumber()      { return number; }
  public String getName()      { return name; }
  public String getBank()      { return bank; }
  public double getBalance()       { return balance; }
  public int getLimit()       { return limit; }
 
  // Action methods
  public boolean chargeIt(double price) {       // Make a charge
    if (price + balance > (double) limit)
      return false;      // Not enough money left to charge it
    balance += price;
    return true;      // The charge is accepted
  }
  public void makePayment(double payment) {      // Make a payment
    balance -= payment;
  }
  public void print() {                        // Print a card's info
    System.out.println("Number = " + getNumber());
    System.out.println("Name = " + getName());
    System.out.println("Bank = " + getBank());
    System.out.println("Balance = " + getBalance());
    System.out.println("Limit = " + getLimit());
  }
}
   

Avatar of Krule
Krule
Flag of Canada image

This looks like homework, is it?
That is so homework.
Avatar of basgen
basgen

ASKER

need help in this part... java class called Transaction (in a file called Transaction.java), which records the information
about a credit card transaction, i.e. the date, the kind of transaction (which is one of the strings “new”,
“credit”, “debit” or “fee”), and the amount.....would appreciate some guidance...
ASKER CERTIFIED SOLUTION
Avatar of Mayank S
Mayank S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of basgen

ASKER

oke i will thanks....however what i need to know how to begin is the crediting and debiting of the card? but thanks for your comments.
Avatar of basgen

ASKER

guys...i need alittle help on this.....6. You should also develop your own test programs for class AuditedCard. You should use the same
naming convention as above, i.e. xyzTest.java for the test program xyzTest.out for the expected output.
These files should be documented in the README file.

 anyone cld show me how to write a test prog for this...im not very sure. thanks fellas.
Avatar of basgen

ASKER

one more thing guys.....i managed to come out with this for transaction.java...no sure with the condition part....wld appreciate the knowledge in that...many thanks.
public class Transaction {

  private String recordTrans ;
  private String accountNumber1 ;
  private String accountNumber2 ;
  private double amt ;
  private Calendar date ;
  private String type ;

      Calendar date;
      private Object rec;
      
      public Transaction(){
      
      }
      
      public addRecord(String type, double amt){
                        
I AM STUCK HERE!!!!
            
            recordTrans = date.getDate() + " " + transType + " " + amount;            
            date.tock(7);
            return recrecordTrans;
      }
}
Could you ask this in a new question since this one is already closed? I'm a little occupied right now with work and won't be able to do EE for a few days, I guess.