Java | JSP | JSF Answers

Questions: 4 418

Answers by our Experts: 3 943

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Task #5: Writing value returning Method

In this task, you are being asked to write value returning method in Java.

Your job is to write a program which will take two integer numbers as input and returns:

 0, if both numbers are equal.

 1, if first number is greater than second number.

 -1, if first number is less than second number. 

You may use the following header for this method:

static int compare(int firstNumber, int secondNumber)

Take input from the user, call the method and print the appropriate messages according to the 

result.

1. Create a program called CompareNumberLab1.java. 

2. Create appropriate variables and assign values using a Scanner object.

3. Correctly display appropriate messages.s


Task #4: Writing value returning Methods


In this task, you are being asked to write value returning methods in Java.


Write a method called charAtPosition() that accepts two arguments: a String object, and a 


positive integer. It then returns the character located at position given by the integer argument.


You may use the following header for this method:


static char charAtPosition(String word, int position)


For example, if the method is called with the arguments, "GIFT University" and 5, the method 


returns the character ‘U’ and a sample output should be:


Character at position 5 is: U


NOTE: A String starts from character position 0. Also, perform input validation so that the 


position must be greater than or equal to 0.


HINT: Use the charAt(index) method of the String to find the character in a String. 


1. Create a program called CharacterPositionLab1.java. 


2. Correctly call the method with appropriate arguments. 


3. Correctly display appropriate messages.


Task #3: Writing void Methods




In this task, you are being asked to write void methods in Java.




Write a method called printTable() that accepts three positive integer arguments, and then prints




the table of the number from the starting number to the ending number.




You may use the following header for this method:




static void printTable(int number, int start, int end)




NOTE: Perform input validation so that all numbers must be greater than 0 and the “start” number




should be less than “end” number.




1. Create a program called TablesLab1.java.




2. Create appropriate variables and assign values using a Scanner object.




3. Correctly display appropriate messages.

In this task, you are being asked to write void methods in Java.

Write a method called wordsInfo() that accepts one String argument, and prints how many

characters are there in that argument, as well as the number of vowels.

You may use the following header for this method:

static void wordsInfo(String word)

For this exercise, assume that a e i o u y are vowels. For example, if the method is called with an

argument "Harry", the method prints:

wordsInfo(“Harry”);

//method prints

5 characters.

2 vowels.

1. Create a program called CharactersLab1.java

2. Create appropriate variables and assign values using a Scanner object.

3. Correctly display appropriate messages.


You will need to create a class FamilyMember with the required attributes i.e. names (String), role (String), gender (char), and age (int). Provide the constructor and getters and setters.

You will also need to create a class Family that will contain a collection (ArrayList) for family member instances. Provide appropriate constructor. Provide methods addFamilyMember (name, role, gender and age) that adds a member to the collection. You will call this method at an appropriate place in the GUI layer

Provide another method getAllMembers() that returns an array containing all instances of family members in this collection. You will call this method at an appropriate place in the GUI 


Write a program to store 15 numbers in an array. Then display all two digits number in ascending order using sorting and also display how many such numbers found.


Write a program to store 15 numbers in an array. Then display all negative numbers in ascending order using sorting.


do while loop



2. Write a java program that reads in a list of int values one per line



and outputs their sum as well as the numbers read with each number.



Your programs will ask the user how many integers there will be, and



fill the table with the integers input.



Sample output:



How many numbers will you enter?



2



Enter 2 integers one per line:



20



30



The sum is 50

do while loop



Sample output:



1. Write a program that asks the user for a starting value and an ending



value and then writes all the integers (inclusive) between those two values.



Enter Start:



10



Enter End:



15



10



11



12



13



14



15



Sum of in range values: 75

while loop


sample output


a. 20 5 16 4 12 3 8 2 4 1



LATEST TUTORIALS
APPROVED BY CLIENTS