https://bit.ly/cpsc210_24W1
CPSC 210 Mid course Feedback Form (Anonymous)!
Collection
Map
Iterable
List
Queue
Set
HashMap
HashSet
ArrayList
LinkedList
...
has
"Firas" |
"Felix" |
"Taryn" |
Map<String, Instructor>
Map<K, V>
values: instructor objects
keys: names
Map<String, Instructor> instructors;
instructors = new HashMap<String, Instructor>();
instructors.put("Firas", new Instructor());
instructors.put("Felix", new Instructor());
instructors.put("Taryn", new Instructor());
Instructor firas = instructors.get("Firas");
Instructor felix = instructors.get("Felix");
Instructor taryn = instructors.get("Taryn");
HashSet
ArrayList
LinkedList
HashMap
List<Instructor> instructors = new ArrayList<>();
instructors.add(new Instructor("Felix"));
Instructor instructor = new Instructor("Felix");
instructors.contains(instructor);
public class RecipeBook {
private String name;
private Map<String, List<String>> recipes;
public RecipeBook(String name){
this.name = name;
this.recipes = new HashMap<>();
}
// REQUIRES: recipeName is not already in recipes
// MODIFIES: this
// EFFECTS: adds recipeName to recipes, and assigns an empty list of ingredients
public void addNewRecipe(String recipeName){
List<String> ingredients = new ArrayList<>();
//BLANK 1
}
// REQUIRES: recipeName is in recipes
// MODIFIES: this
// EFFECTS: adds ingredient to recipeName's list of ingredients
public void addToRecipe(String recipeName, String ingredient){
List<String> ingredients = recipes.get(recipeName);
//BLANK 2
}
public void printRecipes(){
System.out.println(this.recipes);
}
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null )
return false;
if (getClass() != obj.getClass())
return false
Instructor other = (Instructor) obj;
if (name != other.name )
return false
return true
}
auto-generated equals
@Override
public boolean equals(Object o) {
boolean equal = false;
if (o instanceof Instructor) {
Instructor that = (Instructor) o;
equal = this.name.equals(that.name);
}
return equal;
}
instanceof: Checks whether the object on the left is the same type or a subtype of the object on the right