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

  Three or more dimensions

What kind of program, or problem, might necessitate arrays of three or more dimensions?

  Write a mips program that uses a recursive implementation

Write a MIPS program that uses a recursive implementation of quick sort to sort an array of numbers. The values of the array will be given to you via standard input. The first number will be the number of elements in the array and followed by the ..

  Explain 2 dimensional arrays in detail

The data collected is each day's service calls that come in are recorded in a file named SericeCalls.dat.

  Advantages of compilers and interpreters

Discuss the advantages and disadvantages of compilers and interpreters

  Use at least two programmer defined functions

C++ Using an input file similar to the one below, write a program to determine the highest concentration recorded and the number of days the photochemical oxidant concentration exceeded the standard; display number of days and percentage (based on th..

  The two major modifications are the instruction of pointers

the two major modifications are the instruction of pointers and the calculation of mortgage interest rates.requirements

  Requirements of flyhigh airlines

The development team of SoftSols Inc. has revamped the software according to the requirements of FlyHigh Airlines and is in the process of testing the software. While testing the software, the team encounters the following issues:

  Write a program which adjusted bill with a sales tax

Write a program which accepts the total of food and drink purchased for a restaurant bill as input. The output should be adjusted bill with a sales tax of six percent 6% and a tip (gratuity) of 15%.

  Implement a circle class

Implement a Circle class. Each object of this class will represent a circle, storing its radius and the x and y coordinates of its center as floats. Include a default constructor, access functions, an area() function, and a circumference() functio..

  Process management in an os

An Operating System could be implemented using a Ready State and Running State. Provide an argument why this is not an efficient arrangement and outline a more reasonable approach to system states and how they are interlinked for process managemen..

  Feature for entreing information about a new train

Write a program in C++ to maintain the information for a Train station regarding the arrival and departure of trains in that station. Program should have the feature for entreing information about a new train arrived or departed at any point of ti..

  Write a program that prints minimax and maximin of a matrix

The optimal strategies are possible when these two values are equal. Write a program that prints the minimax and the maximin of a given matrix.

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