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

  Pros and cons of choosing two servers

Classify the two alternatives in terms of what type of application architecture they use. b. Outline the pros and cons of the two alternatives and make a recommendation to Fred about which is better.

  The process function will then need

The process function will then need to find the time the person waited by calling the time function and finding the difference between the start and end timestamps. Save this time to an accumulator so that in the end you can find the average wait tim..

  Implement the readlog function

Implement the readLog function below, which is to (1) read the file, (2) populate a vector for each column, and (3) return the number of lines found.

  We wish to process survey results

Suppose we wish to process survey results that are stored in a file. This exercise requires twoseparate programs. First, create a program that prompts the user for survey responses and outputseach response to a file

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Calculates the average of three test scores

Write a program that calculates the average of three test scores. The program should contain three value-returning functions: main, getTestScore, and calcAverage

  Analyze the time complexity and space complexity

Develop a simple prototype version of algorithm in C++. Specifically, you will build an in-place, order reversal algorithm - analyze the time complexity and space complexity of your algorithm

  Create a program that draws a two-dimensional house

Create a program that draws a two-dimensional house seen from the front, the way a child would see it: with a door, two windows, and a roof with a chimney

  A robot can take steps of 1 meter

A robot can take steps of 1 meter, 2 meters, or 3 meters. Write a recursive function to calculate the number of ways the robot can walk n meters. (n is an integer obtained from user.) As example:

  Counts the number of numbers between 150 and 200

create a program that counts the number of numbers between 150 and 200. This is what I have so far, but it's not working. It is an array of 500 number, I did not include the array because of obvious reasons.

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Design and implement a class called cheetah

Create a method that calculates the time required to travel between the starting point and stopping point of the line based on a given speed.

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