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
To save your new document or presentation, click the Start Button
Vika [28.1K]
No you would click save or save as
3 0
3 years ago
"Most of us know that when we come into a college classroom, we will see desks and chairs, a computer station and a projector. A
gayaneshka [121]
Accessibility... I think
3 0
3 years ago
PLEASE HELP TAKING TEST NOW!!! Of the following websites, the least trustworthy is one that (1 point)
Rom4ik [11]

Here's all the right answers.

1. What is the main purpose of a graphic organizer?

Answer: B

2. Which of the following website publishers would be considered an authoritative source about the cultures of ancient Mesopotamia?

Answer: C

3. Which of the following websites is the least biased?

Answer: D

4. Which of the following is true about graphic organizers?

Answer: A

5. Of the following websites, the least trustworthy is one that...

Answer: C

6 0
3 years ago
Can someone sub to my youttube pls, its called Yakobu, im trying to get to 100 subs
Bas_tet [7]

Answer:

ummm sure I guess but just let me know if u got any problem or questions

7 0
2 years ago
If you are connected to a network that uses DHCP, and you need to terminate your Windows workstation's DHCP lease, which command
FromTheMoon [43]

Answer:

IP config/release

Explanation:

6 0
2 years ago
Other questions:
  • A Write about why it is important for a person to upgrade their job skills
    14·1 answer
  • Terminal resource security is a software feature that erases the screen and signs a user off automatically after a specified len
    14·1 answer
  • Suppose that your application uses a loop that isn't producing the intended results. The best way to analyze what’s going on in
    13·1 answer
  • What happens when a flash memory card is installed in a slot and it is recognized by windows?
    6·1 answer
  • Write a function called convert_format which converts the format of a date from mm/dd/yyyy to month name dd, yyyy.
    12·1 answer
  • List two types of energy sources
    10·2 answers
  • Please tell fast plzzzzzzzz​
    11·2 answers
  • A plan budget time for studying and activities is referred to as?
    11·1 answer
  • Write long answer to the following question. a. Define microcomputer. Explain the types of microcomputers in detail.​
    5·2 answers
  • Amogus :0) owo have a good day y'all
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!