Define a class named payment that contains an instance

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

1. Define a class named Payment that contains an instance 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 derived from Payment. This class should contain instance 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 payment Details for each.


2.  Create a class called Vehicle that has the manufacturer's name (type String), number of cylinders in the engine (type int), and owner (type Person given below). Then, create a class called Truck that is derived from Vehicle and has the following additional properties:
the load capacity in tons (type double since it may contain fractional part) and towing capacity in RM (type int). Be sure your class has a reasonable complement of constructors, accessor and mutator methods, and suitably defined equals and toString methods. Write a program to test all your methods.

The definition of the class Person is below. Completing the definitions of the methods is part of this exercise.

public class Person
{
private String name;
public Person()
{...}
public Person (String theName)
{...}
public String getName()
{...}
public void setName (String theName)
{...}
public String toString()
{...}
public Boolean equals(Object other)
{...}


}

3.  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 filed 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 appropriateaccessor and mutator methods. The body of the email message should be stored in the inherited variable text. Redefine thetoString method to concatenate all text field.

Similarly, define a class for File that is derived from Document and includes a instance variable for the pathname. The textual contents of the file should be stored in the inherited variable text. Redefine the toString method to concatenate all text field.

Finally, create several sample objects of type Email and File in your main method. Test you objects by passing them to the following subroutine that returns true if the object contains the specified keyword in the text property.

public static Boolean ContainKeyword (Document docObject, String keyword)
{
if (docObject.toString().indexOf(keyword, 0) >= 0)
return true;
return false;
}

4.  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:
Desired dice sum: 9
4 and 3 = 7
3 and 5 = 8
5 and 6 = 11
1 and 5 = 6
6 and 3 = 9

Finish the following code file:

importjava.util.*;


public class TestDiceRoll {


public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.print("Desired dice sum: ");
int sum = console.nextInt();


// your code here
}
}

Reference no: EM13333453

Questions Cloud

Calculate the new angular speed of the student : A student sits on a rotating stool holding two 3.6-kg objects. When his arms are extended horizontally, Find the new angular speed of the student
Define a class named creditcardpayment : Create a main method that creates at least two CashPayment and two CreditCardPayment objects with different values and calls payment Details for each.
Consulting the attorney of record : 1. Is it in violation of the Canons of Ethics for an attorney being a member of a district attorney's staff to attempt to elicit a confession or statement from a defendant charged with the criminal offense without consulting the attorney of recor..
What is the frequency of the piano wire : A piano tuner hears 2.0 beats per second between his 440 Hz tuning fork and a piano wire that has a lower pitch sound
Define a class named payment that contains an instance : Define a class named Payment that contains an instance variable of type double that stores the amount of the payment and appropriate accessor and mutator methods.
A violation of the canons of ethics for a lawyer : 1. Is it a violation of the Canons of Ethics for a lawyer to try a civil case on a contingent fee basis in a court in which his father is the judge?
Find at what rate is electrical energy transferred to heat : A 109 V potential difference is applied to a space heater whose resistance is 12 when hot. At what rate is electrical energy transferred to heat
Determine what is the transfer to retained earnings : ABC recently reported $34,893 of sales, $6,422 of operating costs other than depreciation, and $2,145 of depreciation. The company had $4,440 of bonds that carry a 7% interest rate, and its income tax rate was 39%.
Determine who do qualify to purchase the property : You want to purchase a home for $239,950 and have saved enough for a 20 percent down payment. The mortgage interest rate is 5.25 percent with for a 30 year loan with monthly payments.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Creates a bus class

write a program that creates a bus class. create a constructor that initializes the number of passengers and number of seats. declare four objects. use the default copy constructor to initialize two of the objects.

  Write test program to call function several times for gcd

Greatest common divisor of two integers is largest integer which will evenly divide both integers. Implement this function in assembly language and write test program which calls function several times, passing it different values.

  Write a program that uses 3 input files and 3 output files

write a program that uses 3 input files and 3 output files.

  Design a class box that defines a box on a floor

Design a class box that defines a box on a floor. A box has a number and an (a,b) location where a and b are numbers between -5, and 5.

  Define two derived classes of the abstract class

Define two derived classes of the abstract class ShapeBase below. Your two classes will be called RightArrow and LeftArrow. These classes will draw arrows that point right and left,

  Menu with options to enter student information

Create a program that uses a menu with options to enter student information (name, ID, GPA), print student information, or quit the program. Use data files and FILE pointers to store and print information entered.

  Create a serial object s

The function call operator is overloaded and will generate a sequential integer each time the operator is used and the object can be created with the sequence start value specified.

  C program to solve the quadratic equation of rocket launch

Write a C program to solve the quadratic equation of rocket launch by computing the roots (t1 and t2) of that quadratic equation: gt2 + vt + l = 0 (or) for simplicity ax2 + bx + c = 0. Get the values of g, v, and l from the user. The program should d..

  Displays columns titled "name", "quantity", "price", value

Write a program that displays columns titled "Name", "Quantity", "Price", and "Value". The fourth column contains the result of multiplying each item's quantity by its price. In addition, the program should calculate and display the total value of th..

  Prepare a businesspartner

Prepare a BusinessPartner class that contains a company name, first name and a telephone number.

  Your city''s parking violation

Your city's Parking Violation Bureau wants you to write a program to compute fines for parking violations.

  Computer programming using c language lab

Computer programming using c language lab

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