Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Assignment Design a java class to represent a credit card. Try to design th

ID: 3909052 • Letter: J

Question

Java Assignment

Design a java class to represent a credit card. Try to design the class such that it only fields and methods relevant to a credit card itself without branching into related functionality that that of a bank or a consumer. I need to have a list of the fields and methods. Fields will need to specify the type, accessibility (private, public, protected, default or package), whether it is a static or instance field and any limitations on the values (non-negative, always less than some other value, etc). For methods, I need to supply the return type and parameter type list. A Free-form description of what each field and method is meant to do with explanation of any potentially confusing design decisions.

Here is what I have so far.

Its attributes (member or instance variables) are:

network - An enum (CardNetwork) type consisting of one of the 4 major networks (AMEX, DISCOVER, MASTERCARD or VISA)
number - The credit card number (String)
cardHolder - The name of the credit card holder (owner) (String)
expirationDate - The expiration date of the credit card (String)
securityCode - The security code associated with the card (int)

The Credit class will have methods to:

Create a new CreditCard (given a network, card holder name, number, expiration date and security code) [constructor]
getCardHolder
getExpirationDate
getNetwork
getNumber
setCardHolder
equals [method to check if one CreditCard is the same as another]
toString [method to turn CreditCard into a string for display]

Explanation / Answer


Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you


CardNetwork.java
------

public enum CardNetwork {
AMEX, DISCOVER, MASTERCARD, VISA
}

CreditCard.java
------

public class CreditCard {
private CardNetwork network;
private String number;
private String cardHolder;
private String expirationDate; //should a valid date
private int securityCode; //should be +ve

public CreditCard(CardNetwork network1, String number1, String cardHolder1, String expirationDate1, int securityCode1){
network = network1;
number =number1;
cardHolder = cardHolder1;
expirationDate = expirationDate1;
securityCode = securityCode1;
}

public CardNetwork getNetwork() {
return network;
}

public String getNumber() {
return number;
}

public String getCardHolder() {
return cardHolder;
}

public String getExpirationDate() {
return expirationDate;
}

public int getSecurityCode() {
return securityCode;
}

public void setCardHolder(String name){
cardHolder = name;
}

public boolean equals(CreditCard other){
if(number.equals(other.number) && network.equals(other.network) && securityCode == other.securityCode)
return true;
else
return false;
}

public String toString(){
return "Card network: " + network + ", number: " + number + ", Holder: " + cardHolder
+ ", Expiry Date: " + expirationDate + ", Security code: " + securityCode;
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote