Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Class Design the card looks like this 4000 1234 5678 9123 00/00 Chris L Martin ? Please define the CreditCard class. The class contains the

Class Design

the card looks like this 4000 1234 5678 9123 00/00 Chris L Martin

? Please define the CreditCard class.

The class contains the following seven attributes:

? first name: String

? Middle initial: char

? last name: String

? account number: long

? code: int

? balance: double

? credit limit: double

In the class definition, please include the following methods:

? One constructor with seven parameters, one for each attribute.

? Getter and setter methods for attributes except for balance.

? The getter method for balance.

? public boolean purchase(double amount): The method returns true if the purchase can go through (that is, when the balance + amount <= credit limit). Otherwise, the method returns false. Only if the purchase can go through, should the balance be increased.

? public void makePayment(double payment): The balance should be reduced by the payment amount.

? Define the equals method: Two credit cards would be considered equal if they have the same account number, assuming there are no duplicates in the bank.

? Define the toString method, which will return a string including the account number, the card holders full name, the balance and credit left, each separated by a comma.

? Write a test program CreditCardTest.java that does the following:

? Create a CreditCard object representing the credit card in the picture above, assuming the code is 256, the balance is $0, and the credit limit is $100

? Make three purchases one by one in the following order: $40, $50, and $60

? For each purchase, please display whether the purchases goes through according to the return value of the purchase method. If the method returns true, your program should display Your purchase went through.s Otherwise, your program should display Sorry, your purchase didnt go through.

? Display the balance.

? Display the credit left. (Hint: Credit left is not the credit limit, but credit limit minus balance.)

? Increase the credit limit to $200.

? Make another purchases of $60. Just as in 2b, your program should display either the purchase goes through or not according to the return value of the purchase method.

? Display the balance and the credit left.

? Ask user to enter the amount of payment and make a payment in this amount.

? At the end, print the information about the account. Please do not invoke the toString method directly, but the code is written in a way that the toString method will be invoked. I have already done some work on it but it's not finished

public class CreditCard { private String firstName; private char middleInitial; private String lastName; private long accountNumber; private int code; private double balance; private double creditLimit; public CreditCard(String firstName, char middleInitial, String lastName, long accountNumber, int code, double balance, double creditLimit) { this.firstName = firstName; this.middleInitial = middleInitial; this.lastName = lastName; this.accountNumber = accountNumber; this.code = code; this.balance = balance; this.creditLimit = creditLimit; } public String getFirstName() { return this.firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public char getMiddleInitial() { return this.middleInitial; } public void setMiddleInitial(char middleInitial) { this.middleInitial = middleInitial; } public String getLastName() { return this.lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public long getAccountNumber() { return this.accountNumber; } public void setAccountNumber(long accountNumber) { this.accountNumber = accountNumber; } public int getCode() { return this.code; } public void setCode(int code) { this.code = code; } public double getCreditLimit() { return this.creditLimit; } public void setCreditLimit(double creditLimit) { this.creditLimit = creditLimit; } public boolean purchase(double amount) { if(balance + amount <= creditLimit){ } return true; } }

public class CreditCardTest { public static void main (String[] args) { CreditCard chrisCard = new CreditCard("Chris", 'L', "Martin", 4000123456789123L, 256, 0, 100); if(chrisCard.purchase(40)) System.out.println("Your purchase went through."); else System.out.println("Your purchase didn't go through."); } }

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

Step: 3

blur-text-image

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

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions