Have you write a program that sets up Thursday’s lecture
Get you to think about different code organizations for problems that structure lists
Let you practice class hierarchy design or play with map and filter in Java
There is no separate advanced option this week because the lab is being used to set up for Thursday lecture. I appreciate that the programming question may seem easy for those with prior Java experience, but the point is to get you thinking about material we will discuss on Thursday (that can also be thought provoking for students with significant programming experience).
Up until now, all of the programs you have had to write (here and in CS1101 if you took it) needed a straightforward traversal of the input data (in CS1101 terms, they followed the templates). Often, we need to write programs that combine multiple tasks on the same data. Then we have to think about how to organize the code. This organizational task is called planning.
To set up for our discussion of planning on Thursday, we want you to write a program that involves multiple tasks.
Create a class called Planning and put your solution to that problem in that class.
The Problem Write a program called rainfall that consumes a LinkedList<Double> representing daily rainfall readings. The list may contain the number -999 indicating the end of the data of interest. Produce the average of the non-negative values in the list up to the first -999 (if it shows up). There may be negative numbers other than -999 in the list (representing faulty readings). If you cannot compute the average for whatever reason, return -1.
For example, given a list containing (1, -2, 5, -999, 8), the program would return 3 (the average of 1 and 5).
This problem is intentionally a bit vague, to give you practice turning a more realistic problem into a class hierarchy. Just figure out the class names and field declarations (names and types). You don’t need to write constructors, methods, etc. This would be a good problem to review with staff if you are unsure of your answers or just want a sanity check.
Problem: A medical research team needs to manage information about its experiments with mice. Each mouse is assigned to a particular regimen of a food to eat, how many grams of that food to eat per meal, how many treadmill workouts to do each day, and how many minutes each workout should last. Each day, the team weighs the mice, recording the date of the experiment along with the weight (and tying each piece of data to a specific mouse).
Design a set of classes to capture this scenario, including field names and types, any class extensions or abstract classes, and any interfaces you think you might need.
If you are confident in your ability to design class hierarchies, you could work through this description of how map and filter work in Java.
Submit a zip of the .java files that you produced for this assignment to the Lab 3 area via InstructAssist.