Include a class UserMainCode with a static methodremoveDuplicateswhich accepts a string. The return type is themodified sentence of type string.Create a Class Main which would be used to accept the input string and call the static method present in UserMainCode.Input and Output Format:Input consists of a string with maximum size of 100 characters.Output consists of a single string.Refer sample output for formatting specifications.Sample Input 1:hi this is sample testSample Output 1:hi tsampleSample Input 2:ABC DEFSample Output 2:ABC DEFimport java.util.HashSet;import java.util.Iterator;import java.util.LinkedHashSet;import java.util.StringTokenizer;public class Main {public static void main(String[] args) {
String s1="hi this is sample test";getvalues(s1);}public static void getvalues(String s1) {char a[]=s1.toCharArray();StringBuffer sb=new StringBuffer();LinkedHashSet<Character>hs=new LinkedHashSet<Character>();for(int i=0;i<a.length;i++){hs.add(a[i]);}Iterator<Character>itr=hs.iterator();while(itr.hasNext()){char o=itr.next();if(o!=' ');{sb.append(o);}}System.out.println(sb);}}8.Mastering HashmapYou have recently learnt about hashmaps and in order to master it, you try and use it in all of your programs.Your trainer / teacher has given you the following exercise:1.Read 2n numbers as input where the first number represents a key and second one as value. Both the numbers areof type integers.2.Write a functiongetAverageOfOddto find out average of all values whose keys are represented by odd numbers.Assume the average is an int and never a decimal number. Return the average as output. Include this function inclass UserMainCode.Create a Class Main which would be used to read 2n numbers and build the hashmap. Call the static method present inUserMainCode.Input and Output Format:Input consists of a 2n+ 1 integers. The first integer specifies the value of n (essentially the hashmap size). The next pair of nnumbers denote the key and value.Output consists of an integer representing the average.Refer sample output for formatting specifications.Sample Input 1:423414512422Sample Output 1:8import java.util.HashMap;import java.util.Scanner;public class kapes3{public static void main(String args[]){Scanner sc=new Scanner(System.in);int n=sc.nextInt();HashMap<Integer,Integer> h1=new HashMap<Integer,Integer>();for(int i=0;i<n;i++){h1.put(sc.nextInt(),sc.nextInt());}System.out.println(UserMainCode.display(h1));}}
import java.util.HashMap;import java.util.Iterator;public class UserMainCode {public static int display(HashMap<Integer,Integer>h1){int av=0,c=0,s=0;Iterator<Integer> it=h1.keySet().iterator();while(it.hasNext()){int a=it.next();if(a%2!=0){int b=h1.get(a);s=s+b;c++;}}av=s/c;return av;}}9.Managers & HashmapsA Company wants to automate its payroll process. You have been assigned as the programmer to build this package. Youwould like to showcase your skills by creating a quick prototype. The prototype consists of the following steps:1.Read Employee details from the User. The details would include id, designation and salary in the given order. Thedatatype for id is integer, designation is string and salary is integer.
Upload your study docs or become a
Course Hero member to access this document
Upload your study docs or become a
Course Hero member to access this document
End of preview. Want to read all 239 pages?
Upload your study docs or become a
Course Hero member to access this document
Term
Summer
Professor
N/A
Tags