In: Computer Science
Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type double that stores the amount of the payment and appropriate accessor (getPaymentAmount() ) and mutator methods. Also create a method named paymentDetails that outputs an English sentence to describe the amount of the payment. Override toString() method to call the paymentDetails() method to print the contents of payment amount and any other details not included in paymentDetails().
Define a class named CashPayment that is derived from Payment. This class will have an additional instance variable of type String (a non-static member variable) that specifies a type of currency, such as "dollar", "euro", "peso", "yen", etc. This class should override the paymentDetails method to indicate that the payment is in cash, and the type of currency used. Include appropriate constructor(s) and accessor/mutator methods for all instance variablesand. Override toString() with contents of cash payment details (should still call paymentDetails()).
Hello folks, i need some JAVA help here.
Define a class named CreditCardPayment that is derived from Payment. This class should contain instance variables (member variables) for the name on the card, expiration date, and credit card number. Include appropriate constructor(s) and accessor/mutator methods for all instance variables. Finally, redefine thepaymentDetails method to include all credit card information in the printout. Override toString() method with contents of credit payment details (should still call paymentDetails()).
Create a main method within Payment that creates at least two CashPayment and two CreditCardPayment objects with different values and payment amounts. Call toString() methods from each object to print the details of each payment.
Hi,
Please Find the code according to the given requirements:
*****************************************************
Payment.java
*****************************************************
public class Payment {
private double paymentAmount;
public Payment() {
}
/**
* @param paymentAmount
*/
public Payment(double paymentAmount) {
this.paymentAmount =
paymentAmount;
}
/**
* @return the paymentAmount
*/
public double getPaymentAmount() {
return paymentAmount;
}
/**
* @param paymentAmount the paymentAmount to set
*/
public void setPaymentAmount(double paymentAmount)
{
this.paymentAmount =
paymentAmount;
}
/**
* @return String that specifies the amount of the
payment
*/
public String paymentDetails() {
return "The Amount of Payement is
"+paymentAmount;
}
@Override
public String toString() {
// TODO Auto-generated method
stub
return this.paymentDetails();
}
public static void main(String[] args) {
//CashPayment Object 1
CashPayment cashPayment = new
CashPayment();
cashPayment.setPaymentAmount(100);
cashPayment.setCurrency("dollars");
//CashPayment Object 2
CashPayment cashPayment2 = new
CashPayment(175, "Euro(s)");
//CreditCard Payment Object 1
CreditCardPayment creditCardPayment
= new CreditCardPayment();
creditCardPayment.setCardNumber(123456781010L);
creditCardPayment.setExpiryMonth(5);
creditCardPayment.setExpiryYear(22);
creditCardPayment.setNameOnCard("John");
creditCardPayment.setPaymentAmount(250);
//CreditCard Payemrnt Object
2
CreditCardPayment
creditCardPayment2 = new CreditCardPayment(75, "Edward", 2, 24,
567432167854L);
System.out.println(cashPayment);
System.out.println("******************************");
System.out.println(cashPayment2);
System.out.println("******************************");
System.out.println(creditCardPayment);
System.out.println("******************************");
System.out.println(creditCardPayment2);
}
}
*****************************************************
CashPayment.java
*****************************************************
package cash;
public class CashPayment extends Payment {
private String currency;
public CashPayment() {
super();
}
/**
* @param paymentAmount
* @param currency
*/
public CashPayment(double paymentAmount, String
currency) {
super(paymentAmount);
this.currency = currency;
}
/**
* @return the currency
*/
public String getCurrency() {
return currency;
}
/**
* @param currency the currency to set
*/
public void setCurrency(String currency) {
this.currency = currency;
}
/**
* @return String that specifies the amount of the
payment in currency
*/
@Override
public String paymentDetails() {
// TODO Auto-generated method
stub
return "The Amount of Payement is
"+getPaymentAmount()+" "+currency;
}
@Override
public String toString() {
// TODO Auto-generated method
stub
return this.paymentDetails();
}
}
*****************************************************
CreditCardPayment.java
*****************************************************
public class CreditCardPayment extends Payment{
private String nameOnCard;
private int expiryMonth;
private int expiryYear;
private long cardNumber;
public CreditCardPayment() {
super();
}
/**
* @param paymentAmount
* @param nameOnCard
* @param expiryMonth
* @param expiryDate
* @param cardNumber
*/
public CreditCardPayment(double paymentAmount, String
nameOnCard, int expiryMonth, int expiryYear,
long cardNumber)
{
super(paymentAmount);
this.nameOnCard = nameOnCard;
this.expiryMonth =
expiryMonth;
this.expiryYear = expiryYear;
this.cardNumber = cardNumber;
}
/**
* @return the nameOnCard
*/
public String getNameOnCard() {
return nameOnCard;
}
/**
* @param nameOnCard the nameOnCard to set
*/
public void setNameOnCard(String nameOnCard) {
this.nameOnCard = nameOnCard;
}
/**
* @return the expiryMonth
*/
public int getExpiryMonth() {
return expiryMonth;
}
/**
* @param expiryMonth the expiryMonth to set
*/
public void setExpiryMonth(int expiryMonth) {
this.expiryMonth =
expiryMonth;
}
/**
* @return the expiryDate
*/
public int getExpiryYear() {
return expiryYear;
}
/**
* @param expiryDate the expiryDate to set
*/
public void setExpiryYear(int expiryYear) {
this.expiryYear = expiryYear;
}
/**
* @return the cardNumber
*/
public long getCardNumber() {
return cardNumber;
}
/**
* @param cardNumber the cardNumber to set
*/
public void setCardNumber(long cardNumber) {
this.cardNumber = cardNumber;
}
@Override
public String paymentDetails() {
// TODO Auto-generated method
stub
return "Name on Card :
"+nameOnCard+"\nCard Number : "+cardNumber+"\nExpiry Date of card :
"+expiryMonth+"/"+expiryYear
+"\nThe Amount of Payement is :
$"+getPaymentAmount();
}
@Override
public String toString() {
// TODO Auto-generated method
stub
return this.paymentDetails();
}
}
Output Screenshot:

Thanks!!