A mock payment interface is set up in the system which is to deploy onto production, many invoices go via payment interfaces. There are also various modes of payments namely Cards, Wallet and Online Banking.

Since there are many malware identified in many of the accounts, any account number that contains 555 in it are not processed and are given failure statuses.

Can you please process the invoices that are through payment interfaces using multi-threading for faster payment checkouts.

When an invoice is made through payment interfaces, based on the mode of payment – Card or Online Banking or Wallet a thread to corresponding to each payment mode should be started, put on to sleep for a few sec and then process the payments.

Note:

1 thread should use Thread class and the other 2 threads should use Runnable Interface.

Create a class named CreditCardPayment extends Thread class with the following private attributes

Long invoiceNumber

String cardNumber

Double amount

Include appropriate getters and setters.

Include default and parameterized constructor with following order (invoiceNumber, cardNumber, amount).

And also include the following override method

No Method Name Method Description

1 public void run() Override the run method, and process the card payment. Before processing payments put the thread in sleep for 200m

Create a class named OnlineBankingPayment implements the Runnable interface with the following private attributes

Long invoiceNumber

String accountNumber

Double amount

Include appropriate getters and setters.

Include default and parameterized constructor with following order (invoiceNumber, accountNumber, amount).

And also include the following override methods.

No Method Name Method Description

1 public void run() Override the run method, and process the card payment. Before processing payments put the thread in sleep for 200ms

Create a class named WalletPayment implements the Runnable interface with the following private attributes

Long invoiceNumber

String mobileNumber

Double amount

Include appropriate getters and setters, Include default and parameterized constructor with following order (invoiceNumber, mobileNumber, amount). And also include the following override methods

No Method Name Method Description

1 public void run() Override the run method, and process the wallet payment. Before processing payments put the thread in sleep for 20

Create the class named as Main, which contains main method read n, the number of payments and the payment details. Span a thread for each payment mode and process the payment in the corresponding thread. Finally print the payment process to the console in the main method.

Sample Solution

This question has been answered.

Get Answer