Lab 4: Working with Abstract Classes, Problem Solving
Partners: You will get a partner in lab today. If you and another student *in your lab section* agree that you want to work together, you may make a request in handins to be partners. Both of you must make this request in handins. If you do not have a preference, we will randomly assign a partner for you.
You will work with your partner on Assignment 4.
Goals: The goals of this lab are to learn how to design and use abstract classes, and to solve problems with the use of accumulators.
Submission: (Due by the end of your lab period) Submit your solutions to Problem 1. You may work with your new partner on this, but the submission is individual. This will be graded on effort and good design. Problem 2 is extra practice, but highly recommended.
Problem 1: Tasks and abstraction
You are now extending the reminders program from Lab 3. You have decided to keep track of tasks specific to your classes. The following class diagram represents your updated task tracker system that records the class tasks you have to complete. For the purposes of this exercise, there are three kinds of class tasks: homework tasks, lab tasks, and in-class tasks.
All homework and lab tasks have 7 days to be completed, while in-class tasks only have 1 day to be completed. Homework tasks have a 10 percent deduction per day late, while other kinds of tasks have a 2 percent deduction per day late.
To update your program from Lab 3, each task still has its own description and an indication of whether the task has been completed or not. But now, each task also has a date created. Homework and lab tasks have a partner name representing who you are working with; in-class tasks are always individual, so it does not have a partner name.
The day when the task is created and the day it is due are counted as days since New Year’s Day in 2025. So, for example, a homework task created today would be recorded as created on day 35 with due date on day 42.
+-------+ | ITask | +-------+ / \ --- | ------------------------------------------------- | | | +--------------------+ +--------------------+ +--------------------+ | HomeworkTask | | LabTask | | InClassTask | +--------------------+ +--------------------+ +--------------------+ | String description | | String description | | String description | | boolean isDone | | boolean isDone | | boolean isDone | | int dateCreated | | int dateCreated | | int dateCreated | | String partnerName | | String partnerName | +--------------------+ +--------------------+ +--------------------+
Design the interface and classes that represent the updated task tracker system.
Define the abstract class ATask and lift those fields that can be lifted to this class.
Lift the provided draw, and drawCheckbox method into the abstract class.
Design the method daysOverdue that consumes the number that represents today in the reminders program system and produces the number of days this task is overdue. If the task has already been marked as done, the method returns 0. If the number is negative, the task still has that many days for it to be completed.
Design the method isOverdue that produces a boolean value that informs us whether the task is overdue on the given day. If the task has already been marked as done, the task is not overdue.
Design the method computePercentDeduction that computes the percentage deduction on the given day. If the task is not yet overdue, the percentage deduction is 0. If a homework task is overdue one day, it is a 10 percent deduction. If it is overdue two days, it is a 20 percent deduction. If a lab task is overdue two days, it is a 4 percent deduction.
Design the method haveWorkedWith in the Group class that determines if you have worked with the given name in the group of tasks. If the given name matches any partner name from the group of tasks, the method returns true. If the given name does not match any name from the group of tasks, the method returns false.
For all methods, think carefully whether they should be designed being implemented solely in the abstract class, implemented solely in the concrete classes, or implemented in the abstract class and then overridden in some of the concrete classes.
Problem 2: Problem Solving Practice
The rest of the lab will be dedicated to strengthening problem solving skills, in particular the use of accumulators. It will require you to create new classes as well as determine what helper methods would be appropriate.
Design a method on a list of integers which produces the integer (or throws an exception if the list was empty) that appears in the longest consecutive sublist. For example, the list of 1,1,5,5,5,4,3,4,4,4 would produce 5 (note that ties are broken by the sublist that appears earlier in the list).