Question

Need Help Please Using Java Language Create a Code Write a class (and a client class...

Need Help Please

Using Java Language

Create a Code

Write a class (and a client class to test it) that encapsulates the evolution of the passwords of three students over four months. Your only instance variable should be a two-dimensional array of values representing the passwords. Dimension 1 represents the student and dimension 2 represents the month. (Since we are concerned about security, we are assuming that people change their password once a month; we only care about the value of the password at the end of a given month.) Your constructor can simply take a single-dimensional array of words representing the 12 passwords; they can be assigned to the two-dimensional array elements one at a time, starting with the first row. You should include the following methods:

❑ a method returning the index of the person who changed his or her password the most times

❑ a method returning the longest password❑ a method changing all the passwords to “unlock”

❑ a method returning true if at least one person had a given word—the method’s parameter—as his/her password in at least one month; false otherwise

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Source Code in Java:

class Password
{
String pass[][]; //instance variable
Password(String passwords[]) //parametrized constructor
{
pass=new String[3][4]; //initializing 2D array
for(int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
pass[i][j]=passwords[i*4+j]; //storing names from the parameter array
}
}
int mostChanges() //method to return index of student with most changes in password
{
int max=0,index=0; //setting max index to 0 initially
for(int j=0;j<4-1;j++) //finding out changes for first index and setting it to max
{
if(pass[0][j].equals(pass[0][j+1])==false)
max++;
}
//finding out changes for rest of the indexes and comparing to temporary max
for(int i=1;i<3;i++)
{
int count=0;
for(int j=0;j<4-1;j++)
{
if(pass[i][j].equals(pass[i][j+1])==false)
count++;
}
if(count>max)
{
max=count;
index=i;
}
}
return index; //returning index with most changes
}
String largestPassword() //method to find and return the largest password
{
String largest=pass[0][0]; //storing first password as largest temporarily
for(int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
{
if(pass[i][j].length()>largest.length())
largest=pass[i][j];
}
}
return largest; //returning largest password
}
void changeToUnlock() //method to change all passwords to unlock
{
for(int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
pass[i][j]="unlock"; //changing all passwords in 2D array to "unlock"
}
}
boolean isPresent(String word) //method to check if a word was a password
{
for(int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
{
if(pass[i][j].equals(word)) //checking every word
return true;
}
}
return false; //if program reaches this point, word was not found
}
}

class PasswordTest
{
public static void main(String args[])
{
//testing class Password
String passwords[]={"climate","climate","change","hiboys","lolitsme","lolitsstillme","lolitsnotme","heyboys","password123","password123","password123","password123"};
Password p=new Password(passwords);
System.out.println("Index of student with most changes: "+p.mostChanges());
System.out.println("Largest password: "+p.largestPassword());
p.changeToUnlock();
System.out.println("Largest password after changing all to unlock: "+p.largestPassword());
}
}

Output:

Blue): Terminal Window - Java Assignment Options Index of student with most changes: 1 Largest password: lolitsstillme Larges

Add a comment
Know the answer?
Add Answer to:
Need Help Please Using Java Language Create a Code Write a class (and a client class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design and implement a Java class (name it Summer Stats. java) that tracks statistics for summer...

    Design and implement a Java class (name it Summer Stats. java) that tracks statistics for summer job salaries for a group of people over several years. The only data field you need is a 2-Dimenssional array of values representing salaries. The rows the represents the people and the columns represent the years. The constructor method takes two integers representing the number of people and the number of years, then randomly generates the annual salaries and fills the array. Other class...

  • Write code in Java programming language. The ShoppingCart class will be composed with an array of...

    Write code in Java programming language. The ShoppingCart class will be composed with an array of Item objects. You do not need to implement the Item class for this question, only use it. Item has a getPrice() method that returns a float and a one-argument constructor that takes a float that specifies the price. The ShoppingCart class should have: Constructors: A no-argument and a single argument that takes an array of Items. Fields: • Items: an array of Item objects...

  • Design and implement a Java class (name it SummerStats.java) that tracks statistics for summer job salaries...

    Design and implement a Java class (name it SummerStats.java) that tracks statistics for summer job salaries for a group of people over several years. The only data field you need is a 2-Dimenssional array of values representing salaries. The rows the represents the people and the columns represent the years. The constructor method takes two integers representing the number of people and the number of years, then randomly generates the annual salaries and fills the array. Other class methods include...

  • Note: According to the question, please write source code in java only using the class method....

    Note: According to the question, please write source code in java only using the class method. Sample Run (output) should be the same as displayed in the question below. Make sure the source code is working properly and no errors. Exercise #2: Design and implement a program (name it compareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array...

  • Write Java code to implement a FSM machine that recognizes the language for the alphabet {a,b,c} ...

    Write Java code to implement a FSM machine that recognizes the language for the alphabet {a,b,c} consisting of all strings that contain two consecutive c's and end with b.                   Your FSM program should include the following three static methods (Java) or functions (C):                                           a.    int nextState(int state, char symbol)                                  A state-transition function that returns the next state based on the                                  current state and an input symbol. This function should also return                                  -1 when an invalid input character is detected.                                  State...

  • JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class....

    JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class. Print out the results after testing each of the methods in both of the classes and solving a simple problem with them. Task 1 – ArrayList Class Create an ArrayList class. This is a class that uses an internal array, but manipulates the array so that the array can be dynamically changed. This class should contain a default and overloaded constructor, where the default...

  • Implement a Java class that is called RainFall that uses a double array to store the...

    Implement a Java class that is called RainFall that uses a double array to store the amount of rainfall for each month of the year. The class should have only one instance variable of type double[]. Implement the following methods in the RainFall class: 1. A constructor that creates and initializes all entries in the array to be -1. 2. toString: a method that returns a one-line String representation of the object that includes 12 double numbers that represent the...

  • Please help me with this code. Thank you Implement the following Java class: Vehicle Class should...

    Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...

  • In Java programming language Please write code for the 6 methods below: Assume that Student class...

    In Java programming language Please write code for the 6 methods below: Assume that Student class has name, age, gpa, and major, constructor to initialize all data, method toString() to return string reresentation of student objects, getter methods to get age, major, and gpa, setter method to set age to given input, and method isHonors that returns boolean value true for honors students and false otherwise. 1) Write a method that accepts an array of student objects, and n, the...

  • Create a simple Java class for a Month object with the following requirements:  This program...

    Create a simple Java class for a Month object with the following requirements:  This program will have a header block comment with your name, the course and section, as well as a brief description of what the class does.  All methods will have comments concerning their purpose, their inputs, and their outputs  One integer property: monthNumber (protected to only allow values 1-12). This is a numeric representation of the month (e.g. 1 represents January, 2 represents February,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT