SlideShare une entreprise Scribd logo
1  sur  3
Télécharger pour lire hors ligne
This is a java program. PLEASE WRITE THIS IN JAVA AND FOLLOW ALL THE
INSTRUCTIONS. THERE SHOULD BE A Tester.java class
Objective: Practice using maps. All the methods you write for this should be marked static and
called from the main(..). Note: none of these exercises have you mutate the input map (you will
always be returning a copy of the given map with the requested modifications made).
Note 1: you'll only need put(..), containsKey(..), get(..), and remove(..) for all of these methods
(there are fancier map methods, though I'll leave these to you to look up for research)
Note 2: sample inputs and outputs are included with each method, the ordering of the (key, value)
pairs in the returned map might vary.
Note 3: java prints maps like this: {a=cat, b=dog}
-in our notation, this is: { (a, cat), (b, dog) }
Question 1: bullyReplace (no loops needed for this one)
Write a static method called bullyReplace that takes a Map<String, String> m as a parameter and
returns a Map<String, String>. The method should create a copy of the input map m and return the
copied map with the following changes made:
--> if the key "a" has a value, set the key "b" to have that value, and set the key "a" to have the
value "". Basically "b" is a bully, taking the value and replacing it with the empty string.
Some input-output examples:
--> bullyReplace( {("a", "candy"), ("b", "dirt")} )
--> should return: { ("a", ""), ("b", "candy") }
--> bullyReplace( {("a", "candy")} )
--> should return: { ("a", ""), ("b", "candy") }
--> bullyReplace( {("a", "candy"), ("b", "carrot"), ("c", "meh")
-should return: { ("a", ""), ("b", "candy"), ("c", "meh") }
Here's some starter code for the method to get you going (you'll have similar setup code for the
remaining methods):
Question 2: toppings (no loops needed for this one)
Write a static method named toppings that takes a Map<String, String> m and returns a
Map<String, String>. The method should create a copy of the input map m and return the copied
map with the following changes made:
-->if the key "ice cream" is present, set its value to "cherry". In all cases, set the key "bread" to
have the value "butter".
Some examples:
--> toppings( {("ice cream", "peanuts")} )
-should return: { ("bread", "butter"), ("ice cream", "cherry") }
-->toppings( {} )
-should return: { ("bread", "butter") }
-->toppings( {("pancake", "syrup")} )
-should return: {("bread", "butter"), ("pancake", "syrup")}
Question 3: mapShare (no loops needed for this one)
Write a static method named mapShare that takes a Map<String, String> m and returns a
Map<String, String>. The method should create a copy of the input map m and return the copied
map with the following changes made:
-->if the key "a" has a value, set the key "b" to have that same value. In all cases remove the key
"c", leaving the rest of the map unchanged.
Some examples:
-->mapShare({("a", "aaa"), ("b", "bbb"), ("c", "ccc")})
-should return: {("a", "aaa"), ("b", "aaa")}
-->mapShare({("b", "xyz"), ("c", "ccc")})
-should return: {("b", "xyz")}
-->mapShare({("a", "aaa"), ("c", "meh"), ("d", "hi")})
-should return: {("a", "aaa"), ("b", "aaa"), ("d", "hi")}
Question 4: mapAB (no loops needed for this one)
Write a static method named mapAB that takes a Map<String, String> m and returns a
Map<String, String>. The method should create a copy of the input map m and return the copied
map with the following changes made:
--> for this problem the returned map may or may not contain the "a" and "b" keys. If both keys are
present, append their 2 string values together and store the result under the key "ab".
Some examples:
--> mapAB( {("a", "Hi"), ("b", "There")} )
- should return: {("a", "Hi"), ("ab", "HiThere"), ("b", "There")}
--> mapAB( {("a", "Hi")} )
- should return: {("a": "Hi")}
--> mapAB( {("b", "There")} )
- should return: {("b", "There")}
Question 5: wordCount0 (1 loop needed)
Write a static method, wordCount0, that takes a list of strings and returns a Map<String, Integer>
containing a key for every different string in the input list -- always with the value 0.
Some examples:
-->wordCount0(List.of("a", "b", "a", "b"))
-should return: {(a, 0), (b, 0)}
-->wordCount0(List.of("a", "b", "a", "c", "b"))
-should return: {(a, 0), (b, 0), (c, 0)}
Question 6: wordLen (1 loop needed)
Write a static method, wordLen that takes list of strings as a parameter and returns a Map<String,
Integer> containing a key for every string in the input list, mapped to that string's length.
Some examples:
-->wordLen(List.of("a", "bb", "a", "bb"))
-should return: {("a", 1), ("bb", 2)}
-->wordLen(List.of("this", "and", "that", "and"))
-should return: {("this", 4), ("and", 3), ("that", 4)}
-->wordLen(List.of("code", "code", "code", "bug"))
-should return: {("code", 4), ("bug", 3)}
Question 7: wordMultiple (1 loop needed)
Given a List<String> as a parameter, this method returns a Map<String, Boolean> where each
different string is a key and its value is true if that string appears 2 or more times in the array.
-->wordMultiple(List.of("a", "b", "a", "c", "b"))
-should return: {("a", true), ("b", true), ("c", false)}
-->wordMultiple(List.of("c", "b", "a"))
-should return: {("a", false), ("b", false), ("c", false)}
-->wordMultiple(List.of("c", "c", "c", "c"))
-should return: {("c", true)}
HERE IS A DOWNABLE FILE THAT WAS INCLUDED IN THE ASSIGNMENT. THIS WAS IN THE
JAVA FILE:

Contenu connexe

Similaire à This is a java program PLEASE WRITE THIS IN JAVA AND FOLLOW.pdf

Use C++ for all 1 bool mapContainsKeysarrayltintgt nu.pdf
Use C++ for all  1 bool mapContainsKeysarrayltintgt nu.pdfUse C++ for all  1 bool mapContainsKeysarrayltintgt nu.pdf
Use C++ for all 1 bool mapContainsKeysarrayltintgt nu.pdfadmin447081
 
Hive function-cheat-sheet
Hive function-cheat-sheetHive function-cheat-sheet
Hive function-cheat-sheetDr. Volkan OBAN
 
Datastage real time scenario
Datastage real time scenarioDatastage real time scenario
Datastage real time scenarioNaresh Bala
 
PHP record- with all programs and output
PHP record- with all programs and outputPHP record- with all programs and output
PHP record- with all programs and outputKavithaK23
 
C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribdAmit Kapoor
 
ES6 patterns in the wild
ES6 patterns in the wildES6 patterns in the wild
ES6 patterns in the wildJoe Morgan
 
lecture7.ppt
lecture7.pptlecture7.ppt
lecture7.pptEdFeranil
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Paige Bailey
 
Using-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptxUsing-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptxUadAccount
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuacionesNatalia
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuacionesNatalia
 
Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Bryan O'Sullivan
 

Similaire à This is a java program PLEASE WRITE THIS IN JAVA AND FOLLOW.pdf (20)

Stacks.ppt
Stacks.pptStacks.ppt
Stacks.ppt
 
Stacks.ppt
Stacks.pptStacks.ppt
Stacks.ppt
 
Use C++ for all 1 bool mapContainsKeysarrayltintgt nu.pdf
Use C++ for all  1 bool mapContainsKeysarrayltintgt nu.pdfUse C++ for all  1 bool mapContainsKeysarrayltintgt nu.pdf
Use C++ for all 1 bool mapContainsKeysarrayltintgt nu.pdf
 
2013-June: 3rd Semester E & C Question Papers
2013-June: 3rd Semester E & C Question Papers2013-June: 3rd Semester E & C Question Papers
2013-June: 3rd Semester E & C Question Papers
 
3rd Semester Electronic and Communication Engineering (2013-June) Question P...
3rd  Semester Electronic and Communication Engineering (2013-June) Question P...3rd  Semester Electronic and Communication Engineering (2013-June) Question P...
3rd Semester Electronic and Communication Engineering (2013-June) Question P...
 
Hive function-cheat-sheet
Hive function-cheat-sheetHive function-cheat-sheet
Hive function-cheat-sheet
 
Datastage real time scenario
Datastage real time scenarioDatastage real time scenario
Datastage real time scenario
 
PHP record- with all programs and output
PHP record- with all programs and outputPHP record- with all programs and output
PHP record- with all programs and output
 
C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribd
 
ES6 patterns in the wild
ES6 patterns in the wildES6 patterns in the wild
ES6 patterns in the wild
 
lecture7.ppt
lecture7.pptlecture7.ppt
lecture7.ppt
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!
 
3rd Semester Computer Science and Engineering (ACU-2022) Question papers
3rd Semester Computer Science and Engineering  (ACU-2022) Question papers3rd Semester Computer Science and Engineering  (ACU-2022) Question papers
3rd Semester Computer Science and Engineering (ACU-2022) Question papers
 
Using-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptxUsing-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptx
 
Sop and pos
Sop and posSop and pos
Sop and pos
 
Cpl
CplCpl
Cpl
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuaciones
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuaciones
 
Adobe
AdobeAdobe
Adobe
 
Real World Haskell: Lecture 5
Real World Haskell: Lecture 5Real World Haskell: Lecture 5
Real World Haskell: Lecture 5
 

Plus de adinathfashion1

This is based on lab activity in week 34 You will explore t.pdf
This is based on lab activity in week 34 You will explore t.pdfThis is based on lab activity in week 34 You will explore t.pdf
This is based on lab activity in week 34 You will explore t.pdfadinathfashion1
 
This is my visual studio C code how do I make it so that w.pdf
This is my visual studio C code how do I make it so that w.pdfThis is my visual studio C code how do I make it so that w.pdf
This is my visual studio C code how do I make it so that w.pdfadinathfashion1
 
This problem is referred to as Exon chaining in bioinformati.pdf
This problem is referred to as Exon chaining in bioinformati.pdfThis problem is referred to as Exon chaining in bioinformati.pdf
This problem is referred to as Exon chaining in bioinformati.pdfadinathfashion1
 
This project is broken up into Windows and Mac versions lis.pdf
This project is broken up into Windows and Mac versions lis.pdfThis project is broken up into Windows and Mac versions lis.pdf
This project is broken up into Windows and Mac versions lis.pdfadinathfashion1
 
Tim and Stephanie are devastated when they find out their ne.pdf
Tim and Stephanie are devastated when they find out their ne.pdfTim and Stephanie are devastated when they find out their ne.pdf
Tim and Stephanie are devastated when they find out their ne.pdfadinathfashion1
 
THis is from an Applied Mixed Models class Answer just part.pdf
THis is from an Applied Mixed Models class Answer just part.pdfTHis is from an Applied Mixed Models class Answer just part.pdf
THis is from an Applied Mixed Models class Answer just part.pdfadinathfashion1
 
This is not working for me at allAnd I cannot edit anythi.pdf
This is not working for me at allAnd I cannot edit anythi.pdfThis is not working for me at allAnd I cannot edit anythi.pdf
This is not working for me at allAnd I cannot edit anythi.pdfadinathfashion1
 
This is false please explain Assuming that the reserve req.pdf
This is false please explain Assuming that the reserve req.pdfThis is false please explain Assuming that the reserve req.pdf
This is false please explain Assuming that the reserve req.pdfadinathfashion1
 
This is NOT TRUE concerning courtship sounds Question 2 opt.pdf
This is NOT TRUE concerning courtship sounds Question 2 opt.pdfThis is NOT TRUE concerning courtship sounds Question 2 opt.pdf
This is NOT TRUE concerning courtship sounds Question 2 opt.pdfadinathfashion1
 
This is what I got for 54 but Im unsure if its right Prepa.pdf
This is what I got for 54 but Im unsure if its right Prepa.pdfThis is what I got for 54 but Im unsure if its right Prepa.pdf
This is what I got for 54 but Im unsure if its right Prepa.pdfadinathfashion1
 
This PNF technique starts with the same process as the the h.pdf
This PNF technique starts with the same process as the the h.pdfThis PNF technique starts with the same process as the the h.pdf
This PNF technique starts with the same process as the the h.pdfadinathfashion1
 
This is where you set up the project infrastructure to help .pdf
This is where you set up the project infrastructure to help .pdfThis is where you set up the project infrastructure to help .pdf
This is where you set up the project infrastructure to help .pdfadinathfashion1
 
This is a true case study A woman kept coming to the doctor.pdf
This is a true case study A woman kept coming to the doctor.pdfThis is a true case study A woman kept coming to the doctor.pdf
This is a true case study A woman kept coming to the doctor.pdfadinathfashion1
 
To answer Questions 14 and 15 read the article Britain.pdf
To answer Questions 14 and 15 read the article Britain.pdfTo answer Questions 14 and 15 read the article Britain.pdf
To answer Questions 14 and 15 read the article Britain.pdfadinathfashion1
 
To adhere to Endangered Species Act ESA guidelines the Fi.pdf
To adhere to Endangered Species Act ESA guidelines the Fi.pdfTo adhere to Endangered Species Act ESA guidelines the Fi.pdf
To adhere to Endangered Species Act ESA guidelines the Fi.pdfadinathfashion1
 
Title Media culture Objectives 1 To apply aseptic techniq.pdf
Title Media culture Objectives 1 To apply aseptic techniq.pdfTitle Media culture Objectives 1 To apply aseptic techniq.pdf
Title Media culture Objectives 1 To apply aseptic techniq.pdfadinathfashion1
 
TitleInvestigating the effect of counterfeit permits on the.pdf
TitleInvestigating the effect of counterfeit permits on the.pdfTitleInvestigating the effect of counterfeit permits on the.pdf
TitleInvestigating the effect of counterfeit permits on the.pdfadinathfashion1
 
Tketici talebindeki kk deiiklikler aadaki nedenlerle ve.pdf
Tketici talebindeki kk deiiklikler aadaki nedenlerle ve.pdfTketici talebindeki kk deiiklikler aadaki nedenlerle ve.pdf
Tketici talebindeki kk deiiklikler aadaki nedenlerle ve.pdfadinathfashion1
 
Titanic Project Management Blunders Links to an external s.pdf
Titanic  Project Management Blunders Links to an external s.pdfTitanic  Project Management Blunders Links to an external s.pdf
Titanic Project Management Blunders Links to an external s.pdfadinathfashion1
 
This is my table met Mry anlea Nole isch studein las diru ev.pdf
This is my table met Mry anlea Nole isch studein las diru ev.pdfThis is my table met Mry anlea Nole isch studein las diru ev.pdf
This is my table met Mry anlea Nole isch studein las diru ev.pdfadinathfashion1
 

Plus de adinathfashion1 (20)

This is based on lab activity in week 34 You will explore t.pdf
This is based on lab activity in week 34 You will explore t.pdfThis is based on lab activity in week 34 You will explore t.pdf
This is based on lab activity in week 34 You will explore t.pdf
 
This is my visual studio C code how do I make it so that w.pdf
This is my visual studio C code how do I make it so that w.pdfThis is my visual studio C code how do I make it so that w.pdf
This is my visual studio C code how do I make it so that w.pdf
 
This problem is referred to as Exon chaining in bioinformati.pdf
This problem is referred to as Exon chaining in bioinformati.pdfThis problem is referred to as Exon chaining in bioinformati.pdf
This problem is referred to as Exon chaining in bioinformati.pdf
 
This project is broken up into Windows and Mac versions lis.pdf
This project is broken up into Windows and Mac versions lis.pdfThis project is broken up into Windows and Mac versions lis.pdf
This project is broken up into Windows and Mac versions lis.pdf
 
Tim and Stephanie are devastated when they find out their ne.pdf
Tim and Stephanie are devastated when they find out their ne.pdfTim and Stephanie are devastated when they find out their ne.pdf
Tim and Stephanie are devastated when they find out their ne.pdf
 
THis is from an Applied Mixed Models class Answer just part.pdf
THis is from an Applied Mixed Models class Answer just part.pdfTHis is from an Applied Mixed Models class Answer just part.pdf
THis is from an Applied Mixed Models class Answer just part.pdf
 
This is not working for me at allAnd I cannot edit anythi.pdf
This is not working for me at allAnd I cannot edit anythi.pdfThis is not working for me at allAnd I cannot edit anythi.pdf
This is not working for me at allAnd I cannot edit anythi.pdf
 
This is false please explain Assuming that the reserve req.pdf
This is false please explain Assuming that the reserve req.pdfThis is false please explain Assuming that the reserve req.pdf
This is false please explain Assuming that the reserve req.pdf
 
This is NOT TRUE concerning courtship sounds Question 2 opt.pdf
This is NOT TRUE concerning courtship sounds Question 2 opt.pdfThis is NOT TRUE concerning courtship sounds Question 2 opt.pdf
This is NOT TRUE concerning courtship sounds Question 2 opt.pdf
 
This is what I got for 54 but Im unsure if its right Prepa.pdf
This is what I got for 54 but Im unsure if its right Prepa.pdfThis is what I got for 54 but Im unsure if its right Prepa.pdf
This is what I got for 54 but Im unsure if its right Prepa.pdf
 
This PNF technique starts with the same process as the the h.pdf
This PNF technique starts with the same process as the the h.pdfThis PNF technique starts with the same process as the the h.pdf
This PNF technique starts with the same process as the the h.pdf
 
This is where you set up the project infrastructure to help .pdf
This is where you set up the project infrastructure to help .pdfThis is where you set up the project infrastructure to help .pdf
This is where you set up the project infrastructure to help .pdf
 
This is a true case study A woman kept coming to the doctor.pdf
This is a true case study A woman kept coming to the doctor.pdfThis is a true case study A woman kept coming to the doctor.pdf
This is a true case study A woman kept coming to the doctor.pdf
 
To answer Questions 14 and 15 read the article Britain.pdf
To answer Questions 14 and 15 read the article Britain.pdfTo answer Questions 14 and 15 read the article Britain.pdf
To answer Questions 14 and 15 read the article Britain.pdf
 
To adhere to Endangered Species Act ESA guidelines the Fi.pdf
To adhere to Endangered Species Act ESA guidelines the Fi.pdfTo adhere to Endangered Species Act ESA guidelines the Fi.pdf
To adhere to Endangered Species Act ESA guidelines the Fi.pdf
 
Title Media culture Objectives 1 To apply aseptic techniq.pdf
Title Media culture Objectives 1 To apply aseptic techniq.pdfTitle Media culture Objectives 1 To apply aseptic techniq.pdf
Title Media culture Objectives 1 To apply aseptic techniq.pdf
 
TitleInvestigating the effect of counterfeit permits on the.pdf
TitleInvestigating the effect of counterfeit permits on the.pdfTitleInvestigating the effect of counterfeit permits on the.pdf
TitleInvestigating the effect of counterfeit permits on the.pdf
 
Tketici talebindeki kk deiiklikler aadaki nedenlerle ve.pdf
Tketici talebindeki kk deiiklikler aadaki nedenlerle ve.pdfTketici talebindeki kk deiiklikler aadaki nedenlerle ve.pdf
Tketici talebindeki kk deiiklikler aadaki nedenlerle ve.pdf
 
Titanic Project Management Blunders Links to an external s.pdf
Titanic  Project Management Blunders Links to an external s.pdfTitanic  Project Management Blunders Links to an external s.pdf
Titanic Project Management Blunders Links to an external s.pdf
 
This is my table met Mry anlea Nole isch studein las diru ev.pdf
This is my table met Mry anlea Nole isch studein las diru ev.pdfThis is my table met Mry anlea Nole isch studein las diru ev.pdf
This is my table met Mry anlea Nole isch studein las diru ev.pdf
 

Dernier

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 

Dernier (20)

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 

This is a java program PLEASE WRITE THIS IN JAVA AND FOLLOW.pdf

  • 1. This is a java program. PLEASE WRITE THIS IN JAVA AND FOLLOW ALL THE INSTRUCTIONS. THERE SHOULD BE A Tester.java class Objective: Practice using maps. All the methods you write for this should be marked static and called from the main(..). Note: none of these exercises have you mutate the input map (you will always be returning a copy of the given map with the requested modifications made). Note 1: you'll only need put(..), containsKey(..), get(..), and remove(..) for all of these methods (there are fancier map methods, though I'll leave these to you to look up for research) Note 2: sample inputs and outputs are included with each method, the ordering of the (key, value) pairs in the returned map might vary. Note 3: java prints maps like this: {a=cat, b=dog} -in our notation, this is: { (a, cat), (b, dog) } Question 1: bullyReplace (no loops needed for this one) Write a static method called bullyReplace that takes a Map<String, String> m as a parameter and returns a Map<String, String>. The method should create a copy of the input map m and return the copied map with the following changes made: --> if the key "a" has a value, set the key "b" to have that value, and set the key "a" to have the value "". Basically "b" is a bully, taking the value and replacing it with the empty string. Some input-output examples: --> bullyReplace( {("a", "candy"), ("b", "dirt")} ) --> should return: { ("a", ""), ("b", "candy") } --> bullyReplace( {("a", "candy")} ) --> should return: { ("a", ""), ("b", "candy") } --> bullyReplace( {("a", "candy"), ("b", "carrot"), ("c", "meh") -should return: { ("a", ""), ("b", "candy"), ("c", "meh") } Here's some starter code for the method to get you going (you'll have similar setup code for the remaining methods): Question 2: toppings (no loops needed for this one) Write a static method named toppings that takes a Map<String, String> m and returns a Map<String, String>. The method should create a copy of the input map m and return the copied map with the following changes made: -->if the key "ice cream" is present, set its value to "cherry". In all cases, set the key "bread" to have the value "butter". Some examples: --> toppings( {("ice cream", "peanuts")} ) -should return: { ("bread", "butter"), ("ice cream", "cherry") } -->toppings( {} ) -should return: { ("bread", "butter") } -->toppings( {("pancake", "syrup")} ) -should return: {("bread", "butter"), ("pancake", "syrup")} Question 3: mapShare (no loops needed for this one) Write a static method named mapShare that takes a Map<String, String> m and returns a Map<String, String>. The method should create a copy of the input map m and return the copied
  • 2. map with the following changes made: -->if the key "a" has a value, set the key "b" to have that same value. In all cases remove the key "c", leaving the rest of the map unchanged. Some examples: -->mapShare({("a", "aaa"), ("b", "bbb"), ("c", "ccc")}) -should return: {("a", "aaa"), ("b", "aaa")} -->mapShare({("b", "xyz"), ("c", "ccc")}) -should return: {("b", "xyz")} -->mapShare({("a", "aaa"), ("c", "meh"), ("d", "hi")}) -should return: {("a", "aaa"), ("b", "aaa"), ("d", "hi")} Question 4: mapAB (no loops needed for this one) Write a static method named mapAB that takes a Map<String, String> m and returns a Map<String, String>. The method should create a copy of the input map m and return the copied map with the following changes made: --> for this problem the returned map may or may not contain the "a" and "b" keys. If both keys are present, append their 2 string values together and store the result under the key "ab". Some examples: --> mapAB( {("a", "Hi"), ("b", "There")} ) - should return: {("a", "Hi"), ("ab", "HiThere"), ("b", "There")} --> mapAB( {("a", "Hi")} ) - should return: {("a": "Hi")} --> mapAB( {("b", "There")} ) - should return: {("b", "There")} Question 5: wordCount0 (1 loop needed) Write a static method, wordCount0, that takes a list of strings and returns a Map<String, Integer> containing a key for every different string in the input list -- always with the value 0. Some examples: -->wordCount0(List.of("a", "b", "a", "b")) -should return: {(a, 0), (b, 0)} -->wordCount0(List.of("a", "b", "a", "c", "b")) -should return: {(a, 0), (b, 0), (c, 0)} Question 6: wordLen (1 loop needed) Write a static method, wordLen that takes list of strings as a parameter and returns a Map<String, Integer> containing a key for every string in the input list, mapped to that string's length. Some examples: -->wordLen(List.of("a", "bb", "a", "bb")) -should return: {("a", 1), ("bb", 2)} -->wordLen(List.of("this", "and", "that", "and")) -should return: {("this", 4), ("and", 3), ("that", 4)} -->wordLen(List.of("code", "code", "code", "bug")) -should return: {("code", 4), ("bug", 3)} Question 7: wordMultiple (1 loop needed)
  • 3. Given a List<String> as a parameter, this method returns a Map<String, Boolean> where each different string is a key and its value is true if that string appears 2 or more times in the array. -->wordMultiple(List.of("a", "b", "a", "c", "b")) -should return: {("a", true), ("b", true), ("c", false)} -->wordMultiple(List.of("c", "b", "a")) -should return: {("a", false), ("b", false), ("c", false)} -->wordMultiple(List.of("c", "c", "c", "c")) -should return: {("c", true)} HERE IS A DOWNABLE FILE THAT WAS INCLUDED IN THE ASSIGNMENT. THIS WAS IN THE JAVA FILE: