The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Java interface question
The payment transaction scenario could be represented by the following hierarchy:
Payment
VISA Master
Debit
Create interface class Payments with one abstract method called paymentInfo.
· Create classes VISA, MASTER, DEBIT that implement Payments.
· For each of the three classes (VISA, MASTER, DEBIT), create one constructor, one instant variable amount, and get balance method.
· Constructors are used to create objects with initial balance.
· The interface class method “paymentInfo” should be overridden in the three classes (VISA, MASTER, DEBIT) to display the initial amount of each object.
· paymentInfo method is used to display information on the screen about the current amount.
· You test method should looks like:
public class Demo {
public static void main(String args[]) {
/* Create two objects using constructor */
Payments visaPymts = new VISA(100);
Payments masterPymts = new MASTER(200);
Payments debitPymts = new DEBIT(400);
// Invoking a method for each object created
visaPymts.paymentInfo ();
masterPymts.paymentInfo ();
debitPymts.paymentInfo ();
double totalAmount = visaPymts.getAmount() + visaPymts.getAmount() + visaPymts.getAmount();
System,out.println(“The total amount you paid is” + totalAmount);
}
}
· The output of the program will be like the following:
You paid $100.00 using your VISA card
You paid $200.00 using your MASTER card
You paid $400.00 using your DEBIT card.
The total amount you paid is $700
Attachments: