SlideShare une entreprise Scribd logo
1  sur  6
In this assignment, you will implement a generic map interface
in two ways:
as a hash table
with another map implementation from the activity (attached)
If you prefer, you may implement and test maps of Strings
(sample code in the right column below).
You should use normal Java arrays for storage, not ArrayList or
other classes from the Java Collections API.
Your submission should be a zip file
that includes the following files:
IMap.java (below, no changes needed)
IMapTest.java, HashMapTest.java, and OtherMapTest.java
(below, no changes needed)
use the first column for Generic version, second column for
String version
HashMap.java (your hash table implementation)
(Here is the main task)
OtherMap.java (your other implementation)
(Here is the main task)
Sample Code for Generics
Sample Code for Strings (not Generic)
interface IMap {
boolean del (int key); // delete key & its value
T get (int key); // get value for key
boolean put (int key, T val); // put key,value in map
boolean hasKey(int key); // is key in map?
boolean hasVal(T val); // is val in map?
void clear (); // remove all keys & values
String dump (); // return String with contents
int size (); // return # of pairs
}
interface IMap {
boolean del (int key); // delete key & its value
String get (int key); // get value for key
boolean put (int key, String val); // put key,value in map
boolean hasKey(int key); // is key in map?
boolean hasVal(String val); // is val in map?
void clear (); // remove all keys & values
String dump (); // return String with contents
int size (); // return # of pairs
}
import static org.junit.Assert.*;
import org.junit.*;
public abstract class IMapTest {
protected IMap map;
// each subclass should initialize map and then call
super.before()
public void before() {
assertNotNull(this.map);
this.map.put(1,"one");
}
@After
public void after() {
this.map = null;
}
@Test
public void constructor() {
assertNotNull(this.map);
}
@Test
public void clear() {
assertEquals(1, this.map.size());
this.map.clear();
assertEquals(0, this.map.size());
}
@Test
public void del() {
assertEquals(1, this.map.size());
assertFalse ( this.map.del(0));
assertTrue ( this.map.del(1));
assertFalse ( this.map.del(1));
assertEquals(0, this.map.size());
}
@Test
public void get() {
assertNull ( this.map.get(0));
assertEquals("one", this.map.get(1));
}
@Test
public void has() {
assertTrue (this.map.hasKey(1));
assertTrue (this.map.hasVal("one"));
assertFalse(this.map.hasKey(3));
assertFalse(this.map.hasVal("three"));
assertTrue (this.map.put(3,"three"));
assertTrue (this.map.hasKey(3));
assertTrue (this.map.hasVal("three"));
}
@Test
public void put() {
assertEquals(1, this.map.size());
assertFalse ( this.map.put(1,"one"));
assertTrue ( this.map.put(3,"three"));
assertFalse ( this.map.put(3,"three"));
assertEquals(2, this.map.size());
}
}
import static org.junit.Assert.*;
import org.junit.*;
public abstract class IMapTest {
protected IMap map;
// each subclass should initialize map and then call
super.before()
public void before() {
assertNotNull(this.map);
this.map.put(1,"one");
}
@After
public void after() {
this.map = null;
}
@Test
public void constructor() {
assertNotNull(this.map);
}
@Test
public void clear() {
assertEquals(1, this.map.size());
this.map.clear();
assertEquals(0, this.map.size());
}
@Test
public void del() {
assertEquals(1, this.map.size());
assertFalse ( this.map.del(0));
assertTrue ( this.map.del(1));
assertFalse ( this.map.del(1));
assertEquals(0, this.map.size());
}
@Test
public void get() {
assertNull ( this.map.get(0));
assertEquals("one", this.map.get(1));
}
@Test
public void has() {
assertTrue (this.map.hasKey(1));
assertTrue (this.map.hasVal("one"));
assertFalse(this.map.hasKey(3));
assertFalse(this.map.hasVal("three"));
assertTrue (this.map.put(3,"three"));
assertTrue (this.map.hasKey(3));
assertTrue (this.map.hasVal("three"));
}
@Test
public void put() {
assertEquals(1, this.map.size());
assertFalse ( this.map.put(1,"one"));
assertTrue ( this.map.put(3,"three"));
assertFalse ( this.map.put(3,"three"));
assertEquals(2, this.map.size());
}
}
import static org.junit.Assert.*;
import org.junit.*;
public class HashMapTest extends IMapTest {
@Before
public void before() {
this.map = new HashMap(10);
super.before();
}
}
import static org.junit.Assert.*;
import org.junit.*;
public class HashMapTest extends IMapTest {
@Before
public void before() {
this.map = new HashMap(10);
super.before();
}
}
import static org.junit.Assert.*;
import org.junit.*;
public class OtherMapTest extends IMapTest {
@Before
public void before() {
this.map = new OtherMap(10);
super.before();
}
}
import static org.junit.Assert.*;
import org.junit.*;
public class OtherMapTest extends IMapTest {
@Before
public void before() {
this.map = new OtherMap(10);
super.before();
}
}

