CreditCard-like Java Program

Selesai Dipasang Apr 1, 2015 Dibayar saat pengiriman
Selesai Dibayar saat pengiriman

Credit card companies use built-in "checksums" as added security measures when creating the account numbers on credit cards. This means that there are only certain valid credit card numbers, and validity can instantly be detected by using an algorithm that may involve adding up parts of the numbers or performing other checks. In this problem, you will implement a security algorithm on a credit card number, and your program will indicate whether or not the card number is valid, according to the security check. Note that this algorithm is purely made-up; don't try to use it to detect fake credit card numbers!

To check that the credit card number is valid, verify that it conforms to the following rules:

The first digit must be a 4.

The fourth digit must be one greater than the fifth digit

The product of the first, fifth, and ninth digits must be 24

The sum of all digits must be evenly divisible by 4

The sum of the first four digits must be one less than the sum of the last four digits

If you treat the first two digits as a two-digit number, and the seventh and eight digits as a two digit number, their sum must be 100.

Hint: valid card numbers according to this set of rules include 480760521766 and 409434602754. You should use these for testing out your program.

Your job is to create a CreditCard class that represents a card number as a String. Hence you will have an instance variable of type String to store this. In addition the CreditCard class must have a mutator method called check( ) that determines if the credit card is valid or not. This information (whether the card is valid or not) should be stored in an instance variable of type boolean. Your class should also have an accessor method called isValid( ) that returns the value of this boolean. Your class CreditCard should also have an instance variable of type int called errorCode. This variable should be initialized to 0 and changed to an integer between 1 and 6 if the CreditCard object fails one of the tests above. That is, the check( ) method should change errorCode to the number corresponding to the first test the number failed. If the number does not fail any tests then you can leave the errorCode variable at 0. Finally, you should have an accessor method called getErrorCode( ) that returns the value of the variable errorCode. You might find this method useful when you are verifying that your check( ) method works correctly.

Attached you will find a test class called CreditCardTester. Your CreditCard class must work with the test class provided without modification. You must NOT alter the test class.

To complete this problem, you will need to use various methods of the String class, described in Horstmann and in the Java online documentation for String. In particular, you should use methods for getting the character at a certain index and for converting characters to Strings. You will also need to use the [login to view URL] method to convert a String to an int.

Must be completed same day.

Java

ID Proyek: #7414182

Tentang proyek

7 proposal Proyek online Aktif Apr 1, 2015

Diberikan kepada:

it2051229

Hi, I have read the requirements and I would like to do this project if given the opportunity. I am a computer science practitioner and having the "Java and Algorithms Certification Badge" in my profile gives me confid Lebih banyak

$20 USD dalam 0 hari
(1079 Ulasan)
7.6

7 freelancer rata-rata menawar $19 untuk pekerjaan ini

Shankarone

This project is easy .I have good experience in java (have done around 80 projects) and I rank at top 1% in algorithm websites like codeforces and codechef with username : shank_punk . I can complete this project quic Lebih banyak

$15 USD dalam 0 hari
(25 Ulasan)
4.8
vietcompro

Hi there, I've already read and understood the project description, and I'm really interested in doing this project. Would you please initiate a chat for further discussion? So really hope to have chance to work wit Lebih banyak

$20 USD dalam 0 hari
(33 Ulasan)
4.3
moonbea5t

I am a teaching assistant at one of the top 50 universities in the world (Purdue University) for a Java Programming Course. I am the best person when it comes to school related assignments since I can relate best to th Lebih banyak

$20 USD dalam 1 hari
(17 Ulasan)
3.7
DavidDani

Hi I am a java developer. Tell me when do you want to be done your java task, thanks a lot for the chance

$25 USD dalam 1 hari
(0 Ulasan)
0.0
motozakiyoshimi

Algorithm: - Parse the whole string to integer. - Extract each digit from right to left and store it in a stack. - Pop the stack and perform the checks. Note: - All of the checks shall be hard-coded. - Since ther Lebih banyak

$14 USD dalam 1 hari
(0 Ulasan)
0.0