Question

In: Computer Science

For this coding exercise, you need to create a new Java project in Eclipse and finish...

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.
    1. This method calculates the basic transaction fee by multiplying the basicFeeRate with the sum of domestic and foreign spending.
    2. 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.
    1. This method calculates the basic mileage award for the user by awarding 1 mile for every $20 spent.
    2. 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.
    1. This method calculates the transaction fee.
    2. 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.
    3. 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.
    1. This method calculates the mileage award.
    2. 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.
    3. 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.
    1. This method calculates the transaction fee.
    2. 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.
    3. 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.

  1. Method calcMileage() takes no parameters and it returns double type.
    1. This method calculates the mileage award.
    2. 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.
    3. 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*/

Solutions

Expert Solution

Please up vote ,comment if any query . Thanks for Question .Be safe .

Note : check attached image for output .

Program : *************************CreditCard.java***********************************


public class CreditCard {
    private double domesticSpending; //private variable
    private double foreignSpending;
    private double basicFeeRate;
  
    public CreditCard() //default constructor
    {
        this.domesticSpending = 0.0;
        this.foreignSpending = 0.0;
        this.basicFeeRate = 0.0;
    }
    //parameter constructor
    public CreditCard(double domesticSpending, double foreignSpending, double basicFeeRate) {
        this.domesticSpending = domesticSpending;
        this.foreignSpending = foreignSpending;
        this.basicFeeRate = basicFeeRate;
    }
    //getter and setter
    public double getDomesticSpending() {
        return domesticSpending;
    }

    public void setDomesticSpending(double domesticSpending) {
        this.domesticSpending = domesticSpending;
    }

    public double getForeignSpending() {
        return foreignSpending;
    }

    public void setForeignSpending(double foreignSpending) {
        this.foreignSpending = foreignSpending;
    }

    public double getBasicFeeRate() {
        return basicFeeRate;
    }

    public void setBasicFeeRate(double basicFeeRate) {
        this.basicFeeRate = basicFeeRate;
    }
  
    //basic fee calculation
    //foreignSpending= $50
    //domestingSpending=$100
    //basicFeeRate=2%
    //fee= (f+d)*2/100
    public double calcBasicFee()
    {
      
        double basicFee=(this.foreignSpending+this.domesticSpending)*this.basicFeeRate/100.0;
        return basicFee;
    }
  
    //mileage
    //1 mile award for every $20 spend
    public double calcBasicMileage()
    {
        return (this.foreignSpending+this.domesticSpending)/20.0;
      
    }
  
  
  
  
  
}

Program : ******************ExpressCard.java**********************


public class ExpressCard extends CreditCard{//inherit Credit Card Class
  
    private double foreignFeeRate;
    private double domesticBonusMileageRate;

    public ExpressCard() { //default constructor
        this.foreignFeeRate = 0.0;
        this.domesticBonusMileageRate = 0.0;
    }
    //parameter constructor
    //assign to local class variable
    //and credit class data
    public ExpressCard(double foreignFeeRate, double domesticBonusMileageRate, double domesticSpending, double foreignSpending, double basicFeeRate) {
        super(domesticSpending, foreignSpending, basicFeeRate);
        this.foreignFeeRate = foreignFeeRate;
        this.domesticBonusMileageRate = domesticBonusMileageRate;
    }
    //getter and setter method
    public double getForeignFeeRate() {
        return foreignFeeRate;
    }

    public void setForeignFeeRate(double foreignFeeRate) {
        this.foreignFeeRate = foreignFeeRate;
    }

    public double getDomesticBonusMileageRate() {
        return domesticBonusMileageRate;
    }

    public void setDomesticBonusMileageRate(double domesticBonusMileageRate) {
        this.domesticBonusMileageRate = domesticBonusMileageRate;
    }
  
    //% of foreignspending with foreign spending rate
    // add with calculate basic fee method of super class
    public double calcFee()
    {
       return (super.getForeignSpending()*this.foreignFeeRate/100.0)+super.calcBasicFee();
    }
    //same add basic mileage of super class
    //with domesticspending % with domestic mileage rate
  
    public double calcMileage()
    {
        return (super.getDomesticSpending()*this.domesticBonusMileageRate/100.0)+super.calcBasicMileage();
    }
  
  
}

Program : ****************************PremiumCard.java********************************


public class PremiumCard extends CreditCard{
    private double annualMemberFee;
    private double foreignBonusMileageRate;
    //default constructor
    public PremiumCard() {
        this.annualMemberFee=0;
        this.foreignBonusMileageRate=0;
    }
    //parameter constructor with credit card memeber assign
    public PremiumCard(double annualMemberFee, double foreignBonusMileageRate, double domesticSpending, double foreignSpending, double basicFeeRate) {
        super(domesticSpending, foreignSpending, basicFeeRate);
        this.annualMemberFee = annualMemberFee;
        this.foreignBonusMileageRate = foreignBonusMileageRate;
    }
   //getter and setter method
    public double getAnnualMemberFee() {
        return annualMemberFee;
    }

    public void setAnnualMemberFee(double annualMemberFee) {
        this.annualMemberFee = annualMemberFee;
    }

    public double getForeignBonusMileageRate() {
        return foreignBonusMileageRate;
    }

    public void setForeignBonusMileageRate(double foreignBonusMileageRate) {
        this.foreignBonusMileageRate = foreignBonusMileageRate;
    }
    //sum of basic fee + annual member fee
    public double calcFee()
    {
        return super.calcBasicFee()+this.annualMemberFee;
    }
    //mileage
    // basic mileage of super class + % of foreign spending with foreign spending rate
    public double calcMileage()
    {
        return super.calcBasicMileage()+(super.getForeignSpending()*this.foreignBonusMileageRate/100.0);
    }
  
  
  

  
}

Program : Main class **************************JohnDoeTest.java*****************************


public class JohnDoeTest {


    public static void main(String[] args) {
      
        //create hard code value for better understannding
        double domesticSpending=100.0;
        double foreignSpending =50.0;
        double basicFeeRate = 2.0;
      
        double foreignFeeRate=3.0;
        double domesticBonusMileageRate=4;
      
        double annualMemberFee=65.0;
        double foreignBonusMileageRate=20;
        //set value to Express Card class
        ExpressCard expressObj=new ExpressCard(foreignFeeRate,domesticBonusMileageRate,
                                               domesticSpending,foreignSpending,basicFeeRate);
        //set value of premium card class
        PremiumCard premiumObj=new PremiumCard(annualMemberFee,foreignBonusMileageRate,domesticSpending,foreignSpending,basicFeeRate);
        //print fee for express card and mileage
        System.out.printf("Express Card Fee : $%.2f\n",expressObj.calcFee());
        System.out.printf("Express Card Mileage Award :%.1f miles.\n",expressObj.calcMileage());
        //fee for premium card and mileage
        System.out.printf("Premium Card Fee : $%.2f\n",premiumObj.calcFee());
        System.out.printf("Premium Card Mileage Award : %.1f miles.\n",premiumObj.calcMileage());
      
      
    }
  
}

Output :

Please up vote ,comment if any query . Be safe .


Related Solutions

Create a new Java Project named “Packages” from within Eclipse. Following the example in the Week...
Create a new Java Project named “Packages” from within Eclipse. Following the example in the Week 6 lecture, create six packages: Main, add, subtract, multiply, divide, and modulo. ALL of these packages should be within the “src” folder in the Eclipse package Explorer. ALL of the packages should be on the same “level” in the file hierarchy. In the “Main” package, create the “Lab04.java” file and add the needed boilerplate (“Hello, World!” style) code to create the main method for...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes each in its own file Student.java, StudentList.java, and Assign5Test.java. Copy your code from Assignment 4 into the Student.java and StudentList.java Classes. Assign5Test.java should contain the main method. Modify StudentList.java to use an ArrayList instead of an array. You can find the basics of ArrayList here: https://www.w3schools.com/java/java_arraylist.asp In StudentList.java, create two new public methods: The addStudent method should have one parameter of type Student and...
Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes each in...
Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes each in its own file Student.java, StudentList.java, and Assign5Test.java. Copy your code from Assignment 4 into the Student.java and StudentList.java Classes. Assign5Test.java should contain the main method. Modify StudentList.java to use an ArrayList instead of an array. You can find the basics of ArrayList here: https://www.w3schools.com/java/java_arraylist.asp In StudentList.java, create two new public methods: The addStudent method should have one parameter of type Student and should add...
Java Coding Background You will create a Java class that simulates a water holding tank. The...
Java Coding Background You will create a Java class that simulates a water holding tank. The holding tank can hold volumes of water (measured in gallons) that range from 0 (empty) up to a maximum. If more than the maximum capacity is added to the holding tank, an overflow valve causes the excess to be dumped into the sewer system. Assignment The class will be named HoldingTank. The class attributes will consist of two int fields – current and maxCapacity....
GETTING STARTED Create an Eclipse Java project containing package “bubble”. Import the 3 starter files BubbleSorter.java,...
GETTING STARTED Create an Eclipse Java project containing package “bubble”. Import the 3 starter files BubbleSorter.java, BubbleSortTestCaseMaker.java, and Statistician.java. PART 1: Implementing BubbleSorter Implement a very simple BubbleSorter class that records how many array visits and how many swaps are performed. Look at the starter file before reading on. This class has an instance variable called “a”. Its type is int[]. This is the array that will be bubble-sorted in place. Usually a single letter is a bad variable name,...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a package named threeDimensional and put all 3 of the classes discussed below in this package Include a header comment to EACH OF your files, as indicated in your instructions. Here's a link describing the header. Note that headers are not meant to be in Javadoc format. Note that Javadoc is a huge part of your grade for this assignment. Javadoc requires that every class,...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a package named threeDimensional and put all 3 of the classes discussed below in this package Include a header comment to EACH OF your files, as indicated in your instructions. Here's a link describing the header. Note that headers are not meant to be in Javadoc format. Note that Javadoc is a huge part of your grade for this assignment. Javadoc requires that every class,...
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for...
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for the following: 1. Name the class SalonServices 2. Add private data fields: a. salonServiceDescription – This field is a String type b. price - This field is a double type 3. Create two methods that will set the field values. a. The first method setSalonServiceDescription() accepts a String parameter defined as service and assigns it to the salonServiceDescription. The method is not static b....
Using PyCharm, create a new Project lab8. Under lab8 create a new Directory exercise, then create...
Using PyCharm, create a new Project lab8. Under lab8 create a new Directory exercise, then create a Python file called nested.py, type the following: Test your code by putting the following at the bottom of the file: make_table_of_stars(2,3) (as shown in the code above). Run the file by right clicking in the code area of Pycharm, then choosing “Run nested”. Your output should be: *** *** (2 rows with 3 columns of stars). Reverse the 2 and 3. What happens?...
For this assignment, you must follow directions exactly. Create a P5 project in Eclipse then write...
For this assignment, you must follow directions exactly. Create a P5 project in Eclipse then write a class P5 with a main method, and put all of the following code into the main method: Instantiate a single Scanner object to read console input. Declare doubles for the gross salary, interest income, and capital gains. Declare an integer for the number of exemptions. Declare doubles for the total income, adjusted income, federal tax, and state tax. Print the prompt shown below...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT