Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java: I'm receiving the following error in my tester. please help. Also, we are not at error handling. Will you please help with the tester

Java: I'm receiving the following error in my tester. please help. Also, we are not at error handling. Will you please help with the tester with no error handling. Thank you.

Error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: The constructor User(String, int, String, String, String) is undefined

at AccountTester.main(AccountTester.java:53)

Code:

public class AccountTester {

public static void main(String[] args) { // need to update the file path in the below line File filePath = new File("data.txt"); /** * Creates an array of Account objects. */ 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(); */ }

} }

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

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. " + "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

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

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

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

Students also viewed these Databases questions

Question

Why do insurance costs and taxes vary among homes?

Answered: 1 week ago

Question

=+ a. How does this change affect the incentives for working?

Answered: 1 week ago