Question

WRITE A JAVA PROGRAM (WILL GUARANTEE A THUMBS UP) BELOW IS WHAT SHOULD BE INCLUDED IN...

WRITE A JAVA PROGRAM (WILL GUARANTEE A THUMBS UP)

BELOW IS WHAT SHOULD BE INCLUDED IN THE CODE:

Map m1 = new HashMap();

m1.put("firstName","f1");

m1.put("lastName","l1");

m1.put("middleName","m1");

Map m2 = new HashMap();

m2.put("firstName","f2");

m2.put("lastName","l2");

m2.put("middleName","m2");

BELOW IS THE EXPECTED OUTPUT IF GETTING ALL THE VALUES FROM THE INPUT:

String strOut = [f1.l1.m1][email protected];[f2.l2.m2][email protected]

BELOW IS THE EXPECTED OUTPUT IF LAST NAME IS NULL:

String strOut = [f1.m1][email protected];[f2.m2][email protected]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

package mis1;

import java.util.HashMap;

import java.util.Map;

import java.util.Set;

import java.util.stream.IntStream;

public class Driver {

public static void print(Map m1){

String strOut="["; //make string with [

Set<String> keys=m1.keySet(); //get all the keys here in set

int i=1;

for(String s:keys){ //go through all they key

if(i==keys.size()) { //if this the last

if(m1.get(s)!=null) //if value if not null

strOut+=m1.get(s)+"]"; //as per example put ] along with value of that key

}

else{

if(m1.get(s)!=null) //if value if not null

strOut+=m1.get(s)+".";//value of that key

}

i++;

}

i=1;

for(String s:keys){ //this for the second part of they string

if(i==keys.size())

strOut+=m1.get(s)+"@abc.com";

else{

strOut+=m1.get(s)+".";

}

i++;

}

System.out.print(strOut);

}

//this method will print both m1 and m2

public static void print(Map m1,Map m2){

//call print tow times

print(m1);

System.out.print(";");

print(m2);

System.out.println("");

}

//driver program to test

public static void main(String[] args) {

Map m1 = new HashMap();

m1.put("firstName","f1");

m1.put("lastName","l1");

m1.put("middleName","m1");

Map m2 = new HashMap();

m2.put("firstName","f2");

m2.put("lastName","l2");

m2.put("middleName","m2");

print(m1,m2);

m1 = new HashMap();

m1.put("firstName","f1");

// m1.put("lastName","l1");

m1.put("middleName","m1");

m2 = new HashMap();

m2.put("firstName","f2");

m2.put("lastName","l2");

m2.put("middleName","m2");

print(m1,m2);

}

}

output

[f1.l1.m1][email protected];[f2.l2.m2][email protected]

[f1.m1][email protected];[f2.l2.m2][email protected]

Add a comment
Know the answer?
Add Answer to:
WRITE A JAVA PROGRAM (WILL GUARANTEE A THUMBS UP) BELOW IS WHAT SHOULD BE INCLUDED IN...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • WRITE A JAVA PROGRAM . (WILL GUARANTEE A THUMBS UP) BELOW ARE INSTRUCTIONS: IF USER ENTERS:...

    WRITE A JAVA PROGRAM . (WILL GUARANTEE A THUMBS UP) BELOW ARE INSTRUCTIONS: IF USER ENTERS: "1, 2, 3" THIS IS THE Expected Output: 1,1,2,2,3,3

  • I have currently a functional Java progam with a gui. Its a simple table of contacts...

    I have currently a functional Java progam with a gui. Its a simple table of contacts with 3 buttons: add, remove, and edit. Right now the buttons are in the program but they do not work yet. I need the buttons to actually be able to add, remove, or edit things on the table. Thanks so much. Here is the working code so far: //PersonTableModel.java import java.util.List; import javax.swing.table.AbstractTableModel; public class PersonTableModel extends AbstractTableModel {     private static final int...

  • (JAVA) I need to write an accessor method for the employeeDatabase field. The method is supposed...

    (JAVA) I need to write an accessor method for the employeeDatabase field. The method is supposed to be named getEmployeeDatabase() and have a return type of Hashmap<Integer,Employee>. I have also included the test case below that is being used for this code to see if it works properly private HashMap<Integer, Employee> employeeDatabase; public CompanyO f Scanner employeeDatabasepopulateEmployeeDatabase(keyboard) keyboard - new Scanner(System.in); public static void main(String[ args) private HashMap<Integer, Employee> populateEmployeeDatabase(Scanner keyboard) int numobjects -keyboard.nextIntO; String words HashMap <Integer, Employee mapnew...

  • Convert Hex To Dec in java with HashMap and put in .txt file I'm making a...

    Convert Hex To Dec in java with HashMap and put in .txt file I'm making a compiler for assembler in JAVA. My program after several processes leaves a text file as follows. 02TLIGHT2.ASM file with this: CLO Start: MOV AL,0 OUT 01 MOV AL,FC OUT 01 JMP Start END Im trying by means of my hashmap convert the commands to his assigned hexadecimal value and put it in a text file? The output of my actual program in a 02TLIGHTHexa.ASM...

  • java only no c++ Write a Fraction class whose objects will represent fractions. You should provide...

    java only no c++ Write a Fraction class whose objects will represent fractions. You should provide the following class methods: Two constructors, a parameter-less constructor that assigns the value 0 to the Fraction, and a constructor that takes two parameters. The first parameter will represent the initial numerator of the Fraction, and the second parameter will represent the initial denominator of the Fraction. Arithmetic operations that add, subtract, multiply, and divide Fractions. These should be implemented as value returning methods...

  • Write a C++/Java program to solve the problem below using Memoization: Problem Definition: Theres a theif...

    Write a C++/Java program to solve the problem below using Memoization: Problem Definition: Theres a theif that enters a store during the night,and upon his entrance,the stores security systems detects the theif and the alarm goes off.The theif knows that theres a hidden door at the corner of this store and in order to escape,he has to get to it.Since the theif has limited time for his burglary,he can only Rob the stuff he comes by on his path towards...

  • Please create a class in Java that completes the following conditions MorseTree.java /* This program will...

    Please create a class in Java that completes the following conditions MorseTree.java /* This program will read in letters followed by their morse code * and insert them properly in a tree based on the amount of symbols * it has and whether they are left or right descendent. Finally * it prints a few certain nodes. */ import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class MorseTree {    public static void main(String[] args) throws FileNotFoundException {        //...

  • Create a java class Customer.java that will represent a water company customer. It should contain the...

    Create a java class Customer.java that will represent a water company customer. It should contain the attributes, constructors, and methods listed below, and when finished should be able to allow the included file TestWaterBills.java to work correctly. Customer class Attributes firstName: String type, initial value null lastName: String type, initial value null streetAddress: String type, initial value null city: String type, initial value null state: String type, initial value null zip: String type, initial value null previousMeterReading: int type, initial...

  • (Java) Rewrite the following exercise below to read inputs from a file and write the output...

    (Java) Rewrite the following exercise below to read inputs from a file and write the output of your program in a text file. Ask the user to enter the input filename. Use try-catch when reading the file. Ask the user to enter a text file name to write the output in it. You may use the try-with-resources syntax. An example to get an idea but you need to have your own design: try ( // Create input files Scanner input...

  • This is a java homework for my java class. Write a program to perform statistical analysis...

    This is a java homework for my java class. Write a program to perform statistical analysis of scores for a class of students.The class may have up to 40 students.There are five quizzes during the term. Each student is identified by a four-digit student ID number. The program is to print the student scores and calculate and print the statistics for each quiz. The output is in the same order as the input; no sorting is needed. The input is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT