Define a class named payment that contains a member variable

Assignment Help C/C++ Programming
Reference no: EM13939815

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.

CodeMate Hints
/**
* 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)
{
amount = paymentAmount;
}
/**
* Sets the payment amount
*/
public void setPayment(double paymentAmount)
{
amount = paymentAmount;
}
/**
* Returns the payment amount
*/
public double getPayment()
{
return amount;
}
/**
* Prints a description of the payment
*/
public void paymentDetails()
{
System.out.println("The payment amount is " + amount);
}
public static void main(String[] args)
{
// Create several test classes and invoke the paymentDetails method
Payment cash1 = new CashPayment(50.5);
Payment cash2 = new CashPayment(20.45);
Payment credit1 =
new CreditCardPayment(10.5, "Fred", "10/5/2010", "123456789");
Payment credit2 =
new CreditCardPayment(100, "Barney", "11/15/2009", "987654321");
System.out.println("Cash 1 details:");
cash1.paymentDetails();
System.out.println();
System.out.println("Cash 2 details:");
cash2.paymentDetails();
System.out.println();
System.out.println("Credit 1 details:");
credit1.paymentDetails();
System.out.println();
System.out.println("Credit 2 details:");
credit2.paymentDetails();
System.out.println();
}
}

Reference no: EM13939815

Questions Cloud

What will price be immediately after next dividend payment : The C. Alice Stone Company's common stock has paid a $3 dividend for so long that investors are now convinced that stock will continue to pay that annual dividend forever. If the next dividend is due in one year and investors require 8% return on the..
Treasury inflation-indexed bond at par value : Your purchase a U.S. Treasury inflation-indexed bond at par value of $1,000. The bond offers a coupon rate of 6% paid semi annually. During the first six months that you hold the bond, prices in the United Stees rise by 2%. What is the new par value ..
Products corporation makes two products : Determine the unit cost of each product according to the ABC system. (Do not round intermediate calculations. Round your answers to 2 decimal places. Omit the "tiny_mce_markerquot; sign in your response.)
Maintains a debt-equity ratio : Merlo, Inc. maintains a debt-equity ratio of 0.25 and follows a residual dividend policy. The company has after-tax earnings of $3,800 for the year and needs $3,200 for new investments. What is the total amount Merlo will pay out in dividends this ye..
Define a class named payment that contains a member variable : 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 eac..
Fill in following data tables to help generate hypothesis : A hypothesis is an educated guess. Based on what you have learned and written about in the Introduction, state what you expect to be the results of the lab procedures.
Was the british pound selling at a discount or premium : What was the 90-day forward premium (or discount)?  Was the British pound selling at a discount or premium in the forward market?
Calculate a firms cost of equity : Consider one of the two equations that can be used to calculate a firm's cost of equity: rE=Div1/P0+g. If the expected growth rate of American Airlines common stock dividends increases and if the price of AAL's stock also increases, what happens to A..
Transaction costs and taxes : The price of ABC stock is currently $42 per share, but in six months you expect it to rise to $50. ABC does not pay a dividend. You buy a six-month call on ABC, with a strike price of $45. The option cost $200. What holding period return do you expec..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  What is stored in beta after each of the following statement

What is stored in beta after each of the following statements executes?

  Write a function that returns a number

Write a test program that prompts the user to enter a phone number as a string. The input number may contain letters. The program translates a letter (upper- or lowercase) to a digit and leaves all other characters intact

  The main program should create an ifstream

For decryption, the main program should create an ifstream for the file to be decrypted. It should use the getline method of the ifstream to read lines from the file, call the encryption / decryption function with the line to be decrypted, and dis..

  Savingsaccount objects and two checkingaccount objects

Develop a polymorphic banking application using the Account hierarchy you created. Create the following two SavingsAccount objects and two CheckingAccount objects and store them in an array called "arrays" of Account references to the objects

  Determine the manner in which each of the provided concepts

Provide a short code example of the use of C++ syntax within the context of an employee database and determine the manner in which each of the provided concepts relates to the concept of object-oriented programming.

  Which manufactures electrical switches

Jake Company, which manufactures electrical switches, uses a standard cost system and carries all inventories at standard. The standard manufacturing overhead costs per switch are based on direct labor hours and are shown below:Variable overhead (5 h..

  Determine the size of the square

1. An open box is to be made from a square piece of cardboard whose sides are 17 in long, by cutting squares of equal sizes from the corners and bending up the sides. Determine the size of the square that is to be cut out so that the volume may be ma..

  Write an interactive program that prompts for a desired sum

Write an interactive program that prompts for a desired sum, then repeatedly rolls two six-sided dice until their sum is the desired sum. Here is the expected dialogue with the user.

  Create a program that counts the number of numbers

you need to create a program that counts the number of numbers between 150 and 200 - Can you write this program in c language? You need to implement a function that counts the numbers.

  Online shopping order and computes and outputs

Write a program that allows the user to input a total dollar amount for an online shopping order and computes and outputs the shipping cost based on the following schedule:

  Calculates the student * averages and quiz averages based

Calculates the student * averages and quiz averages based upon input from the user. Modify this program to read in the following grade text file, * with a maximum number of students set to 35 and having five quiz scores for each student. The output s..

  Generates numbers in the fibonacci sequence

Write a class called fibs that generates numbers in the Fibonacci sequence (each number is the sum of the previous two). The sequence starts 1, 1, 2, 3, 5, ...

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd