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
1-5. Discuss briefly the function and benefits of computer network. (5pts​
Elden [556K]

Computer networks allow an unlimited amount of computers to communicate with each other. This is especially useful in enterprise environments, as technicians have to deal with hundreds of computers at a time. Computer networks make it easier to share files, increase storage capacity, better communication, easier to to control computers remotely, easier to share resources, ability to share a single internet connection on multiple devices. Computer networks also have a lot of cost benifits too, as network administration is centralised, meaning that less IT support is required, and you can cut costs on sharing peripherals and internet access.

Hopefully this helps you out!

7 0
3 years ago
Scott does not use privacy settings on his social media
likoan [24]

Answer:

ARREST HIM!!!

Explanation:

7 0
3 years ago
Read 2 more answers
A system administrator is selecting an operating system for use by the company’s research and development team. The team require
tekilochka [14]

Answer:

Linux

Explanation:

Linux is the open source operating system that can be modified at any time as per requirement of the client or user.

5 0
3 years ago
How good are vw beetle heaters in winter?
Vinvika [58]
It depends on the heater but in most case it works pretty well
7 0
3 years ago
Which of the following items is not found on a web page?
navik [9.2K]
The answer is B. book mark definitely
7 0
3 years ago
Other questions:
  • What should you do if a dialog box covers an area of the screen that you need to see?
    10·2 answers
  • 30 POINTS! PLEASE ANSWER QUICK!!!
    12·1 answer
  • Which of the following components helps to limit the front-to-back movement of the crankshaft? 
    9·2 answers
  • If number is 20, what is printed to the console after this code is executed?
    13·1 answer
  • Can any one help me please with my computer science hwk :)
    11·1 answer
  • Based on what you know about the Sort and Find functions, return to the database file to determine the answers to the following
    7·2 answers
  • Your design company needs to create a sample animation for a client very quickly. You already have the basic graphics, and the c
    10·1 answer
  • Body LanguageWhat are the nonverbal communications mentioned in the video? And how the video explained the meaning of these?
    15·1 answer
  • Why is nigeria no<br>t in the country list​
    6·2 answers
  • A database admin uses a SHOW statement to retrieve information about objects in a database. This information is contained in a _
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!