1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alexxandr [17]
3 years ago
5

This question involves the implementation of the PasswordGenerator class, which generates strings containing initial passwords f

or online accounts. The PasswordGenerator class supports the following functions:
- Creating a password consisting of a specified prefix, a period, and a randomly generated numeric portion of specified length
- Creating a password consisting of the default prefix "A", a period, and a randomly generated numeric portion of specified length
- Reporting how many passwords have been generated

The following table contains a sample code execution sequence and the corresponding results: Statements, Possible Value Returned (blank if no value returned), Comment

PasswordGenerator pw1 = new
PasswordGenerator(4, "chs");
(blank)
Passwords generated by the pw1 object are composed of the prefix "chs", a period, and 4 randomly-generated digits.
pw1.pwCount();
0
No passwords have been generated yet.
pw1.pwGen();
"chs.3900"
A possible password generated by the pw1 object
pw1.pwGen();
"chs.1132"
A possible password generated by the pw2 object
pw1.pwCount();
2
Two passwords have been generated. Both contain the prefix "chs" and 4 digits.
PasswordGenerator pw2 = new
PasswordGenerator(6);

Passwords generated by the pw2 object are composed of the default prefix "A", a period, and 6 randomly generated digits.
pw2.pwCount();
2
Two passwords have been generated. Both contain the prefix "chs" and 4 digits.
pw2.pwGen();
"A.843055"
A possible password generated by the pw2 object
pw2.pwCount();
3
Three passwords have been generated. Two contain the prefix "chs" and 4 digits, and the third contains the default prefix "A" and 6 digits.
pw1.pwCount();
3
Three passwords have been generated. The same value is returned by pwCount for all objects of the PasswordGenerator class.

Write the complete PasswordGenerator class. Your implementation must meet all specifications and conform to the example.
Computers and Technology
1 answer:
liq [111]3 years ago
8 0

The following code will be used for the PasswordGenerator class.

<u>Explanation:</u>

import java.util.Random;

public class PasswordGenerator {

   private static int passwordsGenerated =0;

   private static Random random = new Random();

   private String prefix;

   private int length;

   public PasswordGenerator(int length,String prefix) {

       this.prefix = prefix;

       this.length = length;

   }

   public PasswordGenerator(int length) {

       this.prefix = "A";

       this.length = length;

   }

   public String pwGen(){

       String pwd= this.prefix+".";

       for(int i=1;i<=this.length;i++){

           pwd+=random.nextInt(10);

       }

       passwordsGenerated+=1;

       return pwd;

   }

   public int pwCount(){

       return passwordsGenerated;

   }

   public static void main(String[] args) {

       PasswordGenerator pw1 = new PasswordGenerator(4,"chs");

       System.out.println(pw1.pwCount());

       System.out.println(pw1.pwGen());

       System.out.println(pw1.pwGen());

       System.out.println(pw1.pwCount());

       PasswordGenerator pw2 = new PasswordGenerator(6);

       System.out.println(pw2.pwCount());

       System.out.println(pw2.pwGen());

       System.out.println(pw2.pwCount());

       System.out.println(pw1.pwCount());

   }

}

You might be interested in
Chris needs to modify the default bullets that are used in a nonnumbered list in Word.
laiz [17]

Answer:

he should select the arrow next to the bullet list

Explanation:

6 0
3 years ago
Read 2 more answers
What group in the review tab contains the commands and to accept or reject changes made to a document
matrenka [14]

Answer:

the command tab

Explanation:

4 0
3 years ago
Read 2 more answers
What is a unique text-based Internet address corresponding to a computer's unique numeric IP address called
bekas [8.4K]

Answer:

Domain Name

Im in the class right now we just took a test on this and i got a 96

If you need more help lmk

8 0
4 years ago
What was that show where lowe’s were based off eye colors and the main character had orange eyes that let her mind control peopl
UNO [17]
The Innocents on Hulu i think
7 0
3 years ago
Read 2 more answers
What is the purpose of OPPA<br>​
aivan3 [116]

Answer:

The purpose of OPPA is to make its mandatory for companies to disclose what kind of information they will acquire from their users.

Hope it helps you!!

7 0
3 years ago
Other questions:
  • Acme Parts runs a small factory and employs workers who are paid one of three hourly rates depending on their shift: first shift
    5·1 answer
  • What is the next series of dragon ball super
    6·2 answers
  • Say our confusion matrix is as follows, calculate precision, recall, and accuracy. Interpret the results for the positive class.
    10·1 answer
  • Write a program that will find the smallest, largest, and average values in a collection of N numbers. Get the value of N before
    13·1 answer
  • Which precaution should be taken when working inside computer systems??
    9·1 answer
  • PLZ help
    5·1 answer
  • . Which of the following is NOT a valid declaration for a character string?
    6·1 answer
  • What is a file type and why is it important? Give at least three examples of file
    7·1 answer
  • Hyperlink is a term used to refer to the specific manner of specifying the address of a website. Write reason for true or false.
    10·1 answer
  • identify the difficulties with the k-nearest neighbor algorithm. a. both a and b b. calculate the distance of the test case from
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!