Please do this question by using Java language and do not use handwriting. Just
ID: 3788034 • Letter: P
Question
Please do this question by using Java language and do not use handwriting. Just type it after you test the code.
1. The PredatoryCreditCard class provides a processMonth() method that models the completion of a monthly cycle. Modify the class so that once a customer has made ten calls to charge during a month, each additional call to that method in the current month results in an additional $1 surcharge.
Please do this question by using Java language and do not use handwriting. Just type it after you test the code.
Explanation / Answer
import java.util.Timer;
import java.util.TimerTask;
public class PredatoryCreditCard extends TimerTask {
static int chargeval;
static int subcharge;
/* models the completion of a monthly cycle */
public void processMonth() {
System.out.println("Total Surcharge For Month is : " + subcharge); // printing subcharge after 1 month
subcharge = 0; // Month is completed , subcharge changed to 0 again
}
public void chargemade() {
chargeval++;
if (chargeval > 10) { // if charge is more than 10 , add subcharge
subcharge++;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
PredatoryCreditCard charging = new PredatoryCreditCard();
for (int i = 0; i <= 10; i++) {
charging.chargemade(); // Calling charge method 10 times to add a single subcharge
}
Timer time = new Timer(); // Instantiate Timer Object
PredatoryCreditCard monthschedule = new PredatoryCreditCard();
time.schedule(monthschedule, 0, 2592000); // Create Repetitively task for every 1 month to display subcharge
}
@Override
public void run() {
PredatoryCreditCard pcc = new PredatoryCreditCard();
pcc.processMonth();
}
}