Question

Question 3: The payment transaction scenario could be represented by the following hierarchy: Payments VISA MASTERCARD Paypal

java.


In Question 3, each subclass should extend the superclass Payments and also implement the interface Payments Interface. The i
0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any problem with the code feel free to comment.

Program

interface PaymentsInterface{//interface
  
   public double paymentInfo();
}

//super class
class Payments implements PaymentsInterface{

   //no information was given about this class
  
   @Override
   public double paymentInfo() {
       return 0;
   }
  
}

//visa class
class Visa extends Payments{
   private double money;

   public Visa(double money) {
       this.money = money;
   }

   public double getMoney() {
       return money;
   }

   public void setMoney(double money) {
       this.money = money;
   }

   @Override
   public double paymentInfo() {
       //performing the calculation
       double cad=money*1.35;
       double fee = cad * 0.02;
       return cad - fee;
   }
}

//Master Card class
class MasterCard extends Payments{
   private double money;

   public MasterCard(double money) {
       this.money = money;
   }

   public double getMoney() {
       return money;
   }

   public void setMoney(double money) {
       this.money = money;
   }

   @Override
   public double paymentInfo() {
       double cad = money*1.35;
       double fee = cad * 0.025;
       return cad - fee;
   }
}

//Paypal class
class Paypal extends Payments{
   private double money;

   public Paypal(double money) {
       this.money = money;
   }

   public double getMoney() {
       return money;
   }

   public void setMoney(double money) {
       this.money = money;
   }

   @Override
   public double paymentInfo() {
       double cad = money*1.35;
       double fee = cad * 0.01;
       return cad - fee;
   }
}

public class Test{//driver class for testing
   public static void main(String[] args) {
       //creating objects
       Payments visa = new Visa(100);
       Payments ms = new MasterCard(100);
       Payments paypal = new Paypal(100);
      
       //showing info
       System.out.println("100 Dollar convert into CAD: ");
       System.out.println("Visa: "+visa.paymentInfo());
       System.out.println("Master Card: "+ms.paymentInfo());
       System.out.println("Paypal: "+paypal.paymentInfo());
      
       //showing total CAD
       System.out.println();
       double total = visa.paymentInfo()+ms.paymentInfo()+paypal.paymentInfo();
       System.out.printf("Total CAD: %.3f",total);
      
   }
}

Output

<terminated> Test (1) Java Application] C:Program FilesJavajre1.8.0_211\bin\javaw.exe (28-Nov-2019, 2:54:18 pm) 100 Dollar co

Add a comment
Know the answer?
Add Answer to:
java. Question 3: The payment transaction scenario could be represented by the following hierarchy: Payments VISA...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Lab In this lab, you will be implementing the following class hierarchy. Your concrete classes...

    Java Lab In this lab, you will be implementing the following class hierarchy. Your concrete classes must call the superclass constructor with the proper number of sides (which is constant for each concrete shape). The perimeter method is implemented in the superclass as it does not change based on the number of sides. The area method must be overridden in each subclass as the area is dependent on the type of polygon. The areas of an equilateral triangle, square, and...

  • JAVA - Abstraction and Encapsulation are one pillar of OOP (Object Oriented Programming). Another is inheritance...

    JAVA - Abstraction and Encapsulation are one pillar of OOP (Object Oriented Programming). Another is inheritance and polymorphism. In this assignment we will use inheritance and polymorphism to solve a problem. Part (a) of the figure below shows a symbolic representation of an electric circuit called an amplifier. The input to the amplifier is the voltage vi and the output is the voltage vo. The output of an amplifier is proportional to the input. The constant of proportionality is called...

  • 1. Write a class to represent a AlternativeEnergyCar. Select the fields and methods that fit the...

    1. Write a class to represent a AlternativeEnergyCar. Select the fields and methods that fit the modeling of an alternative energy car. Make sure to include code for the constructors, set/get methods, a toString() method. 2. Inheritance – : For this question submit a UML as the answer. Create two abstract subclasses of AECar, one for Electric cars and one for Altfuel cars. Next create four additional subclasses., two for types of Electric cars and two for Altfuel cars( for...

  • Please help me with the following question. This is for Java programming. In this assignment you...

    Please help me with the following question. This is for Java programming. In this assignment you are going to demonstrate the uses of inheritance and polymorphism. You will create an Animals class and a Zoo class that holds all the animals. You should create a general Animalclass where all other classes are derived from (except for the Zoo class). You should then create general classes such as Mammal, Reptile, and whatever else you choose based off of the Animalclass. For...

  • ********************Java Assigment******************************* 1. The following interface and classes have to do with the storage of information...

    ********************Java Assigment******************************* 1. The following interface and classes have to do with the storage of information that may appear on a mailing label. Design and implement each of the described classes below. public interface AddrLabelInterface { String getAttnName(); String getTitle(); // Mr., Mrs., etc. String getName(); String getNameSuffix(); // e.g., Jr., III String getProfessionalSuffix(); // O.D. (doctor of optometry) String getStreet(); String getSuiteNum(); String getCity(); String getState(); String getZipCode(); } Step 1 Create an abstract AddrLabel class that implements the...

  • Java Question 3 Implement a program to store the applicant's information for a visa office. You...

    Java Question 3 Implement a program to store the applicant's information for a visa office. You need to implement the following: A super class called Applicant, which has the following instance variables: A variable to store first name of type String. A variable to store last name of type String. A variable to store date of birth, should be implemented as another class to store day, month and year. A variable to store number of years working of type integer...

  • Java I need help Q1: Suppose this is a legal assignment statement: Student obj1 = new...

    Java I need help Q1: Suppose this is a legal assignment statement: Student obj1 = new Book(); what is the relationship between Student and Book?    1 - Student has Book as a field    2 - Student is a subtype of Book    3 - No Relationship    4 - Book is a subtype of Student. Question2: Q2: What are the types involved in this statement: Vehicle v1 = new Car();    1- Car    2- new    3-...

  • Please help me with the following question. This is for Java programming. In this assignment you are going to demonstrate the uses of inheritance and polymorphism. You will create an Animals class and...

    Please help me with the following question. This is for Java programming. In this assignment you are going to demonstrate the uses of inheritance and polymorphism. You will create an Animals class and a Zoo class that holds all the animals. You should create a general Animalclass where all other classes are derived from (except for the Zoo class). You should then create general classes such as Mammal, Reptile, and whatever else you choose based off of the Animalclass. For...

  • ONLY NEED THE DRIVER CLASS PLEASE!!! Domain & Comparator Classes: 0.) Design a hierarchy of classes,...

    ONLY NEED THE DRIVER CLASS PLEASE!!! Domain & Comparator Classes: 0.) Design a hierarchy of classes, where the Media superclass has the artistName and the mediaName as the common attributes. Create a subclass called CDMedia that has the additional arrayList of String objects containing the songs per album. Create another subclass called DVDMedia that has the additional year the movie came out, and an arrayList of co-stars for the movie. 1.) The superclass Media will implement Comparable, and will define...

  • ****Please read the following requirements and use java language w/ comments**** ****Can make this a multi...

    ****Please read the following requirements and use java language w/ comments**** ****Can make this a multi part question if needed**** Project requires a base class, a derived subclass, and an interactive driver (class with a main) that allows the user to utilize and manipulate the classes created. You may select one super class from the following:               Superclass                                    Example subclasses Ship class                                a) battleship, tugboat, icebreaker Person class                           b) manager, salaryworker, hourlyworker Aircraft class                         c) Learjet, cargoplane,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT