Question

Java: Please help with my Tester. I'm having a hard time figuring out my error. Thank...

Java: Please help with my Tester. I'm having a hard time figuring out my error. Thank you.

What the tester requires:

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.

My code:

public class Account
{
   private String clearPassword;
   private String encryptedPassword;
   private int key;
   private int accountId;
   private static int nextIDNum = 1000;

public Account()
   {
       this.clearPassword = " ";
       this.encryptedPassword = " ";
       this.key = 0;
       this.accountId = nextIDNum;  
       updateNextIDNum();
   }


   public Account(String clearPassword, int key)
   {
       if(clearPassword.length() >= 8 && 1 <= key && key <= 10)
       {
           this.clearPassword = clearPassword;
           this.key = key;
           this.encryptedPassword = " ";
           encrypt();
       }
       else
       {
           System.out.println("ERROR:: Minimum passwoed length should be 8.\n"
                   + "Key should be between 1 and 10.");
           this.clearPassword = " ";
           this.encryptedPassword = " ";
           this.key = 0;
       }
       this.accountId = nextIDNum;
       updateNextIDNum();
   }


   private void encrypt()
   {

       for (char letter : clearPassword.toCharArray()) {
           char shift = (char) (((letter + key) % 90) + 33);
           encryptedPassword += shift;
       }
   }


   public void setClearPassword(String clearPassword)
   {
       this.clearPassword = clearPassword.length() >= 8 ? clearPassword : this.clearPassword;
       encrypt();
   }

   /**
   * no encryptedPassword mutator method
   */


   public void setKey(int key) {
       this.key = (1 <= key && key <= 10) ? key : this.key;
       encrypt();
   }

  
   public void updateNextIDNum()
   {
       Account.nextIDNum++;
   }


   public int getAccountId()
   {
       return accountId;
   }


   public String getClearPassword()
   {
       return clearPassword;
   }


   public String getencryptedPassword()
   {
       return encryptedPassword;
   }


   public int getkey()
   {
       return key;
   }



   @Override
   public String toString()
   {
       return "Account ID: " + this.accountId + ", Encrypted Password: "
               + this.encryptedPassword + "\t["+ key+"]:Key" ;
   }


   public static void main(String[] args) {

       Account account = new Account("Swcret#123",7);
       System.out.println(account);
   }
}

=================================================================================

public class User extends Account
{

   private String username;
   private String fullName;
   private int deptCode;

   /**
   * Methods
   */


   public User()
   {
       super();
       this.username = " ";
       this.fullName = " ";
       this.deptCode = 0;
   }

   public User(String clearPassword, int key, String userName, String fullName, int code, String username)
   {
       super(clearPassword, key);
       this.username = username;
       this.fullName = fullName;
       this.deptCode = code;

   }


   /**
   * Accessor and mutator methods for all variables in this class
   * return userName
   */

   public String getUsername() {
       return username;
   }


   public void setUsername(String username) {
       this.username = username;
   }


   public String getFullName() {
       return fullName;
   }


   public void setFullName(String fullName) {
       this.fullName = fullName;
   }


   public int getDeptCode() {
       return deptCode;
   }


   public void setDeptCode(int deptCode) {
       this.deptCode = deptCode;
   }


   public String toString()
   {
       return "Username: " + username + ", Fullname: " + fullName + "Department Code: "
               + deptCode + " " + super.toString();
   }


}

=====================================================================

public class Bot extends Account
{


private String botFileName;
private String category;
private GregorianCalendar dateUpdated;
private String createdBy;

/**
* Methods
*/
  

public Bot()
{
super();
this.botFileName = "";
this.category = "";
DateFormat ndf = new SimpleDateFormat("dd/MM/yyyy");
dateUpdated = new GregorianCalendar();
this.createdBy = "";
}


public Bot(String clearPassword, int key, String botFileName, String category, GregorianCalendar dateUpdated, String createdBy)
{
super(clearPassword, key);
this.botFileName = botFileName;
this.category = category;
this.dateUpdated = dateUpdated;
this.createdBy = createdBy;
}


  
/**
* Accessor and mutator methods for all variables in this class.
*/


public String getBotFileName()
{
return botFileName;
}
  

public void setBotFileName(String botFileName)
{
this.botFileName = botFileName;
}


public String getCategory()
{
return category;
}


public void setCategory(String category)
{
this.category = category;
}


public GregorianCalendar getDateUpdated()
{
return dateUpdated;
}


public void setDateUpdated(GregorianCalendar dateUpdated)
{
this.dateUpdated = dateUpdated;
}

  
public String getCreatedBy()
{
return createdBy;
}


public void setCreatedBy(String createdBy)
{
this.createdBy = createdBy;
}
  

@Override
public String toString()
{
return "File name: " + botFileName + "Category: " + category
       + "Updated on: " + dateUpdated.get(Calendar.MONTH) + "/"
       + dateUpdated.get(Calendar.DAY_OF_MONTH) + "/"
       + dateUpdated.get(Calendar.YEAR) + " " +
"Created by:" + dateUpdated + super.toString();
}
}
======================================================================


Data.txt
----------------------------------
u,weaston,Wesley Easton,15,Mo$$y308,mossy
b,SysError.cmd,SYS,10/11/2011,sips,Pa$$word,login
u,cak410,Christina Easton,30,Gra$2012,grad
b,DOSAlert.c,IDS,12/11/2015,jgosling,xyz83$2Iw,answer

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.io.File;
import java.io.FileNotFoundException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Scanner;

public class AccountTester {

    public static void main(String[] args) {
        // need to update the file path in the below line
        File filePath = new File("D:\\Data.txt");
        Account[] accounts = new Account[100];
        int index = 0;
        try {
            Scanner scanner = new Scanner(filePath);
            while (scanner.hasNextLine()) {

                String[] tokens = scanner.nextLine().split(",");
                if (tokens[0].equalsIgnoreCase("u")) {

                    String userId = tokens[1];
                    String userName = tokens[2];
                    int key = Integer.parseInt(tokens[3]);
                    String clearPassword = tokens[4];
                    String code = tokens[5];
                    //String clearPassword, int key, String fullName, int code, String username
                    accounts[index] = new User(clearPassword, key, userName, code, userName);
                    index += 1;

                } else {

                    //b,SysError.cmd,SYS,10/11/2011,sips,Pa$$word,login
                    //String clearPassword, int key, String botFileName, String category, GregorianCalendar dateUpdated, String createdBy
                    String userId = tokens[1];
                    String userName = tokens[2];
                    int key = Integer.parseInt(tokens[3]);
                    String clearPassword = tokens[4];
                    String code = tokens[5];
                    //String clearPassword, int key, String fullName, int code, String username
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("mm/dd/yyyy");
                    Date date = simpleDateFormat.parse(tokens[3]);
                    GregorianCalendar calendar = new GregorianCalendar();
                    calendar.setTime(date);
                    accounts[index] = new Bot(clearPassword, 1, tokens[1], tokens[6], calendar, userName);
                    index += 1;

                }

            }

            for (int i = 0; i < index; i++) {
                System.out.println(accounts[i]);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }
}
Add a comment
Know the answer?
Add Answer to:
Java: Please help with my Tester. I'm having a hard time figuring out my error. Thank...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters...

    Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...

  • The current code I have is the following: package uml; public class uml {        public...

    The current code I have is the following: package uml; public class uml {        public static void main(String[] args) {              // TODO Auto-generated method stub        } } class Account { private String accountID; public Account(String accountID) { this.accountID = accountID; } public String getAccountID() { return accountID; } public void setAccountID(String accountID) { this.accountID = accountID; } @Override public String toString() { return "Account [accountID=" + accountID + "]"; } } class SuppliesAccount extends Account { private...

  • This project will use The Vigenere Cipher to encrypt passwords. Simple letter substitution ciphers are ones...

    This project will use The Vigenere Cipher to encrypt passwords. Simple letter substitution ciphers are ones in which one letter is substituted for another. Although their output looks impossible to read, they are easy to break because the relative frequencies of English letters are known. The Vigenere cipher improves upon this. They require a key word and the plain text to be encrypted. Create a Java application that uses: decision constructs looping constructs basic operations on an ArrayList of objects...

  • JAVA PROGRAMMING***** Please provide screenshots of output and write a tester class to test. The ...

    JAVA PROGRAMMING***** Please provide screenshots of output and write a tester class to test. The starter code has been provided below, just needs to be altered. For this project you will implement the Memento Design Pattern. To continue on with the food theme, you will work with Ice Cream Cones. You will need to use AdvancedIceCreamCone.java. Create at least three Ice Cream Cones - one with chocolate ice cream, one with vanilla ice cream and one with strawberry ice cream....

  • I need help with my java code i am having a hard time compiling it //...

    I need help with my java code i am having a hard time compiling it // Cristian Benitez import java.awt.Color; import java.awt.Graphics; import java.util.ArrayList; import javax.swing.JPanel; Face class public class FaceDraw{ int width; int height; int x; int y; String smileStatus; //default constructor public FaceDraw(){ } // Getters and Setters for width,height,x,y public int getWidth(){ return width; } public void setWidth(int width){ this.width=width; } public int getHeight(){ return height; } public void setHeight(int height){ this.height=height; } public int getX(){ return...

  • Can someone help me with my Java code error! Domain package challenge5race; import java.util.Random; public class...

    Can someone help me with my Java code error! Domain package challenge5race; import java.util.Random; public class Car {    private int year; private String model; private String make; int speed; public Car(int year, String model, String make, int speed) { this.year = year; this.model = model; this.make = make; this.speed = speed; } public Car() { } public int getYear() { return year; } public void setYear(int year) { this.year = year; } public String getModel() { return model; }...

  • Write in java and the class need to use give in the end copy it is...

    Write in java and the class need to use give in the end copy it is fine. Problem Use the Plant, Tree, Flower and Vegetable classes you have already created. Add an equals method to Plant, Tree and Flower only (see #2 below and the code at the end). The equals method in Plant will check the name. In Tree it will test name (use the parent equals), and the height. In Flower it will check name and color. In...

  • Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java...

    Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>();   // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString());       //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234");    // printing information System.out.println(part2.toString());    //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...

  • Hey guys I am having trouble getting my table to work with a java GUI if...

    Hey guys I am having trouble getting my table to work with a java GUI if anything can take a look at my code and see where I am going wrong with lines 38-49 it would be greatly appreciated! Under the JTableSortingDemo class is where I am having erorrs in my code! Thanks! :) import java.awt.*; import java.awt.event.*; import java.util.*; import java.util.List; import javax.swing.*; public class JTableSortingDemo extends JFrame{ private JTable table; public JTableSortingDemo(){ super("This is basic sample for your...

  • NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the...

    NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the current displayed customer PLEASEEEEEEEEEE package bankexample; import java.util.UUID; public class Customer { private UUID id; private String email; private String password; private String firstName; private String lastName;    public Customer(String firstName, String lastName, String email, String password) { this.id = UUID.randomUUID(); this.firstName = firstName; this.lastName = lastName; this.email = email; this.password = password; } public String getFirstName() { return firstName; } public void setFirstName(String...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT