For this coding exercise, you need to create a new Java project in Eclipse and finish all the coding in Eclipse. Run and debug your Eclipse project to make sure it works. Then you can just copy and...


For this coding exercise, you need to create a new Java project in Eclipse and finish all the coding in Eclipse. Run and debug your Eclipse project to make sure it works. Then you can just copy and paste the java source code of each file from Eclipse into the answer area of the corresponding box below.



The boxes will expand once you paste your code into them, so don’t worry about how it looks J



All data members are private and all methods are public in each class/interface in the exercise below.



Creare a class named
CreditCard, which has three private data members:


1.

domesticSpending

of double type,


2.

foreignSpending

of double type,


3. and

basicFeeRate

of double type.


Provide:


1. default constructor with no parameters,


2. constructor with three parameters to initialize its three data members, respectively.


3. getter/setter methods for each data member


There are two effector methods:


1. Method

calcBasicFee
() takes no parameters and it returns a double type.


a. This method calculates the basic transaction fee by multiplying the

basicFeeRate

with the sum of domestic and foreign spending.


b. For example, if a person has $100 and $50 in domestic and foreign spending, respectively, then under a

basicFeeRate

of 2% (0.02), the credit card company will charge 0.02 * (100+50) = $3 as the basic transaction fee.


2. Method

calcBasicMileage
() takes no parameter and it returns a double type.


a. This method calculates the basic mileage award for the user by awarding 1 mile for every $20 spent.


b. Follow the same example above, this credit card user spends $150 (domestic and foreign in total), and will receive an award of $150 / ($20 per mile) = 7.5 miles.



/** CreditCard.java */


















Code a subclass named
ExpressCard
that inherits from the superclass
CreditCard, which has two private data members:


1.

foreignFeeRate

of double type,


2. and

domesticBonusMileageRate

of double type.


Provide:


1. default constructor with no parameters,


2. constructor with all parameters to initialize its own private data and the inherited data from
CreditCard


3. getter/setter methods for each data member


There are two effector methods:


1. Method

calcFee
() takes no parameters and it returns double type.


a. This method calculates the transaction fee.


b. First you need to call the method in superclass to obtain the basic fee, and then for
ExpressCard
user, there is an extra charge for foreign spending.


c. Given the same example above as in class
CreditCard, the basic fee is $3, and under a

foreignFeeRate

of 3%, then the extra fee is calculated by multiplying $50 of foreign spending with 3% (0.03) of

foreignFeeRate
, which yields $50 *0.03 = $1.5, so the total fee is $3 + $1.5 = $4.5.



2. Method

calcMileage
() takes no parameters and it returns double type.


a. This method calculates the mileage award.


b. First you need to call the method in superclass to obtain the basic mileage, then there is a bonus mileage award for domestic spending under a rate of

domesticBonusMileageRate
.


c. Given the same example as in class
CreditCard, the basic mileage award is 7.5 miles, and if the

domesticBonusMileageRate

is 4% (0.04), then the bonus mileage is calculated by multiplying $100 of domestic spending with

domesticBonusMileageRate

0.04, which yields 4 miles. Then the total mileage award is 7.5 + 4 = 11.5 miles.


/** ExpressCard.java */

























































Code a subclass named
PremiumCard
that inherits from the superclass
CreditCard, which has two private data members:


1.

annualMemberFee

of double type,


2. and

foreignBonusMileageRate

of double type


Provide:


1. default constructor with no parameters,


2. constructor with all parameters to initialize its own private data and the inherited data from
CreditCard


3. getter/setter methods for each data member


There are two effector methods:


1. Method

calcFee
() takes no parameters and it returns double type.


a. This method calculates the transaction fee.


b. First you need to call the method in superclass to obtain the basic fee, then for
PremiumCard
user, the annual member fee must be added on top of the basic fee.


c. Given the same example above as in class
CreditCard, the basic fee is $3, and if the annual member fee is $65, then the total fee is $3 + $65 = $68.



2. Method

calcMileage
() takes no parameters and it returns double type.


a. This method calculates the mileage award.


b. First you need to call the method in superclass to obtain the basic mileage, then there is a bonus mileage award for foreign spending under a rate of

foreignBonusMileageRate
.


c. Given the same example above as in class
CreditCard, the basic mileages award is 7.5 miles, and if
foreignBonusMileageRate
is 20% (0.2), then the bonus mileage is calculated by multiplying $50 of foreign spending with

foreignBonusMileageRate

0.2, which yields 10 miles. Then the total mileage is 7.5 + 10 = 17.5 miles.


/** PremiumCard.java */
























Code a class named
JohnDoeTest
that has a main method. Replace JohnDoe with your name.



In the main method, create two objects:


1. one
ExpressCard
object,


2. and one
PremuimCard
object


When creating these two objects, you need to use the constructor that has all parameters in each class, and you need to hardcode reasonable values for the parameters needed by the constructor in each class. (There is no need to ask user to input data - so don’t include the Scanner class!).



Then in the main method, use each object created above to invoke the necessary methods, so that you can calculate each object’s
transaction fee
and
mileage award, then output the transaction fee and mileage award.



Keep 2-digit precision in the output for
transaction fee, and keep 1-digit precision in output for
mileage award.



/**
JohnDoeTest.java, and replace
JohnDoe
with your name*/
















Oct 07, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here