Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java: Please help me modify the code according to the instructions: We need to use Arrays, not ArrayList. We also should not use BufferedReader and

Java: Please help me modify the code according to the instructions: We need to use Arrays, not ArrayList. We also should not use BufferedReader and String Tokenizers.

Thank you.

Instructions:

  1. The AccountTester
    1. This class should consists of a main method that tests all the methods in each class, either directly by calling the method from the Tester or indirectly by having another method call a method.
    2. User and Bot information will be read from a file. A sample file is provided. Use this file format to aid in grading. Using file processing makes entering and testing program with data sets much more efficient.
    3. The file created should include valid and invalid passwords that fully tests the application.
    4. Included is file called data.txt contains Account data. Your project will be graded using a similar input file. Your project must run with an input file formatted as data.txt is formatted. Note the file format is as follows:
      1. Character designation of type of player ( u- User, b - Bot)
      2. User username,fullname,deptCode
      3. Bot botFilename,category,dateUpdated,createdBy
      4. Account data common data for both types
    5. Creates an array of Account objects.
      1. Populate the array with both User and Bot objects.
      2. Retrieves each object stored in the array and calls its toString method polymorphically and displays the results.

Code:

import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.StringTokenizer;

public class AccountTester { public static void main(String [] args) { CompanyAccounts comp1 = new CompanyAccounts("Oracle", "SanFrancisco"); try { BufferedReader inputFile = new BufferedReader(new FileReader("Data.txt")); String delimeter = ","; String [] a = new String [7]; String line = inputFile.readLine(); //Reads the file while the line does not equal null while(line != null){ //Tokenizer that delimits with commas. StringTokenizer inputToken = new StringTokenizer(line, delimeter); int numberOfTokens = inputToken.countTokens(); for(int i = 0; i < numberOfTokens; i++) { a[i] = inputToken.nextToken(); } //If User if(a[0].equalsIgnoreCase("u")) { Account user1 = new User(a[1], a[2], Integer.parseInt(a[3]), a[4], a[5]); comp1.addAccount(user1); //If Bot } else if(a[0].equalsIgnoreCase("b")) { Account bot1 = new Bot(a[1], a[2], a[3], a[4], a[5], a[6]); comp1.addAccount(bot1); //Error } else { System.out.println("wrong user type entered."); System.exit(0); } line = inputFile.readLine(); } System.out.println(comp1.toString()); comp1.deleteAccount(1002); System.out.println(comp1.toString()); System.out.println(comp1.getAccount(1001)); } catch (FileNotFoundException e) { System.out.println("File not found."); System.exit(0); } catch (IOException e) { System.out.println("Could not read"); } //inputFile.close(); }

}

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 PostgreSQL On The Cloud Simplifying Database As A Service On Cloud Platforms

Authors: Baji Shaik ,Avinash Vallarapu

1st Edition

1484234464, 978-1484234464

More Books

Students also viewed these Databases questions

Question

b. Why were these values considered important?

Answered: 1 week ago