Q1. [Expected Time: 10 Mins]
Complete the methods of following class Q1 as per commented specification
class Q1
{
public static boolean nameExists(String[] nameList, String name)
{
/*
This method returns true or false depending upon whether name exists in nameList or not. If any of the passed parameter is null or length of any passed parameter is zero then it returns false.
*/
}// End of method nameExists
public static String getLongestCommonWord(String[] nameList1, String[] nameList2)
{
/*
This method returns the longest common word (highest length) from nameList1 and nameList2. Assume each element of nameList1 and nameList2 is a word. If any of the passed parameter is null or the length of any passed parameter is zero then it returns null. If more than one common word has the same highest length then it can return any one of them. If there does not exist any common word then it returns empty String.
*/
}// End of method getLongestCommonWord()
}// End of class Q1
[3+7=10 M]
Q2. [Expected Time: 20 Mins]
(a)
Consider a classes named ‘Address’ which encapsulates the address of any particular person having attributes as : – line1 : String , – line2 : String, – line3 : String , – city : char[] , – state : char[] and – pin : String . The class supplies only one parameterized constructor which receives only one parameter of type String which embeds the values of all the attributes in $ separated form as per following format:
“line1$line2$line3$city$state$pin”
$ Character is used as a separator to separate the values of line1, line2, line3, city, state and pin attributes. The class supplies accessor methods for every instance field. All accessor methods return only String type value. Implement the Address class in java as per mentioned specification.
(b)
Considering the availability of the code of class Address of Q2(a) in this question, complete the implementation of the following class named ‘AddressList’ as per commented specification given below
class AddressList
{
public static int countAddressWithCity(Adress[] addressList, String city)
{
/*
This method returns the count of the addresses from addressList which have the city attribute equals to city parameter passed for this method. If the length of any passed argument is zero or value of any passed argument is null then it returns -1.
*/
}// End of method countAddressWithCity()
public static int countAddressWithPin(Adress[] addressList, String strP)
{
/*
This method returns the count of the addresses from addressList which have the pin attribute starting with strP parameter passed for this method. If the length of any passed argument is zero or value of any passed argument is null then it returns -1.
*/
}// End of method countAddressWithCity()
public static Address[] getAddressWithCity(Adress[] addressList, String city)
{
/*
This method returns all the addresses from addressList by storing them in String[] which have the city attribute equals to city parameter passed for this method. If the length of any passed argument is zero or value of any passed argument is null then it returns null. If addressList does not contain any address with city attribute value equal to city parameter passed for this method even then it returns null.
*/
}// End of method getAddressWithCity()
public static Address[] getAddressWithPin(Adress[] addressList, String strP)
{
/*
This method returns all the addresses from addressList by storing them in String[] which have their pin attribute starting with strP parameter passed for this method. If the length of any passed argument is zero or value of any passed argument is null then it returns null. If addressList does not contain any address whose pins attribute value starts with strP parameter passed for this method even then it returns null.
*/
}// End of method getAddressWithCity()
}// End of class AddressList
[4+4+6+6=20M]
Q3. [Expected Time: 15 Mins]
(a)
Consider an abstract class named ‘Auto’ with instance fields as: # make : int and #price : double. The class provides parameterized constructor which receives the values for make and price of the car. The class supplies accessor and mutator methods for every instance field. Every mutator method in the class is only having method declaration not implementation. The Auto class has two concrete sub classes named ‘Maruti’ and ‘Honda’. Each of the subclass has an additional attribute as: # color: int (only three possible colors: 1 for white, 2 for blue and 3 for black). Each of the sub classes have their own parameterized constructors and the subclasses also supply a suitable toString() method which after concatenation returns the value(s) of instance fields with proper headings.
Write the implementations of classes Auto, Maruti and Honda in java as per above specification.
(b)
Write a driver class named ‘AutoTest’ for the ‘Auto’ class of Q3(a). This class performs the following tasks in order:
(i) Instantiates two instances of type Auto named auto1 and auto2 referring to Maruti and Honda type of objects respectively. [Assume any arbitrary values for attributes]
(ii) Display the price of auto1 and auto2 (i.e. instances created above) on System.out.
(iii) Print the details of auto1 and auto2 on System.out.
[10+5=15M]
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more