Chat with us, powered by LiveChat Exercise 1 [10 points]:  Write a static method named numUnique that acce | Writedemy

Exercise 1 [10 points]:  Write a static method named numUnique that acce

Exercise 1 [10 points]:  Write a static method named numUnique that acce

Exercise 1 [10 points]:

Write a static method named numUnique that accepts an array of integers as a parameter and returns the number of unique values in that array. The array may contain positive integers in no particular order, which means that the duplicates will not be grouped together. For example, if a variable called list stores the following values:

int[] list = {7, 5, 22, 7, 23, 9, 1, 5, 2, 35, 6, 11, 12, 7, 9};

then the call of numUnique(list) should return 11 because this list has 11 unique values (1, 2, 5, 6, 7, 9, 11, 12, 22, 23, and 35). It is possible that the list might not have any duplicates. For example if the list contain this sequence of values:

int[] list = {1, 2, 11, 17, 19, 20, 23, 24, 25, 26, 31, 34, 37, 40, 41}; Then a call to the method would return 15 because this list contains 15 different values.

If passed an empty list, your method should return 0.

Note: It might be beneficial to sort the array before you count the unique elements. To sort an integer array, you can use Arrays.sort() method.

Exercise 2 [10 points]:

In this exercise, you need to complete the following static methods and then use them.

public class Password{

public static boolean passwordValidator(String pass1, String pass2){

// Your code goes here…

}

public static String passwordGenerator(int length){

// Your code goes here

}

}

• The method passwordValidator takes two alpha-numeric passwords and returns true only if all the following conditions are met:

i) Length of the password must be between 8 and 32 characters.

ii) Password should contain at least one upper case and one lower case alphabet. iii)  Password should contain at least two numbers.

iv) Password should contain at least one special character from this list {!, ~, _, %, $, #}.

v) Both the password strings must match.

• The method passwordGenerator – generates and returns a random password that satisfy the above-mentioned criteria with a specified length.

• Now, write a PasswordTester class – in which you should test these static methods.

Here is an example test run:

Enter a new password: test123

Re-enter the same password: test123

Password should contain at least 8 characters.

Enter a new password: qwerty123

Re-enter the same password: qwerty123

Password must contain at least 1 capital letter character.

Enter a new password: qwerTy123

Re-enter the same password: qwerTy123

Password must contain at least 1 special symbol.

Enter a new password: qwerTy_1

Re-enter the same password: qwerTy_1

Password must contain at least 2 numbers.

Enter a new password: qwerTy_12

Re-enter the same password: qwerty_12

Both passwords must match.

Enter a new password: qwerTy_12

Re-enter the same password: qwerTy_12

Success!

The test cases shown above are sample only. When you test your code, you should test it for all possible cases. If the user cannot select a valid password within 7 tries, then your program should suggest four random passwords (with different length) to the user that satisfies all rules for the password.

Take snapshots of different test runs for your program and attach those snapshots during submission.

Exercise 3 [10 Points]:

DateUtil: Complete the following methods in a class called DateUtil:

• boolean isLeapYear(int year): returns true if the given year is a leap year. A year is a leap year if it is divisible by 4 but not by 100, or it is divisible by 400.

• boolean isValidDate(int year, int month, int day): returns true if the given year, month and day constitute a given date. Assume that year is between 1 and 9999, month is between 1 (Jan) to 12 (Dec) and day shall be between 1 and 28|29|30|31 depending on the month and whether it is a leap year.

• int getDayOfWeek(int year, int month, int day): returns the day of the week, where 0 for SUN, 1 for MON, …, 6 for SAT, for the given date. Assume that the date is valid.

• String toString(int year, int month, int day): prints the given date in the format “xxxday d mmm yyyy”, e.g., “Tuesday 14 Feb 2012”. Assume that the given date is valid.

To find the day of the week (Reference: Wiki “Determination of the day of the week”):

1. Based on the first two digit of the year, get the number from the following “century” table.

1700- 

1800- 

1900- 

2000- 

2100- 

2200- 

2300- 

2400- 

4

2

0

6

4

2

0

6

2. Take note that the entries 4, 2, 0, 6 repeat.

3. Add to the last two digit of the year.

4. Add to “the last two digit of the year divide by 4, truncate the fractional part”.

5. Add to the number obtained from the following month table:

6. Add to the day.

7. The sum modulus 7 gives the day of the week, where 0 for SUN, 1 for MON, …, 6 for SAT.

For example: 2012, Feb, 17

(6 + 12 + 12/4 + 2 + 17) % 7 = 5 (Fri)

The skeleton of the program is as follows:

/* Utilities for Date   Manipulation */ public class DateUtil {

// Month’s name – for printing public static String   strMonths[]

= {“Jan”, “Feb”,   “Mar”, “Apr”, “May”, “Jun”,

“Jul”, “Aug”,   “Sep”, “Oct”, “Nov”, “Dec”};

// Number of days in each month (for non-leap years) public static int   daysInMonths[]

= {31, 28, 31, 30, 31,   30, 31, 31, 30, 31, 30, 31};

Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

Do you need an answer to this or any other questions?

About Writedemy

We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.

How It Works

To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Are there Discounts?

All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.

Hire a tutor today CLICK HERE to make your first order