Lab Assignment 21_1 (Sets)

docx

School

Richland Community College *

*We aren’t endorsed by this school

Course

1436-8460

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

2

Uploaded by BaronFlagLion5

Report
COSC 2436 Lab Assignment 21_1 (Sets) NOTE: Your program should be your own work and not a copy of anyone else’s code. Copied code will not earn any points. (Keeping programs unique should not be too hard since you are naming the variables and functions yourself.) Don’t forget to add labels before everything you print. 1. Write a program named Lab21_1A that will create a set of grocery items and use set operations to see if recipes can be made from those items. Create a HashSet of Strings that will hold items you just bought from the grocery store Fill this set from the input file Lab21_1A1.txt Create a second HashSet of Strings of ingredients for your first recipe and fill it from input file Lab21_1A2.txt Create a third HashSet of Strings of ingredients for your second recipe and fill it from the input file Lab21_1A3.txt Call your method sending the grocery set and the first recipe set Call your method sending the grocery set and the second recipe set Print your remaining grocery set Write a void method that will accept the grocery HashSet and a recipe HashSet as parameters. It should do the following: o Using set operations, determine if the grocery item set contains everything in the recipe set (so you can make the recipe) o If it does: Print a statement that says the dish was made Print the ingredients in the recipe set Remove all the items in this recipe set from the grocery set (because you used them to make dinner.) o If it does not contain the recipe set: Print a statement saying that instead Print the recipe ingredients that are missing from the grocery set 2. Write a program named Lab21_1B . Create a secondary class named House . This class should have: o Private instance variables to hold the address (String), number of bedrooms (int) and square footage (int). o A constructor that receives a parameter matching each of the instance variables and fills them in. o An int method that returns the square footage of the house o A toString method that returns a string with all the instance variables and labels Write a MyComparator class that uses the square footage in each House object to compare objects. If the first house has larger square footage, return a 1; if it has smaller return a -1; equal returns a 0. In the (main class) main method: o Create a TreeSet of House objects.
COSC 2436 o Read data from the text file (Lab21_1B.txt) to create the House objects and add them to the TreeSet. o Create an iterator and use it to print the House Objects o Call your method to find the average house size, sending the TreeSet as a parameter, and print the returned value. Write a double method in the main class that receives the House TreeSet as a parameter. It should use an iterator to go through the TreeSet and total the square footage of the houses. Then it should calculate the average. (Don’t lose the decimals when you calculate the average.)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help