Contenu connexe

Similaire à In this assignment, you will implement a generic map interface in tw.docx

java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
arjuntelecom26
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
aromanets
 
Laporan ai modul 2-if b 2014-14102055-deprilana ego prakasa
Laporan ai modul 2-if b 2014-14102055-deprilana ego prakasaLaporan ai modul 2-if b 2014-14102055-deprilana ego prakasa
Laporan ai modul 2-if b 2014-14102055-deprilana ego prakasa
Deprilana Ego Prakasa
 
Complete the implementation of the Weighted Graph that we began in t.pdf
Complete the implementation of the Weighted Graph that we began in t.pdfComplete the implementation of the Weighted Graph that we began in t.pdf
Complete the implementation of the Weighted Graph that we began in t.pdf
marketing413921
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdf
mohdjakirfb
 
1 Part I written exercises.1. Using the Red-Black Tre.docx
1 Part I written exercises.1. Using the Red-Black Tre.docx1 Part I written exercises.1. Using the Red-Black Tre.docx
1 Part I written exercises.1. Using the Red-Black Tre.docx
mercysuttle
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
siennatimbok52331
 
Main class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdfMain class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdf
anushkaent7
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
ARCHANASTOREKOTA
 
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docxMETA-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
andreecapon
 

Similaire à In this assignment, you will implement a generic map interface in tw.docx (20)

java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
 
Please review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdfPlease review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdf
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
 
Laporan ai modul 2-if b 2014-14102055-deprilana ego prakasa
Laporan ai modul 2-if b 2014-14102055-deprilana ego prakasaLaporan ai modul 2-if b 2014-14102055-deprilana ego prakasa
Laporan ai modul 2-if b 2014-14102055-deprilana ego prakasa
 
Complete the implementation of the Weighted Graph that we began in t.pdf
Complete the implementation of the Weighted Graph that we began in t.pdfComplete the implementation of the Weighted Graph that we began in t.pdf
Complete the implementation of the Weighted Graph that we began in t.pdf
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdf
 
ScalaFlavor4J
ScalaFlavor4JScalaFlavor4J
ScalaFlavor4J
 
Java Question help needed In the program Fill the Add statements.pdf
Java Question  help needed In the program Fill the Add statements.pdfJava Question  help needed In the program Fill the Add statements.pdf
Java Question help needed In the program Fill the Add statements.pdf
 
Write a program that reads a graph from a file and determines whether.docx
 Write a program that reads a graph from a file and determines whether.docx Write a program that reads a graph from a file and determines whether.docx
Write a program that reads a graph from a file and determines whether.docx
 
1 Part I written exercises.1. Using the Red-Black Tre.docx
1 Part I written exercises.1. Using the Red-Black Tre.docx1 Part I written exercises.1. Using the Red-Black Tre.docx
1 Part I written exercises.1. Using the Red-Black Tre.docx
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
 
Internal workshop es6_2015
Internal workshop es6_2015Internal workshop es6_2015
Internal workshop es6_2015
 
Java 5 Features
Java 5 FeaturesJava 5 Features
Java 5 Features
 
Main class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdfMain class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdf
 
JavaOne 2016 - Learn Lambda and functional programming
JavaOne 2016 - Learn Lambda and functional programmingJavaOne 2016 - Learn Lambda and functional programming
JavaOne 2016 - Learn Lambda and functional programming
 
