Question
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:
- The AccountTester
- 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.
- 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.
- The file created should include valid and invalid passwords that fully tests the application.
- 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:
- Character designation of type of player ( u- User, b - Bot)
- User username,fullname,deptCode
- Bot botFilename,category,dateUpdated,createdBy
- Account data common data for both types
- Creates an array of Account objects.
- Populate the array with both User and Bot objects.
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started