PBJ 1200: Introduction to Peanut Butter and Jelly

🥜 🧈 🍇 🍞 🥛 🍽️ 🥪

What is your name?

Hello, ! As a student who likes peanut butter & jelly, you should know how to make one! Well, you're in luck as we will teach you how to code the tastiest PB&J ever <3

Sadly, no one is perfect and this code is ridden with bugs!
Since no want wants a bug-infested PB&J, help us debug everything and you will be rewarded handsomely.

Part 1: Prepare the Bread

Files to submit: Bread.java, Knife.java

/*
This code contains the PBAndJ class, Bread class, and the main method.
*/

public class PBAndJ {
public static void assemble (Bread b1, Bread b2) {
System.out. println( "Hello World" )
}

public static void main() {
Bread topBread = new Bread("wheat");
Bread bottomBread = new Bread("wheat");
Knife knife = new Knife();
}
}

class Bread {
boolean spreaded;
boolean isCut;
boolean isToasted;
String expDate;
String flavor;

Bread(String flavor) {
expDate = ().toString();
isToasted = false;
this.flavor = flavor;
this.spreaded = false;
this.cut = false;
}

public String getExpDate() {
return expDate;
}
}

TERMINAL

Error: Bread is expired!

Part 2: Prepare the Peanut Butter

Files to submit: PeanutButter.java

/*
This code contains the PBAndJ class and the main method.
*/

public class PBAndJ {
public static void assemble (Bread b1, Bread b2) {
System.out. println ( "Hello World" );
}

public static void main() {
Bread topBread = new Bread("wheat");
Bread bottomBread = new Bread("wheat");
Knife knife = new Knife();
PeanutButter pb = new PeanutButter();
knife.spreadPB(pb, bottomBread);
}
}

/*
This code contains all classes that are referenced by the main method.
This includes Bread class, PeanutButter class, Knife class, and JellyJar class.
*/

class Bread {
boolean spreaded;
boolean isCut;
boolean isToasted;
String expDate;
String flavor;

Bread(String flavor) {
expDate = date.today().toString();
isToasted = false;
this.flavor = flavor;
this.spreaded = false;
this.cut = false;
}

public String getExpDate() {
return expDate;
}
}


class PeanutButter {
boolean ;

PeanutButter() {
isAllergic = ;
}
}

class Knife extends Bread, PBAndJ {
Knife() { }

public void spreadJelly(JellyJar j, Bread b) {
b.spreaded = true;
}

public void spreadPB(PeanutButter pb, Bread b) {
b.spreaded = ;
}

public void cut(PBAndJ pbj) {
pbj.isCut = true;
}
}

class JellyJar {
String flavor;
boolean isTight;

JellyJar(String flavor) {
this.flavor = flavor;
isTight = true;
}

public boolean openJar() {
if (isTight) {
throw new IllegalArgumentException("You're too weak and the jar is too tight");
} else {
return true;
}
}
}
TERMINAL

Error: You're allergic to Peanut Butter!

Part 3: Prepare the Jelly and make Sandwich

Files to submit: JellyJar.java

/*
This code contains the PBAndJ class and the main method.
*/

public class PBAndJ {
public static void assemble (Bread b1, Bread b2) {
System.out. println ( "Hello World" );
}

public static void main() {
Bread topBread = new Bread("wheat"){
Bread bottomBread = new Bread("wheat");
Knife knife = new Knife();
PeanutButter pb = new PeanutButter();
knife.spreadPB(pb);
JellyJar jelly = new JellyJar("grape");
jelly.openJar();
knife.spreadJelly(jelly, topBread);
assemble(bottomBread, topBread);
}
}

/*
This code contains all classes that are referenced by the main method.
This includes Bread class, PeanutButter class, Knife class, and JellyJar class.
*/

class Bread {
boolean spreaded;
boolean isCut;
boolean isToasted;
String expDate;
String flavor;

Bread(String flavor) {
expDate = date.today().toString();
isToasted = false;
this.flavor = flavor;
this.spreaded = false;
this.cut = false;
}

public String getExpDate() {
return expDate;
}
}


class PeanutButter {
boolean isAllergic;

PeanutButter() {
isAllergic = true;
}
}

class Knife extends Bread, PBAndJ {
Knife() { }

public void spreadJelly(JellyJar j, Bread b) {
b.spreaded = true;
}

public void spreadPB(PeanutButter pb, Bread b) {
b.spreaded = true;
}

public void cut(PBAndJ pbj) {
pbj.isCut = true;
}
}

class JellyJar {
String flavor;
boolean isTight;

JellyJar(String flavor) {
this.flavor = flavor;
isTight = ;
}

public boolean openJar() {
if (isTight) {
throw new IllegalArgumentException("You're too weak and the jar is too tight");
} else {
return true;
}
}
}
TERMINAL

Exception in thread "main" java.lang.IllegalArgumentException: You're too weak and the jar is too tight
at JellyJar.openJar(JellyJar.java:12)