Array list
Array listArray list
Array list
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
Oop lecture9 13
Oop lecture9 13Oop lecture9 13
Oop lecture9 13
 
Java 5 and 6 New Features
Java 5 and 6 New FeaturesJava 5 and 6 New Features
Java 5 and 6 New Features
 
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docxMETA-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
 

Plus de widdowsonerica

Information Technology, Computer Networks and CyberspaceKizza (201.docx
Information Technology, Computer Networks and CyberspaceKizza (201.docxInformation Technology, Computer Networks and CyberspaceKizza (201.docx
Information Technology, Computer Networks and CyberspaceKizza (201.docx
widdowsonerica
 
Information to use for paperStep 1 Select your topic and focus.docx
Information to use for paperStep 1 Select your topic and focus.docxInformation to use for paperStep 1 Select your topic and focus.docx
Information to use for paperStep 1 Select your topic and focus.docx
widdowsonerica
 
Information and Knowledge Needs of Nurses in the 21st CenturyIn th.docx
Information and Knowledge Needs of Nurses in the 21st CenturyIn th.docxInformation and Knowledge Needs of Nurses in the 21st CenturyIn th.docx
Information and Knowledge Needs of Nurses in the 21st CenturyIn th.docx
widdowsonerica
 
Infectious and Noninfectious Prevention and Control TechniquesIn.docx
Infectious and Noninfectious Prevention and Control TechniquesIn.docxInfectious and Noninfectious Prevention and Control TechniquesIn.docx
Infectious and Noninfectious Prevention and Control TechniquesIn.docx
widdowsonerica
 
INF 410 week 4 assign onAssume you are the project manager for a s.docx
INF 410 week 4 assign onAssume you are the project manager for a s.docxINF 410 week 4 assign onAssume you are the project manager for a s.docx
INF 410 week 4 assign onAssume you are the project manager for a s.docx
widdowsonerica
 
Information Technology in Public HealthPublic health surveillance .docx
Information Technology in Public HealthPublic health surveillance .docxInformation Technology in Public HealthPublic health surveillance .docx
Information Technology in Public HealthPublic health surveillance .docx
widdowsonerica
 
Individuals use social movements when they feel a social institution.docx
Individuals use social movements when they feel a social institution.docxIndividuals use social movements when they feel a social institution.docx
Individuals use social movements when they feel a social institution.docx
widdowsonerica
 
Information is provided for you below that will help you construct a.docx
Information is provided for you below that will help you construct a.docxInformation is provided for you below that will help you construct a.docx
Information is provided for you below that will help you construct a.docx
widdowsonerica
 

Plus de widdowsonerica (20)

Information Technology, Computer Networks and CyberspaceKizza (201.docx
Information Technology, Computer Networks and CyberspaceKizza (201.docxInformation Technology, Computer Networks and CyberspaceKizza (201.docx
Information Technology, Computer Networks and CyberspaceKizza (201.docx
 
Information to use for paperStep 1 Select your topic and focus.docx
Information to use for paperStep 1 Select your topic and focus.docxInformation to use for paperStep 1 Select your topic and focus.docx
Information to use for paperStep 1 Select your topic and focus.docx
 
Information and Knowledge Needs of Nurses in the 21st CenturyIn th.docx
Information and Knowledge Needs of Nurses in the 21st CenturyIn th.docxInformation and Knowledge Needs of Nurses in the 21st CenturyIn th.docx
Information and Knowledge Needs of Nurses in the 21st CenturyIn th.docx
 
Infectious and Noninfectious Prevention and Control TechniquesIn.docx
Infectious and Noninfectious Prevention and Control TechniquesIn.docxInfectious and Noninfectious Prevention and Control TechniquesIn.docx
Infectious and Noninfectious Prevention and Control TechniquesIn.docx
 
Information Management and Software Development Please respo.docx
Information Management and Software Development Please respo.docxInformation Management and Software Development Please respo.docx
Information Management and Software Development Please respo.docx
 
Information Security  Please respond to the followingIdentify t.docx
Information Security  Please respond to the followingIdentify t.docxInformation Security  Please respond to the followingIdentify t.docx
Information Security  Please respond to the followingIdentify t.docx
 
Information PaperThe Chief of Staff is preparing preliminary studi.docx
Information PaperThe Chief of Staff is preparing preliminary studi.docxInformation PaperThe Chief of Staff is preparing preliminary studi.docx
Information PaperThe Chief of Staff is preparing preliminary studi.docx
 
INF 410 week 4 assign onAssume you are the project manager for a s.docx
INF 410 week 4 assign onAssume you are the project manager for a s.docxINF 410 week 4 assign onAssume you are the project manager for a s.docx
INF 410 week 4 assign onAssume you are the project manager for a s.docx
 
Information Technology in Public HealthPublic health surveillance .docx
Information Technology in Public HealthPublic health surveillance .docxInformation Technology in Public HealthPublic health surveillance .docx
Information Technology in Public HealthPublic health surveillance .docx
 
Information System and Enterprise SystemsIdentify the key factors.docx
Information System and Enterprise SystemsIdentify the key factors.docxInformation System and Enterprise SystemsIdentify the key factors.docx
Information System and Enterprise SystemsIdentify the key factors.docx
 
Individuals react to a variety of social cues to construct their per.docx
Individuals react to a variety of social cues to construct their per.docxIndividuals react to a variety of social cues to construct their per.docx
Individuals react to a variety of social cues to construct their per.docx
 
Information Technology and Decision MakingPatient safety and care .docx
Information Technology and Decision MakingPatient safety and care .docxInformation Technology and Decision MakingPatient safety and care .docx
Information Technology and Decision MakingPatient safety and care .docx
 
Individuals use social movements when they feel a social institution.docx
Individuals use social movements when they feel a social institution.docxIndividuals use social movements when they feel a social institution.docx
Individuals use social movements when they feel a social institution.docx
 
Industry Averages and Financial Ratios PaperCalculate the 14 rat.docx
Industry Averages and Financial Ratios PaperCalculate the 14 rat.docxIndustry Averages and Financial Ratios PaperCalculate the 14 rat.docx
Industry Averages and Financial Ratios PaperCalculate the 14 rat.docx
 
Information is provided for you below that will help you construct a.docx
Information is provided for you below that will help you construct a.docxInformation is provided for you below that will help you construct a.docx
Information is provided for you below that will help you construct a.docx
 
Individuals who are frequent voters share common characteristics, re.docx
Individuals who are frequent voters share common characteristics, re.docxIndividuals who are frequent voters share common characteristics, re.docx
Individuals who are frequent voters share common characteristics, re.docx
 
Infectious diseases come with extremely tough challenges to mitigate.docx
Infectious diseases come with extremely tough challenges to mitigate.docxInfectious diseases come with extremely tough challenges to mitigate.docx
Infectious diseases come with extremely tough challenges to mitigate.docx
 
Individual Reflection in which you describe the plan that you would .docx
Individual Reflection in which you describe the plan that you would .docxIndividual Reflection in which you describe the plan that you would .docx
Individual Reflection in which you describe the plan that you would .docx
 
Individual ProjectGroups in the WorkplaceSun, 10816.docx
Individual ProjectGroups in the WorkplaceSun, 10816.docxIndividual ProjectGroups in the WorkplaceSun, 10816.docx
Individual ProjectGroups in the WorkplaceSun, 10816.docx
 
Individual ProjectRecruitment Strategies and Tools Mon, 83.docx
Individual ProjectRecruitment Strategies and Tools Mon, 83.docxIndividual ProjectRecruitment Strategies and Tools Mon, 83.docx
Individual ProjectRecruitment Strategies and Tools Mon, 83.docx
 

Dernier

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
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
heathfieldcps1
 

Dernier (20)

SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
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.
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.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
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 

In this assignment, you will implement a generic map interface in tw.docx

  • 1. In this assignment, you will implement a generic map interface in two ways: as a hash table with another map implementation from the activity (attached) If you prefer, you may implement and test maps of Strings (sample code in the right column below). You should use normal Java arrays for storage, not ArrayList or other classes from the Java Collections API. Your submission should be a zip file that includes the following files: IMap.java (below, no changes needed) IMapTest.java, HashMapTest.java, and OtherMapTest.java (below, no changes needed) use the first column for Generic version, second column for String version HashMap.java (your hash table implementation) (Here is the main task) OtherMap.java (your other implementation) (Here is the main task) Sample Code for Generics Sample Code for Strings (not Generic) interface IMap { boolean del (int key); // delete key & its value T get (int key); // get value for key boolean put (int key, T val); // put key,value in map boolean hasKey(int key); // is key in map? boolean hasVal(T val); // is val in map? void clear (); // remove all keys & values String dump (); // return String with contents int size (); // return # of pairs } interface IMap { boolean del (int key); // delete key & its value String get (int key); // get value for key
  • 2. boolean put (int key, String val); // put key,value in map boolean hasKey(int key); // is key in map? boolean hasVal(String val); // is val in map? void clear (); // remove all keys & values String dump (); // return String with contents int size (); // return # of pairs } import static org.junit.Assert.*; import org.junit.*; public abstract class IMapTest { protected IMap map; // each subclass should initialize map and then call super.before() public void before() { assertNotNull(this.map); this.map.put(1,"one"); } @After public void after() { this.map = null; } @Test public void constructor() { assertNotNull(this.map); } @Test public void clear() { assertEquals(1, this.map.size()); this.map.clear(); assertEquals(0, this.map.size()); } @Test public void del() { assertEquals(1, this.map.size()); assertFalse ( this.map.del(0));
  • 3. assertTrue ( this.map.del(1)); assertFalse ( this.map.del(1)); assertEquals(0, this.map.size()); } @Test public void get() { assertNull ( this.map.get(0)); assertEquals("one", this.map.get(1)); } @Test public void has() { assertTrue (this.map.hasKey(1)); assertTrue (this.map.hasVal("one")); assertFalse(this.map.hasKey(3)); assertFalse(this.map.hasVal("three")); assertTrue (this.map.put(3,"three")); assertTrue (this.map.hasKey(3)); assertTrue (this.map.hasVal("three")); } @Test public void put() { assertEquals(1, this.map.size()); assertFalse ( this.map.put(1,"one")); assertTrue ( this.map.put(3,"three")); assertFalse ( this.map.put(3,"three")); assertEquals(2, this.map.size()); } } import static org.junit.Assert.*; import org.junit.*; public abstract class IMapTest { protected IMap map; // each subclass should initialize map and then call super.before() public void before() {
  • 4. assertNotNull(this.map); this.map.put(1,"one"); } @After public void after() { this.map = null; } @Test public void constructor() { assertNotNull(this.map); } @Test public void clear() { assertEquals(1, this.map.size()); this.map.clear(); assertEquals(0, this.map.size()); } @Test public void del() { assertEquals(1, this.map.size()); assertFalse ( this.map.del(0)); assertTrue ( this.map.del(1)); assertFalse ( this.map.del(1)); assertEquals(0, this.map.size()); } @Test public void get() { assertNull ( this.map.get(0)); assertEquals("one", this.map.get(1)); } @Test public void has() { assertTrue (this.map.hasKey(1)); assertTrue (this.map.hasVal("one"));
  • 5. assertFalse(this.map.hasKey(3)); assertFalse(this.map.hasVal("three")); assertTrue (this.map.put(3,"three")); assertTrue (this.map.hasKey(3)); assertTrue (this.map.hasVal("three")); } @Test public void put() { assertEquals(1, this.map.size()); assertFalse ( this.map.put(1,"one")); assertTrue ( this.map.put(3,"three")); assertFalse ( this.map.put(3,"three")); assertEquals(2, this.map.size()); } } import static org.junit.Assert.*; import org.junit.*; public class HashMapTest extends IMapTest { @Before public void before() { this.map = new HashMap(10); super.before(); } } import static org.junit.Assert.*; import org.junit.*; public class HashMapTest extends IMapTest { @Before public void before() { this.map = new HashMap(10); super.before(); } }
  • 6. import static org.junit.Assert.*; import org.junit.*; public class OtherMapTest extends IMapTest { @Before public void before() { this.map = new OtherMap(10); super.before(); } } import static org.junit.Assert.*; import org.junit.*; public class OtherMapTest extends IMapTest { @Before public void before() { this.map = new OtherMap(10); super.before(); } }