Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Create a JavaTransactionAccount class, so that one may store a name, an ID, a

ID: 3858214 • Letter: 1

Question

1. Create a JavaTransactionAccount class, so that one may store a name, an ID, account balance, and a list of transactions. Please maximize code re-use and extend your class from a Java class you have learned from this semester. Then add additional information if some of them are not available from the super class. 2. Add a new instance field (called credit score) for each account. Add new methods to process this field as needed. 3. Implement a "Measurable" interface in your Java class so that we can find out the total # of transactions of each account. 4. Add codes in your java class to implement and override the .toString() method so that it returns the name, id, account balance and the total # of transactions. You do not need to include the detail listing of transactions in your .toString() output.

Explanation / Answer

import java.util.*;
import java.lang.*;
import java.io.*;
interface Measureable
{
    public int totalTransaction();
}
class JavaTransactionAccount implements Measureable
{
String name;
int id;
float balance;
ArrayList al=new ArrayList();
public int totalTransaction()//Implementing intTransaction method present in Interface
{
    return al.size();//returns the total no. of transactions
}
void updateBalance()
{
Iterator it=al.iterator();
//updating the balance based on transaction history
while(it.hasNext())
{
Integer I=(Integer)it.next();
balance=balance+I;
}
}
}
class MyClass extends JavaTransactionAccount
{
int creditScore;
void setValues(String n,int id,int cs)
{
    super.name=n;
    super.id=id;
    this.creditScore=cs;
}
public String toString()//Overriding toString method present in Object Class
{
    return "Name: "+name+" Id: "+id+" Balance: "+balance+" Total No.of transactions: "+totalTransaction();
}
public static void main (String[] args) throws java.lang.Exception
{
    MyClass ob=new MyClass();
    ob.setValues("John",1234556,24);
    //Adding the Transaction values in ArrayList
ob.al.add(+5000);//'+' sign indicates that money is deposited
ob.al.add(-2500);// '-' sign indicates that money has been withdrawn
ob.al.add(+3000);
ob.al.add(+4000);
ob.al.add(-3500);
ob.updateBalance();
System.out.println(ob);
}
}

Sample Output: