Answered You can buy a ready-made answer or pick a professional tutor to order an original one.
Project 2 Credit Card Solution
Project 2 Credit Card Solution
Learning ObjectivesAfter completing this project, you should be able to: write compile and run a simple Java class write expressions using variables write methods to meet specific requirements explain the differences between local variables, instance variables and method parameters write conditional statements with Boolean expressionsProject SummaryCreate a class, called CreditCard, which simulates the functionality of a credit card such as Visa or Mastercard. You can do simple things like make purchases, take cash advances and make payments. Important information about your card: Annual Percentage Rate (APR) for previous month balance is 15.9% Cash advance APR is 25.9% effective on the day of advance and until the end of the month (assume all months have 30 days but the year has 365 days) Each balance transfer has a fee of $5 or 3% of the transfer, whichever is greater Required minimum payment is 1.5% of balance or $25, whichever is greater Due date is the 20th of the month Late payment fee is $37 – if at least a minimum payment is not made within grace period (20 days) Minimum Interest – if you are charged interest, the minimum amount will be $0.50 There is no annual feeUser InteractionYou do not use a Scanner in this project for user interaction. Instead, the cardholder interacts with the Credit Card by invoking methods within BlueJ.Instance Variables (5 pts)A class should contain several instance variables (section 3.1). Some instance members are not expected to change after given an initial value. It is good practice to define these as final and useALL CAPS for the names (section 7.1). Provide appropriate names and data types for each of the private instance variables: a String for the card holder name doubles for the previous balance, purchases, balance transfers and new balance doubles for the fees, interest and cash advances an integer for the number of purchases in the current month a final double for the balance APR (15.9%) a final int for the due date (20) a final double for the late payment fee (37.0) a final double for the minimum interest amount (0.5) a final double for the cash advance APR (25.9%),private final double ADVANCE_APR = 25.9/100; you might identify the need for other final members as wellConstructors (5 pts)A constructor is a special method with the same name as the class and generally initializes the fields to appropriate starting values. Refer to sections 3.7 and 3.8. public CreditCard (String name) – assigns the cardholder name and otherinstance variables are set to zero. public CreditCard (String name, double amt) - alternative constructorassigns the cardholder name and previous monthly balance to amt. Other instance variables are set to zero.Accessor Methods (5 pts)An accessor method does not modify class fields. The names for these methods, which simplyreturn the current value of a field, often begin with the prefix ‘get’. Refer to section 3.6. public double getPreviousBalance( ) - return the previous balance. public double getFees( ) – return the fees public double getInterest( ) – return the interest public double getPurchases( ) – return the purchases public double getBalanceTransfers( ) – return the balance transfers public double getCashAdvances( ) – return the cash advances public int getNumPurchases( ) – return the number of purchases public String getName( ) – return the card holder nameMutator Methods (20 pts)A mutator method performs tasks that may modify class fields. Refer to section 3.6. public void applyCredit (double amt) – Reduce the purchases by amt.Display an appropriate message (see sample output below). public void balanceTransfer (double amt) – Customer adds to hertransfer balance total for this month. This amount must be paid back and gets moved tothe total amount due at the end of the month. Update the transfer balance and fees. The fee is either $5 or 3% of amt (whichever is greater). Display an appropriate message. public void purchase (double amt) – Update the purchase balance andincrement the number of purchases. Display an appropriate message. public void cashAdvance (double amt, int day) – Update the cashadvance balance and interest. Parameter day represents the day the advance was made. Interest is calculated by applying the cash advance APR for the number of days until the end of the month (assume 30 days for a month but 365 days for the year). For example, if day=10 then there are twenty-one remaining days in the month. Minimum interest is $0.50. Display an appropriate message.Private Helper Methods (15 pts)Designated as private, a helper method is used by other methods within the class. Good practice is to make methods private unless they need to be public. Refer to section 3.6. private double calcMinimumPayment ( ) – calculate and return theminimum payment which is either $25 or 1.5% of the new balance calculated at the end of the month (whichever is greater). Note, this private method is invoked from within printStatement(). private void resetAmounts ( ) – Update previous balance to the newbalance. Reset all other instance variables to zero. Note, this private method is invoked from within closeBillingPeriod(). private void printStatement ( ) - display the monthly statement. Seesample output for how the statement should appear. Invoke calcMinimumPayment() to avoid duplicate code. Note, this private method is invoked from within closeBillingPeriod().Additional Mutator Methods (10 pts)These methods invoke one or more of the private helper methods to keep it short and concise. public void makePayment (double amt, int day) – Reduce theprevious balance by amt. Parameter day represents the day of the month payment was submitted. Apply a penalty fee of $37 if amt is not at least the required minimum payment or is paid later than the 20th of the month. Invoke calcMinimumPayment() rather than duplicating the code. Display an appropriate message. public void closeBillingPeriod () – Calculate interest on the previousbalance, if any, by applying the balance APR. Calculate the new balance due by adding interest, transfer, purchases, cash advances, fees and the previous balance. Display the current statement by invoking the helper method printStatement(). Reset all instance variables as necessary by invoking the helper method resetAmounts().Preventing Customer Errors (10 pts)The following should only be attempted after all other requirements described above have been completed. The credit card class is now functional but it is possible the cardholder will make various errors. Make improvements to the following methods that you already wrote. Your goal is to prevent common customer mistakes by ignoring parameters with negative values. No action should be taken if the amt is negative or if day is not between 1 and 30. balanceTransfer (double amt) applyCredit (double amt) purchaase (double amt) cashAdvance (double amt, int day) makePayment (double amt, int day)Currency Format (10 pts)The following should only be attempted after all other requirements have been completed. You will note that the monetary amounts display with extra decimal places and no dollar sign. Use the NumberFormat class (described below) to display all monetary figuresin currency format. Define an instance variable and use it throughout the code to format currency values private NumberFormat fmt = NumberFormat.getCurrencyInstance();Number FormatThe NumberFormat class can be used to display currency numbers as text/strings. It is not explained in the book but you can find more information in the Java API. The following example may be enough for you.Code fragment outputNumberFormat fmt = NumberFormat.getCurrencyInstance();double amount = 3.0111111;System.out.println("Cost: " + fmt.format(amount)); Cost: $3.01Coding Style (10 pts)Good programming practice includes writing elegant source code for the human reader. Follow the GVSU Java Style Guide.Sample MessagesThe following sample messages, printed while interacting with BlueJ, are provided as examples.Your messages should be similar.Make purchase of 184.95Purchase Amount: $184.95Cash advance of (1000, 13)Cash Advance on Day 13: $1,000.00Cash advance with illegal day (1000, -1)Request cancelled: provide a day 1 - 30Balance transfer of 300Transfer: $300.00Make purchase of -5Request cancelled: provide a positive amountApply credit of 45.5Credit: $45.50Close Billing PeriodPrevious Balance: $0.001 Purchase(s): $139.45Advances: $1,000.00Transfers: $300.00Fees: $9.00Interest: $12.77New Balance: $1,461.22Minimum Payment: $25.00Make payment of (500, 10)Payment on Day 10: $500.00Software Testing (10 pts)Software developers must carefully test their code. BlueJ allows you to instantiate objects and then invoke individual methods to manipulate the fields (instance variables) within the object. You can carefully check each method and compare actual results with expected results. However, this gets tedious and cannot be automated.Testing Your Class using a main() methodAnother approach is to write a main method, called a test harness, that instantiates an object and then calls methods in a carefully designed sequence. Refer to section 4.12.For this project, write a main method in a new class called CardTest that instantiates a credit card and invokes each of the methods with a variety of parameter values. Provide multiple if statements to test each method along with error messages as needed. It takes careful consideration to test every possibility.This is a brief and incomplete example. Your test harness should be much longer with 10-15if statements.public static void main(String arg[]){CreditCard brenda = new CreditCard("Brenda Stern");int errors = 0;// multiple purchasesbrenda.purchase(100);brenda.purchase(2.35);if(brenda.getPurchases() != 102.35){System.out.println(" ERROR! with purchase");errors++;}// negative purchasebrenda.purchase(-10);if(brenda.getPurchases() != 102.35){System.out.println(" ERROR! with negative purchase");errors++;}System.out.println(errors + " errors detected");
- @
- 331 orders completed
- ANSWER
-
Tutor has posted answer for $40.00. See answer's preview
******* * Credit **** SolutionLearning ObjectivesAfter ********** this project you should ** **** ****** ***** ******* *** *** a simple **** ******** ***** *********** ***** variables ***** methods ** **** ******** *************** ******* *** differences ******* ***** ********* instance ********* *** method ************* write *********** ********** **** ******* ****************** ************* * ***** ****** ********** ***** ********* *** functionality ** a ****** card such ** ****** ********** *** *** ** ****** ****** **** **** ********* **** **** ******** *** ************ Important information about your ******** ****** ********** **** ***** *** ******** ***** balance is 159% Cash advance *** is **** effective ** the *** ** advance *** until *** *** ** ******** ******* *** ****** **** 30 **** but *** year *** *** days) **** ******* ******** *** * *** ** $5 or ** of *** transfer ********* ** ********** ******** ******* ******* ** *** ** balance ** *** ********* ** greater *** date ** the **** of *** month **** ******* *** is *** *** ** at least * ******* payment is not **** ****** ***** period(20 ******** Minimum ******** *** ** *** *** ******* ******** *** minimum ****** **** ** ******* There ** ** ****** feeUser InteractionYou ** *** *** * ******* ** this ******* for **** *********** ******* the ********** ************* the Credit **** ** ******** ******* within ************* ********* ** ***** class should contain ******* instance variables (section *** **** ******** members are notexpected ** change after given ** ******* ***** It ** good practice ** ****** ***** as ***** *** ****** **** for *** ***** ******** 71) ******* *********** names *** data ***** *** each ***** ******* ******** variables: * ****** for the **** ****** name doubles *** *** previous balance purchases ******* transfers and *** ********** ******* *** *** fees ******** and **** *********** ** ******* *** *** ****** ** ********* ** the current month a final ****** *** the ******* *** ********* * ***** *** for *** *** **** ******* a ***** ****** *** the **** ******* *** ******** a final ****** *** *** ******* ******** amount ******* * final double for *** **** ******* *** ************* final double *********** * *********** *** ***** ******** *** **** *** ***** final ******* ** **************** ** pts)A *********** is a special ****** with the **** name ** *** ***** *** ********* initializes ********* ** *********** ******** values Refer ** sections ** *** 38 public ********** ******* ***** – assigns the ********** name *** otherinstance ********* are set to ******* ****** CreditCard ******* **** ****** amt) * *********** constructorassigns the cardholder **** *** previous monthly ******* ** amt ***** ***************** are set ** ************ ******* ** pts)An accessor ****** **** *** modify ***** ****** *** names *** ***** methods ***** simplyreturn *** ******* value ** a ***** ***** ***** **** *** ****** ********* ***** ** ******* ***** ****** double ******************* ) * return the ******** balance ****** ****** getFees( * *** ****** *** ******* ****** ****** ************ * *** ****** the interest public ****** getPurchases( * *** ****** *** ************ public ****** ******************** * – ****** the ******* ************ public ****** **************** * *** ****** the **** advances public *** getNumPurchases( * *** ****** *** number ** ************ ****** ****** ******** * – return the card ****** *********** Methods *** ***** ******* method ******** tasks that *** ****** ***** ****** ***** to ******* ***** ****** **** applyCredit ******* amt) *** Reduce *** ********* ** amtDisplay ** *********** ******* **** ****** ****** ********* public **** *************** ******* amt) *** ******** **** to *********** balance ***** *** this ***** **** ****** **** ** **** back and **** ***** ***** total amount *** ** *** *** ** *** month ****** *** ******** ******* and **** Thefee ** either $5 ** ** ** *** ********** is greater) ******* ** appropriate ********** public **** purchase ******* **** *** ****** the purchase ******* ************ *** ****** ** ********* ******* ** *********** message ****** **** *********** ******* amt *** day) – ****** *** *********** ******* *** ******** ********* day ********** the *** *** advance was madeInterest ** ********** ** applying *** **** ******* *** for *** number ** days ***** ****** ** *** ***** ******* ** days *** * ***** *** *** **** *** *** year) For ********* day=10 then ***** are ********** remaining **** ** *** ***** Minimum interest is$050 ******* ** *********** ************** ****** ******* (15 ************** as ******* * ****** method ** **** by ***** ******* ****** the ***** Good ********** ** make ******* ******* unless **** **** to ** ****** ***** to section ***** ******* ****** calcMinimumPayment * * *** calculate and ****** ********** payment ***** is either *** ** *** ** *** *** balance calculated ** *** ***** the ***** ********** ** ******** Note **** ******* method ** ******* **** ************************* ******* **** resetAmounts * ) *** Update ******** balance ** *** ********** ***** *** other ******** variables ** **** Note **** ******* method ** *********** ****** *********************** ******* **** ************** * * - ******* *** monthly ********* ********* ****** for how *** statement ****** ****** ****** ********************** avoid ********* **** **** **** ******* ****** is ******* **** withincloseBillingPeriod()Additional Mutator ******* (10 pts)These ******* invoke *** ** more ** *** private ****** ******* ** keep ** ***** *** ********** ****** **** makePayment ******* *** *** **** *** ****** *********** ******* ** amt ********* *** ********** the *** ** *** ***** ******* wassubmitted ***** * penalty fee ** $37 ** *** ** *** ** ***** *** ******** ************** or is **** later than the **** ** *** ***** ****** ************************** than *********** the code ******* ** *********** message public **** ****************** () *** ********* ******** on *** *************** ** *** ** ******** *** balance *** ********* *** *** ******* *** ** ************** ******** ********* **** advances **** *** the ******** ******* ******* thecurrent ********* ** ******** *** helper ****** **************** ***** *********** variables ** necessary ** invoking *** ****** method ************************ Customer ****** *** ******* ********* ****** **** be ********* after *** other ************ ********* ***** **** ************* *** credit **** ***** ** now functional but ** ** ******** *** cardholder **** *********** ****** Make improvements ** *** following ******* **** *** ******* ***** **** ****** ** prevent ****** ******** mistakes ** ignoring ********** **** ******** ****** Noaction should ** ***** if *** *** ** ******** or ** day is not ******* * and 30 *************** (double amt) *********** ******* amt) ********* ******* ******* *********** ******* amt *** ******* *********** ******* *** *** ************ ****** (10 ******* following ****** **** be attempted ***** *** ***** ************ have **** ************ *** will **** **** *** ******** amounts ******* **** ***** ******* ****** *** no ********** *** *** NumberFormat ***** ********** ****** ** ******* *** monetary ********* currency ********* ****** an ******** ******** *** *** ** ********** *** **** ** ****** ******** ************* ************ fmt * NumberFormatgetCurrencyInstance();Number ********* ************ ***** *** be used to ******* currency ******* as ************ It is ************ in the **** *** you can find **** *********** ** the **** API *** **************** may ** ****** *** youCode ******** outputNumberFormat *** * NumberFormatgetCurrencyInstance();double ****** * ******************************** * * ******************* ***** ********** ***** *** ******** *********** ******** ******** ******* ******* ****** **** *** *** ***** ****** ********* **** **** ***** *********** *********** ********* ****** messages printed ***** *********** with ***** *** provided ** ************ messages ****** ** *********** ******** of 18495Purchase ******* ********** ******* of ***** ******* ******* ** *** *** *********** ******* **** ******* *** (1000 ********** cancelled: ******* * *** * * ********* transfer of ************ ********** purchase ** ********* ********** ******* * ******** *********** ****** ** ********** ********** ******* ************** ******** ***** ************ *************** ***************** *********** $900Interest: ******** ******** $146122Minimum ******** ********* payment ** **** ********** ** Day 10: ************** Testing (10 ************ ********** **** ********* test ***** **** ***** allows *** ** instantiate ********** then ****** ********** ******* ** manipulate the ****** (instance ********** ****** ********* You *** carefully check **** ****** and ******* ****** ******* with *************** ******* this gets ******* *** ****** be **************** **** ***** ***** a ****** methodAnother ******** ** ** write * main method ****** * **** harness **** ************ ** ********* **** calls ******* ** a ********* ******** ******** ***** to ******* ****** **** ******* ***** * main ****** ** * *** ***** called ******** that ************ ******* card *** ******* each of *** ******* **** a ******* ** ********* values Providemultiple ** ********** ** **** each ****** along with error ******** ** ****** It ************ ************* ** **** ***** possibilityThis is a ***** *** ********** example **** **** harness ****** ** **** ****** with ******* **************** ****** void main(String arg[]){CreditCard ****** = *** ****************** Stern");int ****** * **** ******** ************************************************************************ ** 10235){Systemoutprintln(" ERROR! **** *********************** ******** *************************************************** ** 10235){Systemoutprintln(" ****** **** negative ******************************************** * " ****** ***********