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

JAVA LANGUAGE Create a new project named BankAccount in Eclipse. Then, implement the following requirements. You...
JAVA LANGUAGE Create a new project named BankAccount in Eclipse. Then, implement the following requirements. You need to create two classes, one for BankAccount (BankAccount.java) and the other for the tester (BankAccountTest.java). Make sure your program compile without errors before submitting. Submit .java files to eCampus by the end of next Thursday, 10/15/2020. Part 1: Create the BankAccount class (template is attached after the project description) in the project. You must add the following to the BankAccount class: An instance...
In Java: 1) Create a new eclipse project. 2) Create a basic SWING window 3) Create...
In Java: 1) Create a new eclipse project. 2) Create a basic SWING window 3) Create a Label Called Name 4) Create a Text Field for entering the name 5) Create a Text Field for entering and email 5) Create a text area to push the results to 6) Create two buttons, one that says submit and the other that says clear. 7) When the user enters their name and email, they should press submit and see the Text area...
open up a new Java project on Eclipse named Review and create a new class called...
open up a new Java project on Eclipse named Review and create a new class called Review.java. Copy and paste the below starter code into your file: /** * @author * @author * CIS 36B */ //write your two import statements here public class Review {        public static void main(String[] args) { //don't forget IOException         File infile = new File("scores.txt");         //declare scores array         //Use a for or while loop to read in...
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...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign4. Create 3 Java Classes...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign4. Create 3 Java Classes each in its own file Student.java, StudentList.java, and Assign4Test.java. Copy your code from Assignment 3 into the Student.java and StudentList.java. Assign4Test.java should contain the main method. In Student.java, add a new private variable of type Integer called graduationYear. In Student.java, create a new public setter method setGraduationYear to set the graduationYear. The method will have one parameter of type Integer. The method will set...
Using eclipse IDE, create a java project and call it applets. Create a package and call...
Using eclipse IDE, create a java project and call it applets. Create a package and call it multimedia. Download an image and save it in package folder. In the package, create a java applet where you load the image. Use the drawImage() method to display the image, scaled to different sizes. Create animation in Java using the image. In the same package folder, download a sound. Include the sound in your applets and make it repeated while the applet executes....
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...
Pre-Assignment hom Before you start, create a new Eclipse project and create one package in that...
Pre-Assignment hom Before you start, create a new Eclipse project and create one package in that project. The package should be called “HW3” Problem 1 Create a class called “Person”. This class should have, at minimum, the following members and methods. I advise you to add others as you see fit. // Members firstName (string) lastName (string) age (int) pAddress (Address)  // This is composition! I suggest using the Address class we defined earlier! pDOB (Date)  // This is composition!  I suggest using...
OOPDA in java project. in eclipse Instructions: Create a class called Person with the properties listed:...
OOPDA in java project. in eclipse Instructions: Create a class called Person with the properties listed: int id, String firstName, String middleName, String lastName, String email, String ssn, int age. The Person class should have getters and setters for all properties other than id. (You may use Eclipse to help you auto-generate these.) Person class should also have a getter for id Create a no-arg constructor for Person In addition to these getters and setters, Person should have the following...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT