Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Week 14 Assignment SDEV-350 Java Programming II © Champlain College Assignment This week, we will implement a HashMap with a GUI interface. Requirements  Your GUI may not appear exactly as the sample...

1 answer below »
Week 14 Assignment
SDEV-350 Java Programming II

© Champlain College
Assignment
This week, we will implement a HashMap with a GUI interface.
Requirements
 Your GUI may not appear exactly as the sample above. However, it should have all of the
components/nodes shown
 Create a GUI that will allow an entry of a name and co
esponding age into a HashMap
 As in the GUI (above), your program should have two TextAreas for display purposes
 Utilize the following code from Chapter 27:
o MyMap.java interface (Listing 27.1)
o MyHashMap.java subclass (Listing 27.2)
 The Enter button:
o Inserts a key (Name) and a value (Age) from the appropriate TextFields into a HashMap
o Displays the Name and Age in the right TextArea once entered (See screen shots)
o Displays a message in the left TextArea (See screen shots)
o Sets focus to the Name TextField
 The Find button:
o Searches the HashMap for a key entered into the Name TextField
o Displays a message in the left TextArea (See screen shots)
o Sets focus to the Name TextField
 The Remove button:
o Removes an entry from the HashMap whose key (entered into the Name TextField) matches
the Name
o Updates the Right TextArea (See screen shots)
o Displays a message in the left TextArea (See screen shots)
o Sets focus to the Name TextField
JavaFX Hashing
Week 14 Assignment
SDEV-350 Java Programming II

© Champlain College
 The Clear button:
o Clears both TextAreas, the HashMap, and any other user entry fields if applicable (See
screen shots)
o Sets focus to the Name TextField
 The Exit button closes the program
 Validation/Exception handling where appropriate should inform the user of:
o No value entered when the Enter button is pressed (Name OR Age missing)
o No value entered when the Remove or Find buttons are pressed (Name missing)
o An empty HashMap when searching or removing values when the HashMap is empty
o A key value is not found (for Find or Remove button clicks)
o Others when/where appropriate
 This assignment covers subjects from Chapter 1 - 27
Hints
Sample code is readily available in this week’s lecture material as well as the text book and Internet. If
you find code on the Internet that you believe might assist, make sure you give proper credit to the
source. Make sure that you utilize the most efficient algorithm that you can.
Expected Output
You have creative freedom with this assignment. Your result is not required to appear exactly as the
sample above or screen shots below. However; it must contain all of the same components and include
the functionality described above and below in the screen shot examples. Your GUI must also be visually
appealing with consistent spacing/gapping. You do not have to incorporate an image in this assignment
unless you wish.
Deliverables
Please zip your program and submit the zip file by the due date listed in the requirements.
Screen Shots:
(Next page)
Week 14 Assignment
SDEV-350 Java Programming II

© Champlain College

After 7 entries. Results shown are after Mary Ann was added to the HashMap
After searching for a known entry (Linda)
Week 14 Assignment
SDEV-350 Java Programming II

© Champlain College
After Jim was removed from the HashMap
After the Clear Button was clicked

source/MyHashMap.class
public synchronized class MyHashMap implements MyMap {
private static int DEFAULT_INITIAL_CAPACITY;
private static int MAXIMUM_CAPACITY;
private int capacity;
private static float DEFAULT_MAX_LOAD_FACTOR;
private float loadFactorThreshold;
private int size;
java.util.LinkedList[] table;
static void ();
public void MyHashMap();
public void MyHashMap(int);
public void MyHashMap(int, float);
public void clear();
public boolean containsKey(Object);
public boolean containsValue(Object);
public java.util.Set entrySet();
public Object get(Object);
public boolean isEmpty();
public java.util.Set keySet();
public Object put(Object, Object);
public void remove(Object);
public int size();
public java.util.Set values();
private int hash(int);
private static int supplementalHash(int);
private int trimToPowerOf2(int);
private void removeEntries();
private void rehash();
public String toString();
}
source/MyHashMap.java
source/MyHashMap.java
import java.util.LinkedList;
public class MyHashMap implements MyMap {
  
 Define the default hash table size. Must be a power of 2
  private static int DEFAULT_INITIAL_CAPACITY = 4;
  
  
 Define the maximum hash table size. 1 
 30 is same as 2^30
  private static int MAXIMUM_CAPACITY = 1 
 30; 
  
  
 Cu
ent hash table capacity. Capacity is a power of 2
  private int capacity;
  
  
 Define default load facto
  private static float DEFAULT_MAX_LOAD_FACTOR = 0.75f; 
  
 Specify a load factor used in the hash table
  private float loadFactorThreshold; 
     
  
 The number of entries in the map
  private int size = 0; 
  
  
 Hash table is an a
ay with each cell that is a linked list
  LinkedList[] table;
  /** Construct a map with the default capacity and load factor *
  public MyHashMap() {  
    this(DEFAULT_INITIAL_CAPACITY, DEFAULT_MAX_LOAD_FACTOR);    
  }
  
  /** Construct a map with the specified initial capacity and 
   * default load factor *
  public MyHashMap(int initialCapacity) { 
    this(initialCapacity, DEFAULT_MAX_LOAD_FACTOR);    
  }
  
  /** Construct a map with the specified initial capacity 
   * and load factor *
  public MyHashMap(int initialCapacity, float loadFactorThreshold) { 
    if (initialCapacity > MAXIMUM_CAPACITY)
      this.capacity = MAXIMUM_CAPACITY;
    else
      this.capacity = trimToPowerOf2(initialCapacity);
    
    this.loadFactorThreshold = loadFactorThreshold;    
    table = new LinkedList[capacity];
  }
  
  @Ove
ide /** Remove all of the entries from this map */ 
  public void clear() {
    size = 0;
    removeEntries();
  }
  @Ove
ide /** Return true if the specified key is in the map *
  public boolean containsKey(K key) {    
    if (get(key) != null)
      return true;
    else
      return false;
  }
  
  @Ove
ide /** Return true if this map contains the value */ 
  public boolean containsValue(V value) {
    for (int i = 0; i < capacity; i++) {
      if (table[i] != null) {
        LinkedList bucket = table[i]; 
        for (Entry entry: bucket)
          if (entry.getValue().equals(value)) 
            return true;
      }
    }
    
    return false;
  }
  
