Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Define a class named Payment that contains a member variable of type double that

ID: 3553794 • Letter: D

Question

Define a class named Payment that contains a member variable of type double that stores

the amount of the payment and appropriate accessor and mutator methods. Also create a

method named paymentDetails that outputs an English sentence to describe the amount of

the payment. Next, define a class named CashPayment that is derived from Payment. This

class should redefine the paymentDetails method to indicate that the payment is in cash.

Include appropriate constructor(s). Define a class named CreditCardPayment that is derived

from Payment. This class should contain member variables for the name on the card,

expiration date, and credit card number. Include appropriate constructor(s). Finally, redefine

the paymentDetails method to include all credit card information in the printout. Create a

main method that creates at least two CashPayment and two CreditCardPayment objects

with different values and calls paymentDetails for each.

ANSWER HINT******

/**

* This program introduces inheritance through a problem of

* creating two types of Payments, Cash and Credit. The

* paymentDetails method outputs in English a sentence that describes

* the payment.

*/

/**

* Base class that holds payment amount provides a method for returning

* a description of the payment.

*/

public class Payment

{

//Payment amount

private double amount;

//Constructor to initialize amount to 0

public Payment()

{

amount = 0.0;

}

/**

* Constructor to initialize payment amount

*/

public Payment(double paymentAmount)

{


/**Must be your own original code. No copy and paste from internet. Easy to locate copied code. Also, must have java comments, state below (1). Points rewarded once ALL requirements are met. Thanks. **/


1. Comments within your code. Please look up how to do JavaDoc style comments if you don't know how. Using Eclipse IDE, you can have Eclipse create the comments sections for you automatically. This is critical in going forth in your future classes. You should have method documentations as well as inline documentations. Example:

Explanation / Answer

The Class: public class BankAccount { // the attributes private String accountNumber; private String accountName; private double balance; // the methods // the constructor public BankAccount(String numberIn, String nameIn) { accountNumber = numberIn; accountName = nameIn; balance = 0; } // methods to read the attributes public String getAccountName() { return accountName; } public String getAccountNumber() { return accountNumber; } public double getBalance() { return balance; } // methods to deposit and withdraw money public void deposit(double amountIn) { balance = balance + amountIn; } public boolean withdraw(double amountIn) { if(amountIn > balance) { return false; } else { balance = balance - amountIn; return true; } } } The Code for main class : import java.util.*; public class Bank { public static void main(String[] args) { BankAccount[] accountList = new BankAccount[2]; accountList[0] = new BankAccount ("120568", "John Bishop"); accountList[1] = new BankAccount ("120786", "Peter Cambridge"); System.out.println("Please Enter the account number that you wish to deposite money: "); Scanner sc = new Scanner(System.in); String accountNum = sc.next(); boolean IsAccount = false; for (int i = 0; i < 2; i++) { if(accountNum.equals(accountList[i].getAccountNumber())) { double amount; do { System.out.println("Please Enter the amount that you want to deposit or Type '0' to quit: "); amount = sc.nextDouble(); accountList[i].deposit(amount); } while (amount != 0); System.out.println(accountList[i].getAccountNumber()); System.out.println(accountList[i].getAccountName()); System.out.println(accountList[i].getBalance()); IsAccount = true; } } if (!IsAccount) { System.out.println("There is no such an account!"); } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote