You may make a copy of a worksheet and complete this activity, or type your answers in any text editor.
You may work alone or with another student in this course (max team size = 2)
Consider an implementation of the old engineering joke: Good, Fast, Cheap.
public final class GoodFastCheap
{
boolean good = false;
boolean fast = false;
boolean cheap = false;
public void makeGood ()
{
good = true;
if (fast && cheap) { cheap = false; }
}
public void makeFast ()
{
fast = true;
if (good && cheap) { good = false; }
}
public void makeCheap ()
{
cheap = true;
if (fast && good) { fast = false; }
}
public void makeBad () { good = false; }
public void makeSlow () { fast = false; }
public void makeExpensive () { cheap = false; }
public boolean isSatisfactory()
{
if ((good && fast) || (good && cheap) || (fast && cheap))
return true;
return false;
}
public static void main(String[] args)
{
// Question: How well do the following tests exercise the clauses?
GoodFastCheap gfc = new GoodFastCheap(); // g f c
gfc.isSatisfactory(); // F F F
gfc.makeGood(); gfc.isSatisfactory(); // T F F
gfc.makeFast(); gfc.isSatisfactory(); // T T F
gfc.makeCheap(); gfc.isSatisfactory(); // T F T
gfc.makeSlow(); gfc.isSatisfactory(); // T F T
}
}
Focus on the predicate in isSatisfactory().
We will start with the truth table.
(Note: in reality, if tools are available, use the tools.
For practice purposes and to help you prepare for the exam: we will fill the truth table ourselves)
| Row# | g | f | c | P | Pg | Pf | Pc |
|---|---|---|---|---|---|---|---|
| 1 | T | T | T | ||||
| 2 | T | T | |||||
| 3 | T | T | |||||
| 4 | T | ||||||
| 5 | T | T | |||||
| 6 | T | ||||||
| 7 | T | ||||||
| 8 |
main() method achieve RACC?
isSatisfactory()
public boolean isSatisfactory()
{
if (good && fast) return true;
if (good && cheap) return true;
if (fast && cheap) return true;
return false;
}
CC-BY-NC-SA 4.0 license.