Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Task 1 Creating ArrayList of Student Objects and Sorting First lets create an ArrayList of Student objects java import javautilArrayList public class ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microeconomics An Intuitive Approach with Calculus

Authors: Thomas Nechyba

1st edition

538453257, 978-0538453257

More Books

Students also viewed these Programming questions

Question

Illustrate the systems approach of family therapy.

Answered: 1 week ago