java
java
java
Given three strings say Searchstring, Strl and Str2 as input, write a program to find out if Str2 comes
after Strl in the Searchstring.
Include a class UserMalnCode with a static method strlngFlnder that accepts 3 String arguments
and returns an integer. The 3 arguments correspond to Searchstring, Strl and Str2. The function
returns 1 if Str2 appears after Strl in the Searchstring. Else it returns 2. Create a class Main which
would get 3 Strings as input and call the static method stringfinder present in the UserMainCode.
Ma in.java
Name Shrinking
Write a program that accepts a string as input and converts the first two names into dotseparated
initials and print the output. Input string format is 'fn mn In'. Output string format is 'In [mn's 1st
character] .[fn's 1st character]'.
Include a class UserMalnCode with a static method getformatedStrlng which accepts a string. The
return type (String) should return the shrinked name. Create a Class Main which would be used to
accept Input String and call the static method getFormatedStrlng present in UserMalnCode.
Sample Input:
Sachin Ramesh Tendulkar
Sample Output:
Tendulkar R.S
Ma in.java
. por t Java
1m . . ut 1· 1 . * ;
UserMainCode . java
Digits - II
Write a program to read a non-negative integer n, compute the sum of its digits. If sum is greater
tha n 9 repeat the process and calculate the sum once again until the final sum comes to single digit.
Return the single digit.
Include a class UserMalnCode with a static method getDlgltSum which accepts the integer value.
The return type is integer. Create a Class Main which would be used to accept the string and call the
static method getDlgltSum present in UserMalnCode.
Ma in.lava
UserMa lnCode.lava
Max Substring
Write a program to accept two string Inputs. The first being a source string and second one a
deli miter. The source string contains the delimiter at various locations. Your Job Is to return the
substring w ith maximum number of characters. If two or more substrings have maximum number
of characters return the substring which appears first. The size of the delimiter Is 1.
Include a class UserMalnCode with a static method extractMax which accepts the string. The return
type (string) should be the max substring. Create a Class Main which would be used to accept Input
string and call the static method extractMax present in UserMalnCode.
Main.lava
import java.util . *;
UserMainCode.java
import java.util.*;
Date Validation
Write a program to read a string representing a date. The date can be in any of the three formats
1:dd-MM-yyyy 2:dd/MM/yyyy 3:dd.MM.yyyy. If the date is valid, print valid else print invalid.
Include a class UserMainCode with a static method getValidDate which accepts a string. The return
type (integer) should be based on the validity of the date. Create a class Main which would be used
to accept Input string and call the static method getValidDate present in UserMainCode.
UserMainCode.java
import java . text . ParseException;
import java . text . SimpleDateFormat ;
import java . util . Date;
Grade Calculator I
A School wants to give assign grades to its students based on their marks. You have been assigned
as the programmer to automate this process. You would lik.e to showcase your skills by creating a
quick prototype.
The prototype consists of the following steps:
Read student details from the User. The details w ould include name, m ark in the given order. The
datatype for name is string. mark is float. You decide to build a hashmap. The hashmap contains
name as key and mark as value.
BUSINESS RULE:
1. If Mark is less than 60, then grade is FAIL.
2. If Mark is greater than or equal to 60, then grade is PASS.
Note: FAIL/PASS should be In uppercase.
Store the result In a new HashMap w ith name as Key and grade as Value. You decide to write a
fu nction calculateGrade which takes the above HashMap as Input and returns the HashMap as
output. Include this function in class UserMalnCode. Create a class Main which would be used to
read student details In step 1 and build the hashmap. canthe stat ic method cakulateGrade present
In UserMalnCode.
Sample Input 1:
3
Avi
76.36
Sunil
68.42
Raj a
36.25
Sample Output 1:
Avi
PASS
Sunil
PASS
Raj a
FAIL
Maln.java
UserMainCode.java
publi c cl as s UserMainCode {
publ ic static Map<String, String>
calculateGrade(Map <String, Float > input ) {
Map<String, String> output = new LinkedHashMap <>();
for (Map . Entry <String, Float > me : input . entrySet ()) {
if (me . getValue () < 60) {
output . put (me . getKey (), "FAIL" );
} else {
output . put (me . get Key (), "PASS" );
}
}
return output ;
}
}