Question

In: Computer Science

Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type...

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.

Solutions

Expert Solution

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!!


Related Solutions

In JAVA please... Define a class named Payment that contains an instance variable "paymentAmount" (non-static member...
In JAVA please... 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...
Define a class named Document that contains an instance variable of type String named text that...
Define a class named Document that contains an instance variable of type String named text that stores any textual content for the document. Create a method named toString that returns the text field and also include a method to set this value. Next, define a class for Email that is derived from Document and includes instance variables for the sender, recipient, and title of an email message. Implement appropriate set and get methods. The body of the email message should...
Draw UML diagram Define a class named Document that contains a member variable of type string...
Draw UML diagram Define a class named Document that contains a member variable of type string named text that stores any textual content for the document. Create a function named getText that returns the text field and a way to set this value. Next, define a class for Email that is derived from Document and that includes member variables for the sender , recipient , and title of an e-mail message. Implement appropriate accessor and mutator functions. The body of...
Define a class named Document that contains an instance variable of type String named text that stores any textual content for the document.
IN JavaDefine a class named Document that contains an instance variable of type String named text that stores any textual content for the document. Create a method named toString that returns the text field and also include a method to set this value. Next, define a class for Email that is derived from Document and includes instance variables for the sender, recipient, and title of an email message. Implement appropriate set and get methods. The body of the email message...
Define a class named Document that contains an instance variable of type String named text that stores any textual content for the document.
Code in Java Define a class named Document that contains an instance variable of type String named text that stores any textual content for the document. Create a method named toString that returns the text field and also include a method to set this value.Next, define a class for Email that is derived from Document and includes instance variables for the sender, recipient, and title of an email message. Implement appropriate set and get methods. The body of the email message...
Define a class named Document that contains an instance variable of type String named text that stores any textual content for the document.
IN JAVADefine a class named Document that contains an instance variable of type String named text that stores any textual content for the document. Create a method named toString that returns the text field and also include a method to set this value.Next, define a class for Email that is derived from Document and includes instance variables for the sender, recipient, and title of an email message. Implement appropriate set and get methods. The body of the email message should...
Define a class named Document that contains a member variable of type String named text that stores any textual content for the document.
Define a class named Document that contains a member variable of type String named text that stores any textual content for the document. Create a method named toString() that returns the text field and also include a method to set this value. Next, define a class for Email that is derived from Document and includes member variables for the sender, recipient, and title of an email message. Implement appropriate accessor and mutator methods. The body of the email message should...
Write a class named GasTank containing: An instance variable named amount of type double, initialized to...
Write a class named GasTank containing: An instance variable named amount of type double, initialized to 0. An instance variable named capacity of type double. A constructor that accepts a parameter of type double. The value of the parameter is used to initialize the value of capacity. A method named addGas that accepts a parameter of type double. The value of the amount instance variable is increased by the value of the parameter. However, if the value of amount is...
Java Implement a class MyInteger that contains: • An int data field/instance variable named value that...
Java Implement a class MyInteger that contains: • An int data field/instance variable named value that stores the int value represented by this object. • A constructor that creates a MyInteger object for a default int value. What default value did you choose? What other values did you consider? Why did you make this choice? • A constructor that creates a MyInteger object for a specified int value. • A getter method, valueOf(), that returns value. • A setter method,...
Create a Java class named Trivia that contains three instance variables, question of type String that...
Create a Java class named Trivia that contains three instance variables, question of type String that stores the question of the trivia, answer of type String that stores the answer to the question, and points of type integer that stores the points’ value between 1 and 3 based on the difficulty of the question. Also create the following methods: getQuestion( ) – it will return the question. getAnswer( ) – it will return the answer. getPoints( ) – it will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT