Skip to content

Commit

Permalink
Sample Solutions Updated (Fall 2022)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulnguyen committed Oct 1, 2022
1 parent 9b0514f commit 109d716
Show file tree
Hide file tree
Showing 42 changed files with 839 additions and 2 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file removed demos/demo4/counter-bluej/counter-bugger-uml.asta
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file added demos/demo4/counter-burger-uml.asta
Binary file not shown.
Binary file not shown.
Binary file removed demos/demo4/observer-bluej/observer-urml-parser.png
Binary file not shown.
Binary file added demos/demo4/observer-pattern-uml.asta
Binary file not shown.
4 changes: 2 additions & 2 deletions demos/demo6/five-guys-burger-bluej-lambda/package.bluej
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ editor.fx.0.width=0
editor.fx.0.x=0
editor.fx.0.y=0
objectbench.height=221
objectbench.width=616
package.divider.horizontal=0.5996150144369586
objectbench.width=575
package.divider.horizontal=0.5601539942252165
package.divider.vertical=0.6637168141592921
package.editor.height=443
package.editor.width=944
Expand Down
Binary file added demos/demo6/five-guys-burger-bluej-output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
134 changes: 134 additions & 0 deletions demos/demo8/counter-burger-updated-bluej/BuildOrder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@

public class BuildOrder {
public static Component getOrder()
{
Composite order = new Composite( "Order" ) ;

// Get Custom Burgers
CustomBurger customBurger1 = getBurger1() ;
CustomBurger customBurger2 = getBurger2() ;

// Add Custom Burger to the Order
order.addChild( customBurger1 );
order.addChild( customBurger2 );

return order ;
}

private static CustomBurger getBurger1() {
CustomBurger customBurger1 = new CustomBurger( "Build Your Own Burger" ) ;
// Burger
Burger b = new Burger( "Burger" ) ;
String[] bo = { "Organic Bison*", "1/2lb.", "On A Bun" } ;
b.setOptions( bo ) ;
// Cheese
Cheese c = new Cheese( "Cheese" ) ;
String[] co = { "Yellow American", "Spicy Jalapeno Jack" } ;
c.setOptions( co ) ;
c.wrapDecorator( b ) ;
// Premium Cheese
PremiumCheese pc = new PremiumCheese( "Premium Cheese" ) ;
String[] pco = { "Danish Blue Cheese" } ;
pc.setOptions( pco ) ;
pc.wrapDecorator( c ) ;
// Sauce
Sauce s = new Sauce( "Sauce" ) ;
String[] so = { "Mayonnaise", "Thai Peanut Sauce" } ;
s.setOptions( so ) ;
s.wrapDecorator( pc ) ;
// Unlimited Toppings
UnlimitedToppings ut = new UnlimitedToppings( "Unlimited Toppings" ) ;
String[] uto = { "Dill Pickle Chips", "Black Olives", "Spicy Pickles" } ;
ut.setOptions( uto ) ;
ut.wrapDecorator( s ) ;
// Premium Toppings
PremiumToppings pt = new PremiumToppings( "Premium Toppings" ) ;
String[] pto = { "Marinated Tomatoes" } ;
pt.setOptions( pto ) ;
pt.wrapDecorator( ut ) ;
// Bun Choice
BunChoice bc = new BunChoice( "Bun Choice" ) ;
String[] bco = { "Ciabatta (Vegan)" } ;
bc.setOptions( bco ) ;
bc.wrapDecorator( pt ) ;
// Extra Sides
ExtraSides ex = new ExtraSides( "Extra Sides" ) ;
String[] exo = { "Shoestring Fries" } ;
ex.setOptions( exo ) ;
ex.wrapDecorator( bc ) ;

// Setup Custom Burger Ingredients
customBurger1.setDecorator( ex ) ;
customBurger1.addChild( b ) ;
customBurger1.addChild( c ) ;
customBurger1.addChild( pc ) ;
customBurger1.addChild( s ) ;
customBurger1.addChild( ut ) ;
customBurger1.addChild( pt ) ;
customBurger1.addChild( bc ) ;
customBurger1.addChild( ex ) ;

// return custom burger
return customBurger1 ;
}

private static CustomBurger getBurger2() {

CustomBurger customBurger2 = new CustomBurger( "Build Your Own Burger" ) ;

// Burger
Burger b = new Burger( "Burger" ) ;
String[] bo = { "Hormone & Antibiotic Free Beef*", "1/3lb.", "On A Bun" } ;
b.setOptions( bo ) ;
// Cheese
Cheese c = new Cheese( "Cheese" ) ;
String[] co = { "Smoked Gouda", "Greek Feta" } ;
c.setOptions( co ) ;
c.wrapDecorator( b ) ;
// Premium Cheese
PremiumCheese pc = new PremiumCheese( "Premium Cheese" ) ;
String[] pco = { "Fresh Mozzarella" } ;
pc.setOptions( pco ) ;
pc.wrapDecorator( c ) ;
// Sauce
Sauce s = new Sauce( "Sauce" ) ;
String[] so = { "Habanero Salsa" } ;
s.setOptions( so ) ;
s.wrapDecorator( pc ) ;
// Unlimited Toppings
UnlimitedToppings ut = new UnlimitedToppings( "Unlimited Toppings" ) ;
String[] uto = { "Crushed Peanuts" } ;
ut.setOptions( uto ) ;
ut.wrapDecorator( s ) ;
// Premium Toppings
PremiumToppings pt = new PremiumToppings( "Premium Toppings" ) ;
String[] pto = { "Sunny Side Up Egg*", "Marinated Tomatoes" } ;
pt.setOptions( pto ) ;
pt.wrapDecorator( ut ) ;
// Bun Choice
BunChoice bc = new BunChoice( "Bun Choice" ) ;
String[] bco = { "Gluten-Free Bun" } ;
bc.setOptions( bco ) ;
bc.wrapDecorator( pt ) ;
// Extra Sides
ExtraSides ex = new ExtraSides( "Extra Sides" ) ;
String[] exo = { "Shoestring Fries" } ;
ex.setOptions( exo ) ;
ex.wrapDecorator( bc ) ;

// Setup Custom Burger Ingredients
customBurger2.setDecorator( ex ) ;
customBurger2.addChild( b ) ;
customBurger2.addChild( c ) ;
customBurger2.addChild( pc ) ;
customBurger2.addChild( s ) ;
customBurger2.addChild( ut ) ;
customBurger2.addChild( pt ) ;
customBurger2.addChild( bc ) ;
customBurger2.addChild( ex ) ;

// return custom burger
return customBurger2 ;
}

}
35 changes: 35 additions & 0 deletions demos/demo8/counter-burger-updated-bluej/BunChoice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

public class BunChoice extends LeafDecorator
{
private String[] options ;


public BunChoice( String d )
{
super(d) ;
}

public void setOptions( String[] options )
{
this.options = options ;
for ( int i = 0; i<options.length; i++ )
{
if ( "Gluten-Free Bun".equals(options[i]) ) this.price += 1.00 ;
else if ( "Hawailan Bun".equals(options[i]) ) this.price += 1.00 ;
else if ( "Pretzel Bun".equals(options[i]) ) this.price += 0.50 ;
else this.price += 0.00 ;
}
}

public String getDescription()
{
String desc = "" ;
for ( int i = 0; i<options.length; i++ )
{
if (i>0) desc += " + " + options[i] ;
else desc = options[i] ;
}
return desc ;
}

}
36 changes: 36 additions & 0 deletions demos/demo8/counter-burger-updated-bluej/Burger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
public class Burger extends LeafDecorator
{
private String[] options ;


public Burger( String d )
{
super(d) ;
}

public void setOptions( String[] options )
{
this.options = options ;
for ( int i = 0; i<options.length; i++ )
{
if ( "1/3lb.".equals(options[i]) ) this.price += 9.00 ;
if ( "1/2lb.".equals(options[i]) ) this.price += 12.00 ;
if ( "1lb.".equals(options[i]) ) this.price += 18.00 ;
if ( "In A Bowl".equals(options[i]) ) this.price += 1.50 ;
if ( "Organic Bison*".equals(options[i]) ) this.price += 4.00 ;
if ( "Ahi Tuna*".equals(options[i]) ) this.price += 4.00 ;
}
}

public String getDescription()
{
String desc = "" ;
for ( int i = 0; i<options.length; i++ )
{
if (i>0) desc += " + " + options[i] ;
else desc = options[i] ;
}
return desc ;
}

}
30 changes: 30 additions & 0 deletions demos/demo8/counter-burger-updated-bluej/Cheese.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
public class Cheese extends LeafDecorator
{
private String[] options ;


public Cheese( String d )
{
super(d) ;
}

// 1 cheese free, extra cheese +1.00
public void setOptions( String[] options )
{
this.options = options ;
if ( options.length > 1 )
this.price += (options.length-1) * 1.00 ;
}

public String getDescription()
{
String desc = "" ;
for ( int i = 0; i<options.length; i++ )
{
if (i>0) desc += " + " + options[i] ;
else desc = options[i] ;
}
return desc ;
}

}
12 changes: 12 additions & 0 deletions demos/demo8/counter-burger-updated-bluej/Client.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


public class Client {

public static void runTest()
{
Component theOrder = BuildOrder.getOrder() ;
theOrder.printDescription();

}
}

11 changes: 11 additions & 0 deletions demos/demo8/counter-burger-updated-bluej/Component.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


public interface Component {

void printDescription() ;
void addChild(Component c);
void removeChild(Component c);
Component getChild(int i);

}

36 changes: 36 additions & 0 deletions demos/demo8/counter-burger-updated-bluej/Composite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@


import java.util.ArrayList;

public class Composite implements Component {

protected ArrayList<Component> components = new ArrayList<Component>() ;
protected String description ;

public Composite ( String d )
{
description = d ;
}

public void printDescription() {
System.out.println( "\n" + description );
for (Component obj : components)
{
obj.printDescription();
}
}

public void addChild(Component c) {
components.add( c ) ;
}

public void removeChild(Component c) {
components.remove(c) ;
}

public Component getChild(int i) {
return components.get( i ) ;
}

}

28 changes: 28 additions & 0 deletions demos/demo8/counter-burger-updated-bluej/CustomBurger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

import java.text.DecimalFormat;

public class CustomBurger extends Composite
{
PriceDecorator decorator = null ;

public CustomBurger ( String d )
{
super(d) ;
}

public void setDecorator( PriceDecorator p )
{
this.decorator = p ;
}

public void printDescription() {
DecimalFormat fmt = new DecimalFormat("0.00");
System.out.println( "\n\n" + description + " " + fmt.format(decorator.getPrice()) );
for (Component obj : components)
{
obj.printDescription();
}
}
}


29 changes: 29 additions & 0 deletions demos/demo8/counter-burger-updated-bluej/ExtraSides.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

public class ExtraSides extends LeafDecorator
{
private String[] options ;


public ExtraSides( String d )
{
super(d) ;
}

public void setOptions( String[] options )
{
this.options = options ;
this.price += (options.length) * 3.00 ;
}

public String getDescription()
{
String desc = "" ;
for ( int i = 0; i<options.length; i++ )
{
if (i>0) desc += " + " + options[i] ;
else desc = options[i] ;
}
return desc ;
}

}
Loading

0 comments on commit 109d716

Please sign in to comment.