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
java. Question 3: The payment transaction scenario could be represented by the following hierarchy: Payments VISA...
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 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...
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 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 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-...
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...
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, 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...
Purpose Demonstrate the ability to create and use subclasses and inheritance. This includes overriding method behaviors and using polymorphism. Assignment Create an Aircraft class that has several properties that are common to all aircraft (Ex: number of engines, seat capacity). You define the name of the Class and the actual fields. The fields MUST BE PRIVATE!!! You must define a constructor that allows you to provide at least some of the field values used for an aircraft. You must define...
Must be in Java. Please show step by step process with proper explanation and comments. Please maintain proper indentation. CODE PROVIDED: Doctor.java HospitalDoctor.java Q1Runner.java import java.util.Scanner; public class Q1Runner { public static void main(String[] args) { Scanner kb = new Scanner(System.in); // Do your work here } } You are asked to create the starting point of a system to represent several types of medical doctors. You decided to implement two classes: a superclass...