Can ChatGPT be Trusted to Bake your Matzah?
Earlier today, I gave an exam in Object Oriented Software Design. I wanted to test whether ChatGPT (4o model) could do better than my students on the exam. So, I took an image of the exam and asked it to answer.
The last question was about a Simple Matzah factory.
But, it was the last question on the exam, so the exam image was out of context. It first tried to make a question and answer about Dogs:
(9) Factory Pattern —
Dog
withbark()
a) Create an interface
Dog
interface Dog { void bark(); }
b) Implement at least two concrete dogs
class Poodle implements Dog {
public void bark() {
System.out.println("Yap yap!");
}
}
class Bulldog implements Dog {
public void bark() {
System.out.println("Woof!");
}
}
c) Implement a
DogFactory
class DogFactory {
public static Dog getDog(String type) {
switch (type.toLowerCase()) {
case "poodle":
return new Poodle();
case "bulldog":
return new Bulldog();
default:
throw new IllegalArgumentException("Unknown dog type: " + type);
}
}
}
Dog d1 = DogFactory.getDog("poodle");
d1.bark(); // Output: Yap yap!
Dog d2 = DogFactory.getDog("bulldog");
d2.bark(); // Output: Woof!
I pointed out that this was off, writing: “What does this have to do with question 9. Dogs??!”
So, ChatGPT (4o model) wrote back:
Haha — fair point! That dog factory answer was just a generic textbook example.
You're absolutely right — Question 9 on your exam is not about dogs at all. Let's look at what Question 9 actually asked based on the images you uploaded earlier.
Actual Question 9:
(9) Factory Pattern [10 points]
Write an interfacePita
and two implementations: oneRegular
and oneLaffa
.
Write aPitaFactory
that produces aPita
based on a boolean parameter:true
for regular,false
for laffa.
You should not usenew
in your driver code.
and then answered with:
Correct Answer to Question 9:
interface Pita {
void describe();
}
b) Two implementations:
class Regular implements Pita {
public void describe() {
System.out.println("Regular pita: small, round, fluffy.");
}
}
class Laffa implements Pita {
public void describe() {
System.out.println("Laffa pita: large, flat, chewy.");
}
}
class PitaFactory {
public static Pita makePita(boolean isRegular) {
if (isRegular) return new Regular();
else return new Laffa();
}
}
Pita p = PitaFactory.makePita(true);
p.describe(); // Output: Regular pita: small, round, fluffy.
Pita q = PitaFactory.makePita(false);
q.describe(); // Output: Laffa pita: large, flat, chewy.
I had to turn around and say, “Didn't i ask about a matza factory?”
At this point it replied, “You absolutely did — and you're 100% right again. The question was about a matza factory, not a pita one — I must’ve been hungry or stuck in Mediterranean carb mode. Let’s correct that:” and then finally generated a question and code, with a Matza interface, and Regular and Shmura classes implementing Matza.
Yikes! It seems that ChatGPT needs a gadol omed al gabav.