edit and finish class authenticate below do not give a solution (example copying from another source and giving it as a solution) that is not part of my code below. Also provided is user class.
This is what I have so far please help me finish it. The task is listed below
//Authenticate.java
import java.util.Scanner;
import java.io.File;
Class Authenticate {
private final int SIZE = 100;
private User() users = new User[SIZE];
public Authenticator (String fileName) throws Exception;
Scanner sc = new Scanner(new File(fileName));
int i = 0;
While(sc.hasNext() && i < SIZE) {
users[i] = Users.read(sc);
i++
}
}
public void authenticate(String username, String password) throws Exception{
try {
User u = null;
for(User X : users) {
if(x.getUsername().equals(username) && x.verifyPassword(password){
return ;
_________________________________________________________________
//User.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class User
{
private String username;
private String password;
private String hint;
public User(String username, String password, String hint)
{
this.username = username;
this.password = password;
this.hint = hint;
}
public boolean verifyPassword(String Password)
{
return Password.equals(password);
}
public String toString()
{
return "User "+username;
}
public static User read(Scanner scanner)
{
if(scanner.hasNext()){ }else {return null;}
return new User(scanner.next(), scanner.next(), scanner.next());
}
public String getUsername()
{
return username;
}
public String getHint()
{
return hint;
}
}
TASK
Implement the following class name Authenticator:
State
An array of type User (use a capacity of 100 — I would recommend using a class constant the way I did in the 06-Array class of Lecture 2).
An integer size
Behavior
A constructor accepting a file name, that opens a Scanner on the file and reads in User objects
A method named authenticate that accepts a username and password and attempts to authenticate them against the User array (by doing a search).
Not finding the username in the array causes an exception to be thrown
finding the username, but not matching the password (via verifyPassword) causes an exception with a different message to be thrown (this one with the password hint included).
See below for the exact exception messages expected
The return type of the method is void, i.e., the method returns nothing if the username and password are matched; otherwise an exception is thrown, as described above. (This is a common pattern for authentication methods — if everything is fine, the method simply returns, otherwise it throws an exception.)
The name of your class should be Authenticator. Please remove the public attribute from the class header.
Your class is tested by a AuthenticatorApp class that reads in Users from a file using your read method, loads them into an array and prompts the keyboard for a login sequence (username/password).
For example, if the file users.data contains:
weiss puppy2 woof-woof
arnow java cuppa
sokol brooklyn college
here are some sample excutions of the program:
username? arnow
password? java
Welcome to the system
Sample Test Run #2
Given the same users.data file as above, execution of the program should look like:
username? weiss
password? dontremember
*** Invalid password - hint: woof-woof
username? weiss
password? puppy2
Welcome to the system
Sample Test Run #3
Given the same users.data file as above, execution of the program should look like:
username? sokol
password? CUNY
*** Invalid password - hint: college
username? sokol
password? SUNY
*** Invalid password - hint: college
username? sokol
password? BC
*** Invalid password - hint: college
Too many failed attempts... please try again later
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
- import java.util.Scanner; public class Shady RestRoom 2 { // Modify the code below public static void main (String args[]) { int selection; int price; String result; final int QUEEN = 1, KING = 2, SUITE = 3; final int QPRICE = 125, KPRICE = 139, SPRICE = 165; final String QSTRING = "Queen bed", KSTRING = "King bed"; SSTRING = "Suite with a king bed and pull-out couch"; INVALIDSTRING = "an invalid option"; Scanner in = new Scanner(System.in); System.out.println("\t\n\nMenu\n"); System.out.println("(" + QUEEN + ") " + QSTRING); System.out.println("(" + KING + ") " + KSTRING); System.out.println("(" + SUITE + ") " + SSTRING); System.out.print("Enter Selection (1, 2, or 3) >> "); selection = in.nextInt(); if(selection == QUEEN) { result = QSTRING; price = QPRICE; } else if(selection == KING) { result = KSTRING; price = KPRICE; } else if (selection == SUITE) { result = SSTRING; price = SPRICE; } else { result = INVALIDSTRING; price = 0; } System.out.println("You selected " + result +…arrow_forwardStatement that increases numPeople by 5. Ex: If numPeople is initially 10, the output is: There are 15 people.arrow_forwardPlease be aware that your score will be zero if your codes are the same as others'. Do not cheat. 填空题 The JDK command to compile a class in the file Test.java is The main method header is written as Suppose a Scanner object is created as follows: Scanner input = new Scanner(System.in); What method do you use to read a double type number? What is y after the following statement is executed? x = -1; y = (x < 0) ? 10: -10; What is the index variable for the element at the first row and first column in array a? 1. 2. 3. 4. 5.arrow_forward
- Write in Javaarrow_forwardSee ERROR in Java file 2: Java file 1: import java.util.Random;import java.util.Scanner; public class Account {// Declare the variablesprivate String customerName;private String accountNumber;private double balance;private int type;private static int numObjects;// constructorpublic Account(String customerName, double balance, int type) { this.customerName = customerName;this.balance = balance;this.type = type;setaccountNumber(); // set account number functionnumObjects += 1;}private void setaccountNumber() // definition of set account number{Random rand = new Random();accountNumber = customerName.substring(0, 3).toUpperCase();accountNumber += type;accountNumber += "#";accountNumber += (rand.nextInt(100) + 100);}// function to makedepositvoid makeDeposit(double amount){if (amount > 0){balance += amount;}}// function for withdrawboolean makeWithdrawal(double amount) {if (amount < balance)balance -= amount;elsereturn false;return true;}public String toString(){return accountNumber +…arrow_forwardDon't give me AI generated answer or plagiarised answer. If I see these things I'll give you multiple downvotes and will report immediately.arrow_forward
- Reply to another student's post. Modify the student's code by providing a modified approach to the class or suggestions for enhancement. * * * Import java.util.Scanner; public class Appliance { //Instance variables declared public int level; public char auto; //Method to assign values for humidity level and auto feature; taken from user input in main method public void setValues(int level, char auto) { this.level = level; this.auto = auto; } //Method to display results from user input public void displayStatus() { System.out.println("You have entered " + level + " for humidity"); System.out.println("You have entered " + auto + " for auto feature"); String setting = null; if (Character.toUpperCase(auto) == 'Y') { setting = "ON"; } else { setting = "OFF"; } System.out.println("\nThe humidity level is " + level + "%"); System.out.println("The auto feature is set to " + setting); } public static void main(String[] args) { //Create instance of class Appliance humidity = new…arrow_forwardWrite class named as Main having main method and show activity of above methods. Add 5 Students in array Display all students in array Remove a student by name Show the count of students in array Display all student in array Sort array by name and display all students Sort array by age and display all students Sort array by cgpa and display all students Reverse the array and display all students Note.This is a java programarrow_forwardView Assessment X abe lll- Google Drive X blackboard.uob.edu.bh/ultra/courses/ 26720 1/outline/assessment/ 672949 1/overvi Assume you have a method (shown below) inside the ArrayQueue class public void unknown() Iifsize == 0) return; int i=front; int k=rear; for(int j=0; jarrow_forwardMake a game. package p1; public class Game { public static void main(String[] args) { throw new RuntimeException("Not implemented"); } }arrow_forward13 public class MaxMinAtLeastOneValue 14 {. public static void main(String[] args) { Scanner in = new Scanner (System.in); 15 16 17 18 // Step 2: Read in an integer as the count of double values 19 wit an input prompt "Enter the count of values: and store it in a variable // 20 21 // 22 23 // Step 3: Read in a double value with an input prompt 24 25 "Enter the first value: and store it in a variable max 26 27 28 // Step 4: Assign the value of max to another 29 // variable min 30 31 32 // Step 5: Use a for loop to read all remaining double values with an input prompt 33 // 34 // "Enter the next value: 35 // and update max and min 36 37 savedarrow_forward6. Design a Java class with a main method that does the following. You must include a meaningful comment for main and each method a. Main invokes a method readScores to read input from a file (name of your choice) that contains the name of the bowlers (no more than 25) and their bowling scores (two scores per bowler). The program stops reading values when it has reached the end of the file. For example, the file might contain: Bob 203 176 Jane 210 253 Jack 300 189 Eileen 220 298 • As the method reads the data, it stores the name into a String array and the average of the two bowling scores into an array of double. • The method returns the actual number of bowlers read in b. Main then invokes a method computeOverallAvg to: compute (a) the overall average score of all the bowlers combined, (b) the average score and name of the bowler with the highest average score and (c) the average score and name of the bowler with the lowest average scores. print to the console (a) the overall average…arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY