Create an array of creditcard objects populate and display


Programming and Logic I

Project: Credit Card

Your CreditCard class should contain three data fields and methods to set, get and manipulate these fields. In this project, you will create an array of CreditCard objects, populate and display the values. You will not be changing your CreditCard class, but you will have to submit it.

Files to Submit:

CreditCard.java
TestCreditCard.java

TestCreditCard.java

createAccountArrayFromFile()
Create a method called createAccountArrayFromFile. (This is a long name, I realize, but it is descriptive.) This method will create and return an array of CreditCard objects.

Open the file, accounts.txt, for reading. Hard code this file name into your program. The file will contain three lines for each account: an account number, account name, and balance, and has data for 10 accounts. The file I will use to test your program will also have data for 10 accounts but the accounts will contain different data.

Create the array. The size will be 10 and this can be hard coded. Although we are reading this information from a file and it would be more usefulto simply add objects as we go along, an array needs a size when it is created. (The ArrayList class does not, and is preferable in this respect.)

Create a loop and iterate through the file, creating elements of the CreditCard array. If you didn't know how much data was stored in the file, you would use a while loop, but since you know it will contain exactly 10 accounts, you can use a while loop or for loop.

Finally, the method must return the array.

printCreditCardArray()
Create a void method called printCreditCardArrray that takes one parameter, a CreditCard array. Loop through the array and print the values using the CreditCard object's printAccount method.

main()
Empty the main method. Create a CreditCardarray and make it equal to thecreateAccountArrayFromFile method call. The call theprintCreditCardArray method and send it one argument: the CreditCard array.
Notes:
- You can append numbers to your files if you want to preserve old files - for example, CreditCard3.java, TestCreditCard3.java. Just make sure you are using the correct class name in your TestCreditCard program.
- If you use a while loop to iterate through the file, you will need an int variable to act as an index for the array. Make sure to initialize this variable to 0 before the loop begins and increment it within the loop.
- You may enconter the nextLine issue as you read through the file. This occurs when you read a number using nextInt or nextDouble and then use the nextLine method. This is remedied by using a "dummy"nextLine call in between nextInt and nextLine.

Attachment:- Code.rar

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Create an array of creditcard objects populate and display
Reference No:- TGS02392040

Now Priced at $20 (50% Discount)

Recommended (98%)

Rated (4.3/5)