Reference no: EM133390170
PROBLEM 1
Write a Java method that takes an array of type int and a variable of type int. The method returns true if the sum of values in the array is evenly divisible by the second argument in the method, otherwise, the method returns false.
The method header is as follows.
public static boolean threshold(int[ ] x, int y)
Sample run
|
Result
|
Consideration
|
int[ ] x = {1, 2, 3};
boolean b = threshold(x, 3);
|
true
|
The remainder of 6 divided by 3 is zero
|
int[ ] x = {8, 8, 8, 8};
boolean b = threshold(x, 8);
|
true
|
The remainder of 32 divided by 8 is zero
|
int[ ] x = {5, 2, 4, -3};
boolean b = threshold(x, 5);
|
false
|
The remainder of 8 divided by 5 is 3
|
PROBLEM 2
Write a Java method that takes a variable of type String and returns a value of type boolean. The method returns true if the parameter string contains a valid password, and false otherwise. A valid password should satisfy all the following conditions:
• It can contain only hexadecimal digits (hexadecimal digits are the values 0 to 9 and the characters a to f)
• Its length is larger than or equal to 9 characters
• It starts with a decimal digit (0 to 9).
The method's header is as follows.
public static boolean password(String s)
Sample Run
|
Result
|
String s = "8abc93def0";
boolean b = password(s);
|
true
|
String s = "abcde189715";
boolean b = password(s);
|
false
|
PROBLEM 3
Write the following class: Person.
Details
Class Person is to have the following data members: firstName of type String, lastName of type String representing a person's first and last names and ssn of type int representing a social security number. Each data member has an access specifier of type private.
Implementation
Class Person is to have two constructors with the following specifications:
a no-arg constructor that initializes each String to an empty String and the integer data member to zero;
a constructor that takes three arguments, each representing one of the class data members. The arguments are to be listed in the order of (firstName, lastName, ssn);
Class Person is to have standard get/set methods for each data member.
Class Person is to have a method named equals(Person other ) method to do the following:
determine if the calling object and the parameter object (other) store identical data values for the corresponding data members (firstName, lastName, ssn)
Class Person is to have a method named display( ) that displays the following information in the format presented:
First Name: display firstName data
Last Name: display lastName data
SSN: display ssn data