  @Ove
ide /** Return a set of entries in the map *
  public java.util.Set entrySet() {
    java.util.Set set = 
      new java.util.HashSet
();
    
    for (int i = 0; i < capacity; i++) {
      if (table[i] != null) {
        LinkedList bucket = table[i]; 
        for (Entry entry: bucket)
          set.add(entry); 
      }
    }
    
    return set;
  }
  @Ove
ide /** Return the value that matches the specified key *
  public V get(K key) {
    int bucketIndex = hash(key.hashCode());
    if (table[bucketIndex] != null) {
      LinkedList bucket = table[bucketIndex]; 
      for (Entry entry: bucket)
        if (entry.getKey().equals(key)) 
          return entry.getValue();
    }
    
    return null;
  }
  
  @Ove
ide /** Return true if this map contains no entries *
  public boolean isEmpty() {
    return size == 0;
  }  
  
  @Ove
ide /** Return a set consisting of the keys in this map *
  public java.util.Set keySet() {
    java.util.Set set = new java.util.HashSet
();
    
    for (int i = 0; i < capacity; i++) {
      if (table[i] != null) {
        LinkedList bucket = table[i]; 
        for (Entry entry: bucket)
          set.add(entry.getKey()); 
      }
    }
    
    return set;
  }
      
  @Ove
ide /** Add an entry (key, value) into the map *
  public V put(K key, V value) {
    if (get(key) != null) { 
 The key is already in the map
      int bucketIndex = hash(key.hashCode());
      LinkedList bucket = table[bucketIndex]; 
      for (Entry entry: bucket)
        if (entry.getKey().equals(key)) {
          V oldValue = entry.getValue();
          
 Replace old value with new value
          entry.value = value; 
          
 Return the old value for the key
          return oldValue;
        }
    }
  
    
 Check load facto
    if (size >= capacity * loadFactorThreshold) {
      if (capacity == MAXIMUM_CAPACITY)
        throw new RuntimeException("Exceeding maximum capacity");
      
      rehash();
    }
    
    int bucketIndex = hash(key.hashCode());
    
    
 Create a linked list for the bucket if it is not created
    if (table[bucketIndex] == null) {
      table[bucketIndex] = new LinkedList();
    }
    
 Add a new entry (key, value) to hashTable[index]
    table[bucketIndex].add(new MyMap.Entry(key, value));
    size++; 
 Increase size
    
    return value;  
  } 
 
  @Ove
ide /** Remove the entries for the specified key *
  public void remove(K key) {
    int bucketIndex = hash(key.hashCode());
    
    
 Remove the first entry that matches the key from a bucket
    if (table[bucketIndex] != null) {
      LinkedList bucket = table[bucketIndex]; 
      for (Entry entry: bucket)
        if (entry.getKey().equals(key)) {
          bucket.remove(entry);
          size--; 
 Decrease size
          
eak; 
 Remove just one entry that matches the key
        }
    }
  }
  
  @Ove
ide /** Return the number of entries in this map *
  public int size() {
    return size;
  }
  
  @Ove
ide /** Return a set consisting of the values in this map *
  public java.util.Set values() {
    java.util.Set set = new java.util.HashSet
();
    
    for (int i = 0; i < capacity; i++) {
      if (table[i] != null) {
        LinkedList bucket = table[i]; 
        for (Entry entry: bucket)
          set.add(entry.getValue()); 
      }
    }
    
    return set;
  }
  
  /** Hash function *
  private int hash(int hashCode) {
    return supplementalHash(hashCode) & (capacity - 1);
  }
  
  /** Ensure the hashing is evenly distributed *
  private static int supplementalHash(int h) {
    h ^= (h 
 20) ^ (h 
 12);
    return h ^ (h 
 7) ^ (h 
 4);
  }
  /** Return a power of 2 for initialCapacity *
  private int trimToPowerOf2(int initialCapacity) {
    int capacity = 1;
    while (capacity < initialCapacity) {
      capacity 
= 1;
    }
    
    return capacity;
  }
  
  /** Remove all entries from each bucket *
  private void removeEntries() {
    for (int i = 0; i < capacity; i++) {
      if (table[i] != null) {
        table[i].clear();
      }
    }
  }
  
  /** Rehash the map *
  private void rehash() {
    java.util.Set set = entrySet(); 
 Get entries
    capacity 
= 1; 
 Double capacity    
    table = new LinkedList[capacity]; 
 Create a new hash table
    size = 0; 
 Reset size to 0
    
    for (Entry entry: set) {
      put(entry.getKey(), entry.getValue()); 
 Store to new table
    }
  }
  @Ove
ide
  public String toString() {
    StringBuilder builder = new StringBuilder("[");
    
    for (int i = 0; i < capacity; i++) {
      if (table[i] != null && table[i].size() > 0) 
        for (Entry entry: table[i])
          builder.append(entry);
    }
    
    builder.append("]");
    return builder.toString();
  }
}
source/MyMap$Entry.class
public synchronized class MyMap$Entry {
Object key;
Object value;
public void MyMap$Entry(Object, Object);
public Object getKey();
public Object getValue();
public String toString();
}
source/MyMap.class
public abstract interface MyMap {
public abstract void clear();
public abstract boolean containsKey(Object);
public abstract boolean containsValue(Object);
public abstract java.util.Set entrySet();
public abstract Object get(Object);
public abstract boolean isEmpty();
public abstract java.util.Set keySet();
public abstract Object put(Object, Object);
public abstract void remove(Object);
public abstract int size();
public abstract java.util.Set values();
}
source/MyMap.java
source/MyMap.java
public interface MyMap {
  /** Remove all of the entries from this map */ 
  public void clear();
  
  /** Return true if the specified key is in the map *
  public boolean containsKey(K key);
  
  /** Return true if this map contains the specified value */ 
  public boolean containsValue(V value);
  /** Return a set of entries in the map *
  public java.util.Set entrySet();
  /** Return the first value that matches the specified key *
  public V get(K key);
  
  /** Return true if this map contains no entries *
  public boolean isEmpty();
  /** Return a set consisting of the keys in this map *
  public java.util.Set keySet();
  
  /** Add an entry (key, value) into the map *
  public V put(K key, V value);
  /** Remove the entries for the specified key *
  public void remove(K key);
  /** Return the number of mappings in this map *
  public int size();
  /** Return a set consisting of the values in this map *
  public java.util.Set values();
  
  /** Define inner class for Entry *
  public static class Entry {
    K key;
    V value;
    
    public Entry(K key, V value) {
      this.key = key;
      this.value = value;
    }
    
    public K getKey() {
      return key;
    }
    
    public V getValue() {
      return value;
    }
    
    @Ove
ide
    public String toString() {
      return "[" + key + ", " + value + "]";
    }
  }
}
Answered 2 days After Apr 26, 2021

Solution

Shweta answered on Apr 28 2021
146 Votes
82018Solution/JavaFXHashMaps
uild
uilt-jar.properties
#Wed, 28 Apr 2021 08:09:48 +0530
F\:\\JavaFXHashMaps=
82018Solution/JavaFXHashMaps
uild/classes/javafxhashmaps/FXMLDocument.fxml






























82018Solution/JavaFXHashMaps
uild/classes/javafxhashmaps/FXMLDocumentController.class
package javafxhashmaps;
public synchronized class FXMLDocumentController implements javafx.fxml.Initializable {
private javafx.scene.control.TextField txtName;
private javafx.scene.control.TextField txtAge;
private javafx.scene.control.TextArea txtAreaAllEntries;
private javafx.scene.control.TextArea txtAreaMessage;
MyHashMap map;
public void FXMLDocumentController();
public void enterData();
public void findData();
public void removeData();
public void allEnteries();
public void clearTextBox();
public void clearAll();
public void exitApp();
public void initialize(java.net.URL, java.util.ResourceBundle);
}
82018Solution/JavaFXHashMaps
uild/classes/javafxhashmaps/JavaFXHashMaps.class
package javafxhashmaps;
public synchronized class JavaFXHashMaps extends javafx.application.Application {
public void JavaFXHashMaps();
public void start(javafx.stage.Stage) throws Exception;
public static void main(String[]);
}
82018Solution/JavaFXHashMaps
uild/classes/javafxhashmaps/MyHashMap.class
package javafxhashmaps;
public synchronized class MyHashMap implements MyMap {
private static int DEFAULT_INITIAL_CAPACITY;
private static int MAXIMUM_CAPACITY;
private int capacity;
private static float DEFAULT_MAX_LOAD_FACTOR;
private float loadFactorThreshold;
private int size;
java.util.LinkedList[] table;
public void MyHashMap();
public void MyHashMap(int);
public void MyHashMap(int, float);
public void clear();
public boolean containsKey(Object);
public boolean containsValue(Object);
public java.util.Set entrySet();
public Object get(Object);
public boolean isEmpty();
public java.util.Set keySet();
public Object put(Object, Object);
public void remove(Object);
public int size();
public java.util.Set values();
private int hash(int);
private static int supplementalHash(int);
private int trimToPowerOf2(int);
private void removeEntries();
private void rehash();
public String toString();
static void ();
}
82018Solution/JavaFXHashMaps
uild/classes/javafxhashmaps/MyMap$Entry.class
package javafxhashmaps;
public synchronized class MyMap$Entry {
Object key;
Object value;
public void MyMap$Entry(Object, Object);
public Object getKey();
public Object getValue();
public String toString();
}
82018Solution/JavaFXHashMaps
uild/classes/javafxhashmaps/MyMap.class
package javafxhashmaps;
public abstract interface MyMap {
public abstract void clear();
public abstract boolean containsKey(Object);
public abstract boolean containsValue(Object);
public abstract java.util.Set entrySet();
public abstract Object get(Object);
public abstract boolean isEmpty();
public abstract java.util.Set keySet();
public abstract Object put(Object, Object);
public abstract void remove(Object);
public abstract int size();
public abstract java.util.Set values();
}
82018Solution/JavaFXHashMaps
uild.xml

Builds, tests, and runs the project JavaFXHashMaps.


82018Solution/JavaFXHashMaps/dist/JavaFXHashMaps.html
Test page for JavaFXHashMaps
Webstart: click to launch this app as webstart


82018Solution/JavaFXHashMaps/dist/JavaFXHashMaps.ja
META-INF/MANIFEST.MF
Manifest-Version: 1.0
Implementation-Title: JavaFXHashMaps
X-COMMENT: Main-Class will be added automatically by build
Implementation-Version: 1.0
Permissions: sandbox
Codebase: *
JavaFX-Version: 8.0
Class-Path:
Created-By: JavaFX Package
Implementation-Vendor: Ace
Main-Class: javafxhashmaps.JavaFXHashMaps
javafxhashmaps/FXMLDocument.fxml






























javafxhashmaps/FXMLDocumentController.class
package javafxhashmaps;
public synchronized class FXMLDocumentController implements javafx.fxml.Initializable {
private javafx.scene.control.TextField txtName;
private javafx.scene.control.TextField txtAge;
private javafx.scene.control.TextArea txtAreaAllEntries;
private javafx.scene.control.TextArea txtAreaMessage;
MyHashMap map;
public void FXMLDocumentController();
public void enterData();
public void findData();
public void removeData();
public void allEnteries();
public void clearTextBox();
public void clearAll();
public void exitApp();
public void initialize(java.net.URL, java.util.ResourceBundle);
}
javafxhashmaps/JavaFXHashMaps.class
package javafxhashmaps;
public synchronized class JavaFXHashMaps extends javafx.application.Application {
public void JavaFXHashMaps();
public void start(javafx.stage.Stage) throws Exception;
public static void main(String[]);
}
javafxhashmaps/MyHashMap.class
package javafxhashmaps;
public synchronized class MyHashMap implements MyMap {
private static int DEFAULT_INITIAL_CAPACITY;
private static int MAXIMUM_CAPACITY;
private int capacity;
private static float DEFAULT_MAX_LOAD_FACTOR;
private float loadFactorThreshold;
private int size;
java.util.LinkedList[] table;
public void MyHashMap();
public void MyHashMap(int);
public void MyHashMap(int, float);
public void clear();
public boolean containsKey(Object);
public boolean containsValue(Object);
public java.util.Set entrySet();
public Object get(Object);
public boolean isEmpty();
public java.util.Set keySet();
public Object put(Object, Object);
public void remove(Object);
public int size();
public java.util.Set values();
private int hash(int);
private static int supplementalHash(int);
private int trimToPowerOf2(int);
private void removeEntries();
private void rehash();
public String toString();
static void ();
}
javafxhashmaps/MyMap$Entry.class
package javafxhashmaps;
public synchronized class MyMap$Entry {
Object key;
Object value;
public void MyMap$Entry(Object, Object);
public Object getKey();
public Object getValue();
public String toString();
}
javafxhashmaps/MyMap.class
package javafxhashmaps;
public abstract interface MyMap {
public abstract void clear();
public abstract boolean containsKey(Object);
public abstract boolean containsValue(Object);
public abstract java.util.Set entrySet();
public abstract Object get(Object);
public abstract boolean isEmpty();
public abstract java.util.Set keySet();
public abstract Object put(Object, Object);
public abstract void remove(Object);
public abstract int size();
public abstract java.util.Set values();
}
82018Solution/JavaFXHashMaps/dist/JavaFXHashMaps.jnlp


JavaFXHashMaps
Ace
null








82018Solution/JavaFXHashMaps/manifest.mf
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
82018Solution/JavaFXHashMaps/nbproject
uild-impl.xml


























































































































Must set platform.home
Must set platform.bootcp
Must set platform.java
Must set platform.javac

The J2SE Platform is not co
ectly set up.
Your active platform is: ${platform.active}, but the co
esponding property "platforms.${platform.active}.home" is not found in the project's properties files.
Either open the project in the IDE and setup the Platform with the same name or add it manually.
For example like this:
ant -Duser.properties.file= jar (where you put the property "platforms.${platform.active}.home" in a .properties file)
or ant -Dplatforms.${platform.active}.home= jar (where no properties file is used)







































































































































































Must set src.di
Must set test.src.di
Must set build.di
Must set dist.di
Must set build.classes.di
Must set dist.javadoc.di
Must set build.test.classes.di
Must set build.test.results.di
Must set build.classes.excludes
Must set dist.ja











































































































































































Must set javac.includes












































































































































































No tests executed.

























































































































































































Must set JVM to use for profiling in profiler.info.jvm
Must set profiler agent JVM arguments in profiler.info.jvmargs.agent























































































































































































































































































Must select some files in the IDE or set javac.includes
































































To run this application from the command line without Ant, try:

${platform.java} -jar "${dist.jar.resolved}"

































































































































Must select one file in the IDE or set run.class



Must select one file in the IDE or set run.class






















Must select one file in the IDE or set debug.class




Must select one file in the IDE or set debug.class




Must set fix.includes









This target only works when run from inside the NetBeans IDE.








Must select one file in the IDE or set profile.class
This target only works when run from inside the NetBeans IDE.








This target only works when run from inside the NetBeans IDE.












This target only works when run from inside the NetBeans IDE.































Must select one file in the IDE or set run.class





Must select some files in the IDE or set test.includes




Must select one file in the IDE or set run.class




Must select one file in the IDE or set applet.url




































































































































Must select some files in the IDE or set javac.includes























Some tests failed; see details above.








Must select some files in the IDE or set test.includes



Some tests failed; see details above.



Must select some files in the IDE or set test.class
Must select some method in the IDE or set test.method



Some tests failed; see details above.




Must select one file in the IDE or set test.class



Must select one file in the IDE or set test.class
Must select some method in the IDE or set test.method













Must select one file in the IDE or set applet.url








Must select one file in the IDE or set applet.url





















































82018Solution/JavaFXHashMaps/nbproject/configs/Run_as_WebStart.properties
# Do not modify this property in this configuration. It can be re-generated.
$label=Run as WebStart
82018Solution/JavaFXHashMaps/nbproject/configs/Run_in_Browser.properties
# Do not modify this property in this configuration. It can be re-generated.
$label=Run in Browse
82018Solution/JavaFXHashMaps/nbproject/genfiles.properties
uild.xml.data.CRC32=2b3
6c8
uild.xml.script.CRC32=d6e101ba
[email protected]
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject
uild-impl.xml.data.CRC32=2b3
6c8
nbproject
uild-impl.xml.script.CRC32=45b01095
nbproject
[email protected]
82018Solution/JavaFXHashMaps/nbproject/jfx-impl.xml

JavaFX-specific Ant calls
























































































































































































































































































































































































































































































































































































































































































































































...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here