Looking for clear explanation guidance on the following. I have attached Sample Code. Using the student object
Question:
Looking for clear explanation guidance on the following. I have attached Sample Code.
Using the student object from below code create an ArrayList of Students Objects
public class Student { private String name; private int id; private String module;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getModule() { return module; }
public void setModule(String module) { this.module = module; }
public Student(String mName, int mId, String mModule) { this.name = mName; this.id = mId; this.module = mModule; } }
Then:
try sorting your students using the comparable interface, sorting by ID
Then try using a Comparator object to sort by name
------------------------------------------------
Second Query:
Using the the following Recipes class
public class Recipe {
private String name; private boolean dairy; private boolean meat; private boolean gluten;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public boolean hasDairy() { return dairy; }
public boolean hasMeat() { return meat; }
public boolean hasGluten() { return gluten; }
public Recipe(String name, boolean dairy, boolean meat, boolean gluten) { super(); this.name = name; this.dairy = dairy; this.meat = meat; this.gluten = gluten; }
}
Store the Recipes in an ArrayList
Use thecomparable interface to sort vegan recipes first, then vegetarian then meat
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba