Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

download the skeleton code for the CreditCard.java class. Create a sample project in your chosen IDE. The commented code in the files should provide you

download the skeleton code for the CreditCard.java class. Create a sample project in your chosen IDE. The commented code in the files should provide you with instructions to fulfill the tasks for each. Add both files to your src directory in the IDE project files. Fulfill the tasks asked in the comments and run the code

Exceptions : you are to create a credit card with an approved limit and a registered location. You are to create three exceptions (each in their own class) that check for different possible errors. One exception check for fraud by comparing locations. One exception checks for approval limits against the max approval amounts. The last exception checks if the card is maxed out on a purchase.

// Create the following three exception classes, each in its own class

// All are checked exceptions (inheriting from Exception)

// ApprovedLimitException

// CardMaxException

// FraudException

public class CreditCard {

private int MAXLIMIT = 5000;

private int credit;

private String location;

// create CreditCard constructor that will throw an ApprovedLimitException if

// the credit given is greater than the MAXLIMIT

// create a private subtractCredit method that takes in a purchase amount and checks if a CardMaxException

// is thrown on the purchase

// make sure to subtract the purchase amount from the card's credit

// create a public purchase method that takes in the purchase amount and the purchase location

// check if the location of the purchase is in the same location as the card in order to check

// against a FraudException

// hint: you will also need to handle CardMaxExceptions due to the use of the subtractCredit method

public static void main(String args[]) throws CardMaxException, FraudException, ApprovedLimitException {

CreditCard card = new CreditCard(2500, "Toronto");

card.purchase(500, "Toronto");

// CreditCard card = new CreditCard(25000, "Toronto");

// card.purchase(5000, "Toronto");

// card.purchase(5000, "Atlanta");

// try different combinations that trigger different exceptions

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions