main
Michael Kowalczyk 11 months ago
parent 1cda7cceb1
commit 5a9c9516fd

@ -1,3 +0,0 @@
Sprint planning:
Determine tasks to be completed this week, with quick difficulty estimates. Tasks should be relatively small, specific, completable pieces of work. Plan how it's going to get done. Use the kanban in Gitea to populate it. Spring ends with next Monday's class meeting.

@ -0,0 +1,177 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill-opacity="1" color-rendering="auto" color-interpolation="auto" text-rendering="auto" stroke="black" stroke-linecap="square" width="604" stroke-miterlimit="10" shape-rendering="auto" stroke-opacity="1" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" height="526" font-family="'Dialog'" font-style="normal" stroke-linejoin="miter" font-size="12px" stroke-dashoffset="0" image-rendering="auto">
<!--Generated by ySVG 2.5-->
<defs id="genericDefs"/>
<g>
<defs id="defs1">
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath1">
<path d="M0 0 L604 0 L604 526 L0 526 L0 0 Z"/>
</clipPath>
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath2">
<path d="M413 231 L1017 231 L1017 757 L413 757 L413 231 Z"/>
</clipPath>
</defs>
<g stroke-linecap="butt" transform="matrix(1,0,0,1,-413,-231)" fill="rgb(153,153,153)" text-rendering="geometricPrecision" shape-rendering="geometricPrecision" stroke-dasharray="6,2" stroke="rgb(153,153,153)" stroke-miterlimit="1.45">
<rect fill="none" x="520.46" width="175" height="175" y="237.84" clip-path="url(#clipPath2)"/>
</g>
<g stroke-linecap="butt" transform="matrix(1,0,0,1,-413,-231)" fill="white" text-rendering="geometricPrecision" shape-rendering="geometricPrecision" stroke="white" stroke-miterlimit="1.45">
<circle fill="none" r="2.84" clip-path="url(#clipPath2)" cx="692.62" cy="240.68"/>
<circle fill="none" r="2.84" clip-path="url(#clipPath2)" cx="588.62" cy="277.84"/>
<circle fill="none" r="2.84" clip-path="url(#clipPath2)" cx="523.3" cy="410.84"/>
<circle fill="none" r="2.84" clip-path="url(#clipPath2)" cx="419.3" cy="448"/>
</g>
<g text-rendering="geometricPrecision" shape-rendering="geometricPrecision" transform="matrix(1,0,0,1,-413,-231)">
<circle r="8" clip-path="url(#clipPath2)" cx="556.1243" cy="267" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="556.1243" cy="267" stroke-miterlimit="1.45"/>
<circle fill="green" r="8" clip-path="url(#clipPath2)" cx="642.7886" cy="344.271" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="642.7886" cy="344.271" stroke-width="2" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="475.1173" cy="347.271" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="475.1173" cy="347.271" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="475.1173" cy="400" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="475.1173" cy="400" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="588.62" cy="333.5584" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="588.62" cy="333.5584" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="550.7886" cy="430.7021" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="550.7886" cy="430.7021" stroke-miterlimit="1.45"/>
</g>
<g stroke-linecap="butt" transform="matrix(1,0,0,1,-413,-231)" fill="rgb(153,153,153)" text-rendering="geometricPrecision" shape-rendering="geometricPrecision" stroke-dasharray="6,2" stroke="rgb(153,153,153)" stroke-miterlimit="1.45">
<rect fill="none" x="836.8027" width="175" height="175" y="234.84" clip-path="url(#clipPath2)"/>
<rect x="732.8027" y="272.84" clip-path="url(#clipPath2)" fill="none" width="175" height="175" stroke="black"/>
<circle clip-path="url(#clipPath2)" fill="none" r="2.84" stroke-dasharray="none" cx="1008.9627" cy="237.68" stroke="white"/>
<circle clip-path="url(#clipPath2)" fill="none" r="2.84" stroke-dasharray="none" cx="904.9627" cy="274.84" stroke="white"/>
<circle clip-path="url(#clipPath2)" fill="none" r="2.84" stroke-dasharray="none" cx="839.6427" cy="407.84" stroke="white"/>
<circle clip-path="url(#clipPath2)" fill="none" r="2.84" stroke-dasharray="none" cx="735.6427" cy="445" stroke="white"/>
</g>
<g text-rendering="geometricPrecision" shape-rendering="geometricPrecision" transform="matrix(1,0,0,1,-413,-231)">
<circle r="8" clip-path="url(#clipPath2)" cx="929.467" cy="253" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="929.467" cy="253" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="971.1314" cy="378.271" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="971.1314" cy="378.271" stroke-miterlimit="1.45"/>
<circle fill="green" r="8" clip-path="url(#clipPath2)" cx="791.46" cy="344.271" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="791.46" cy="344.271" stroke-width="2" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="776.4827" cy="419" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="776.4827" cy="419" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="925.1314" cy="407.84" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="925.1314" cy="407.84" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="867.1314" cy="427.7021" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="867.1314" cy="427.7021" stroke-miterlimit="1.45"/>
</g>
<g stroke-linecap="butt" transform="matrix(1,0,0,1,-413,-231)" fill="rgb(153,153,153)" text-rendering="geometricPrecision" shape-rendering="geometricPrecision" stroke-dasharray="6,2" stroke="rgb(153,153,153)" stroke-miterlimit="1.45">
<rect fill="none" x="521.2886" width="175" height="174.4" y="505.9" clip-path="url(#clipPath2)"/>
<circle clip-path="url(#clipPath2)" fill="none" r="2.84" stroke-dasharray="none" cx="693.4486" cy="508.24" stroke="white"/>
<circle clip-path="url(#clipPath2)" fill="none" r="2.84" stroke-dasharray="none" cx="589.4486" cy="545.4" stroke="white"/>
<circle clip-path="url(#clipPath2)" fill="none" r="2.84" stroke-dasharray="none" cx="524.1286" cy="678.4" stroke="white"/>
<circle clip-path="url(#clipPath2)" fill="none" r="2.84" stroke-dasharray="none" cx="420.1286" cy="715.56" stroke="white"/>
</g>
<g text-rendering="geometricPrecision" shape-rendering="geometricPrecision" transform="matrix(1,0,0,1,-413,-231)">
<circle r="8" clip-path="url(#clipPath2)" cx="600.2886" cy="522.2592" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="600.2886" cy="522.2592" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="659.953" cy="602.1184" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="659.953" cy="602.1184" stroke-width="2" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="475.9459" cy="564.831" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="475.9459" cy="564.831" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="451.9459" cy="645.831" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="451.9459" cy="645.831" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="613.953" cy="659.1184" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="613.953" cy="659.1184" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="529.2886" cy="698.2621" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="529.2886" cy="698.2621" stroke-miterlimit="1.45"/>
</g>
<g stroke-linecap="butt" transform="matrix(1,0,0,1,-413,-231)" fill="rgb(153,153,153)" text-rendering="geometricPrecision" shape-rendering="geometricPrecision" stroke-dasharray="6,2" stroke="rgb(153,153,153)" stroke-miterlimit="1.45">
<rect fill="none" x="837.6314" width="175" height="174.2" y="506" clip-path="url(#clipPath2)"/>
<circle clip-path="url(#clipPath2)" fill="none" r="2.84" stroke-dasharray="none" cx="1009.7914" cy="505.24" stroke="white"/>
<circle clip-path="url(#clipPath2)" fill="none" r="2.84" stroke-dasharray="none" cx="905.7914" cy="542.4" stroke="white"/>
<circle clip-path="url(#clipPath2)" fill="none" r="2.84" stroke-dasharray="none" cx="840.4714" cy="675.4" stroke="white"/>
<circle clip-path="url(#clipPath2)" fill="none" r="2.84" stroke-dasharray="none" cx="736.4714" cy="712.56" stroke="white"/>
</g>
<g text-rendering="geometricPrecision" shape-rendering="geometricPrecision" transform="matrix(1,0,0,1,-413,-231)">
<circle r="8" clip-path="url(#clipPath2)" cx="864.9514" cy="524.831" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="864.9514" cy="524.831" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="971.96" cy="645.831" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="971.96" cy="645.831" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="777.3114" cy="573.831" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="777.3114" cy="573.831" stroke-width="2" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="777.3114" cy="686.56" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="777.3114" cy="686.56" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="936.2957" cy="685.4" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="936.2957" cy="685.4" stroke-miterlimit="1.45"/>
<circle r="8" clip-path="url(#clipPath2)" cx="867.96" cy="618.2621" stroke="none"/>
<circle stroke-linecap="butt" clip-path="url(#clipPath2)" fill="none" r="8" cx="867.96" cy="618.2621" stroke-miterlimit="1.45"/>
<rect stroke-linecap="butt" x="733.6314" y="540.4" clip-path="url(#clipPath2)" fill="none" width="175" stroke-dasharray="6,2" height="175" stroke-miterlimit="1.45"/>
<rect stroke-linecap="butt" x="417.2886" y="543.4" clip-path="url(#clipPath2)" fill="none" width="175" stroke-dasharray="6,2" height="175" stroke-miterlimit="1.45"/>
<rect stroke-linecap="butt" x="416.46" y="275.84" clip-path="url(#clipPath2)" fill="none" width="175" stroke-dasharray="6,2" height="175" stroke-miterlimit="1.45"/>
<path fill="none" stroke-miterlimit="1.45" stroke-dasharray="6,2" d="M689.9456 241.6356 L591.2944 276.8844" clip-path="url(#clipPath2)" stroke-linecap="butt"/>
</g>
<g font-size="20px" stroke-linecap="butt" transform="matrix(1,0,0,1,-413,-231)" text-rendering="geometricPrecision" font-family="'Tahoma'" shape-rendering="geometricPrecision" stroke-miterlimit="1.45">
<text x="418.2065" xml:space="preserve" y="483.1794" clip-path="url(#clipPath2)" stroke="none">a) Good (loose coupling, high cohesion)</text>
<path fill="none" stroke-dasharray="6,2" d="M520.6256 411.7956 L421.9744 447.0444" clip-path="url(#clipPath2)"/>
</g>
<g stroke-linecap="butt" transform="matrix(1,0,0,1,-413,-231)" fill="navy" text-rendering="geometricPrecision" shape-rendering="geometricPrecision" stroke="navy" stroke-width="3" stroke-miterlimit="1.45">
<path fill="none" d="M562.0955 272.324 L636.8174 338.9471" clip-path="url(#clipPath2)"/>
<path fill="none" d="M550.4417 272.631 L480.7999 341.64" clip-path="url(#clipPath2)"/>
<path fill="none" d="M475.1173 392 L475.1173 355.271" clip-path="url(#clipPath2)"/>
<path fill="none" d="M482.7089 397.4767 L635.197 346.7943" clip-path="url(#clipPath2)"/>
<path fill="none" d="M483.0595 346.3115 L580.6777 334.5179" clip-path="url(#clipPath2)"/>
<path fill="none" d="M596.468 335.1104 L634.9406 342.719" clip-path="url(#clipPath2)"/>
<path fill="none" d="M482.5304 403.0077 L543.3755 427.6944" clip-path="url(#clipPath2)"/>
<path fill="none" d="M555.8637 274.9958 L551.0493 422.7063" clip-path="url(#clipPath2)"/>
<path fill="none" d="M553.6918 423.2474 L585.7169 341.0131" clip-path="url(#clipPath2)"/>
</g>
<g text-rendering="geometricPrecision" stroke-miterlimit="1.45" stroke-dasharray="6,2" shape-rendering="geometricPrecision" transform="matrix(1,0,0,1,-413,-231)" stroke-linecap="butt">
<path fill="none" d="M836.8012 236.3815 L733.9144 272.8351" clip-path="url(#clipPath2)"/>
<path fill="none" d="M1011.8027 408.84 L908.8027 447.84" clip-path="url(#clipPath2)"/>
<path fill="none" d="M1006.2883 238.6356 L907.6371 273.8844" clip-path="url(#clipPath2)"/>
<path fill="none" d="M836.9683 408.7956 L738.3171 444.0444" clip-path="url(#clipPath2)"/>
</g>
<g stroke-linecap="butt" transform="matrix(1,0,0,1,-413,-231)" fill="navy" text-rendering="geometricPrecision" shape-rendering="geometricPrecision" stroke="navy" stroke-width="3" stroke-miterlimit="1.45">
<path fill="none" d="M931.9918 260.5912 L968.6066 370.6799" clip-path="url(#clipPath2)"/>
<path fill="none" d="M922.7943 257.413 L798.1328 339.858" clip-path="url(#clipPath2)"/>
<path fill="none" d="M650.7886 344.271 L783.46 344.271" clip-path="url(#clipPath2)" stroke="green"/>
<path fill="none" d="M799.3205 345.7585 L963.2709 376.7836" clip-path="url(#clipPath2)"/>
<path fill="none" d="M778.0548 411.156 L789.8879 352.1151" clip-path="url(#clipPath2)"/>
<path fill="none" d="M784.3131 417.3615 L963.301 379.9095" clip-path="url(#clipPath2)"/>
<path fill="none" d="M798.6846 347.7068 L917.9067 404.4042" clip-path="url(#clipPath2)"/>
<path fill="none" d="M931.861 403.5142 L964.4018 382.5968" clip-path="url(#clipPath2)"/>
<path fill="none" d="M784.4461 419.7645 L859.168 426.9376" clip-path="url(#clipPath2)"/>
<path fill="none" d="M926.7786 260.5347 L869.8198 420.1674" clip-path="url(#clipPath2)"/>
<path fill="none" d="M796.8346 350.1967 L861.7568 421.7764" clip-path="url(#clipPath2)"/>
<path fill="none" d="M874.6999 425.1103 L917.5629 410.4318" clip-path="url(#clipPath2)"/>
</g>
<g text-rendering="geometricPrecision" stroke-miterlimit="1.45" stroke-dasharray="6,2" shape-rendering="geometricPrecision" transform="matrix(1,0,0,1,-413,-231)" stroke-linecap="butt">
<path fill="none" d="M690.7742 509.1956 L592.123 544.4444" clip-path="url(#clipPath2)"/>
<text x="420.0541" font-size="20px" y="747.1794" clip-path="url(#clipPath2)" font-family="'Tahoma'" stroke-dasharray="none" stroke="none" xml:space="preserve">b) Bad (high coupling, low cohesion)</text>
<path fill="none" d="M521.4542 679.3556 L422.803 714.6044" clip-path="url(#clipPath2)"/>
</g>
<g stroke-linecap="butt" transform="matrix(1,0,0,1,-413,-231)" fill="navy" text-rendering="geometricPrecision" shape-rendering="geometricPrecision" stroke="navy" stroke-width="3" stroke-miterlimit="1.45">
<path fill="none" d="M605.0768 528.668 L655.1648 595.7095" clip-path="url(#clipPath2)"/>
<path fill="none" d="M592.72 524.8505 L483.5146 562.2397" clip-path="url(#clipPath2)"/>
<path fill="none" d="M459.7749 644.1858 L652.124 603.7637" clip-path="url(#clipPath2)"/>
<path fill="none" d="M618.9771 652.8928 L654.9288 608.344" clip-path="url(#clipPath2)"/>
<path fill="none" d="M536.5501 694.9048 L606.6915 662.4756" clip-path="url(#clipPath2)"/>
</g>
<g text-rendering="geometricPrecision" stroke-miterlimit="1.45" stroke-dasharray="6,2" shape-rendering="geometricPrecision" transform="matrix(1,0,0,1,-413,-231)" stroke-linecap="butt">
<path fill="none" d="M1007.1169 506.1956 L908.4658 541.4444" clip-path="url(#clipPath2)"/>
<path fill="none" d="M837.7969 676.3556 L739.1458 711.6044" clip-path="url(#clipPath2)"/>
</g>
<g stroke-linecap="butt" transform="matrix(1,0,0,1,-413,-231)" fill="red" text-rendering="geometricPrecision" shape-rendering="geometricPrecision" stroke="red" stroke-width="3" stroke-miterlimit="1.45">
<path fill="none" d="M483.904 564.0128 L856.9933 525.6494" clip-path="url(#clipPath2)"/>
<path fill="none" d="M870.2511 530.8237 L966.6602 639.8383" clip-path="url(#clipPath2)" stroke="navy"/>
<path fill="none" d="M537.2331 697.3211 L964.0155 646.772" clip-path="url(#clipPath2)"/>
<path fill="none" d="M459.9459 645.8311 L963.96 645.8311" clip-path="url(#clipPath2)"/>
<path fill="none" d="M857.9686 528.7351 L784.2941 569.9269" clip-path="url(#clipPath2)" stroke="navy"/>
<path fill="none" d="M667.7302 600.2438 L769.5341 575.7056" clip-path="url(#clipPath2)"/>
<path fill="none" d="M777.3113 678.56 L777.3113 581.8311" clip-path="url(#clipPath2)" stroke="navy"/>
<path fill="none" d="M607.4852 525.7534 L929.0991 681.9059" clip-path="url(#clipPath2)"/>
<path fill="none" d="M783.7008 681.746 L861.5706 623.0761" clip-path="url(#clipPath2)" stroke="navy"/>
<path fill="none" d="M873.6666 623.8687 L930.5891 679.7934" clip-path="url(#clipPath2)" stroke="navy"/>
</g>
<g text-rendering="geometricPrecision" stroke-miterlimit="1.45" stroke-dasharray="6,2" shape-rendering="geometricPrecision" transform="matrix(1,0,0,1,-413,-231)" stroke-linecap="butt">
<path fill="none" d="M837.6298 507.1415 L734.8445 540.3959" clip-path="url(#clipPath2)"/>
<path fill="none" d="M1012.6313 679.6 L909.6313 715.4" clip-path="url(#clipPath2)"/>
<path fill="none" d="M521.2871 507.1415 L418.4003 543.3973" clip-path="url(#clipPath2)"/>
<path fill="none" d="M696.2886 679.6 L593.2886 718.4" clip-path="url(#clipPath2)"/>
<path fill="none" d="M520.4585 239.3815 L417.5716 275.8351" clip-path="url(#clipPath2)"/>
<path fill="none" d="M695.46 411.84 L592.46 450.84" clip-path="url(#clipPath2)"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 18 KiB

@ -0,0 +1,26 @@
public class CoinInventory {
private int[] coinCounts; //cp (pennies), sp (dimes), ep (half-dollars), gp (dollar bills), pp (five dollar bills)
private int weight; //The weight is the sum of all the coins.
public CoinInventory() {
coinCounts = new int[5];
}
public void setCoins(int[] a) {
coinCounts = a;
}
public int[] getCoins() {
return coinCounts;
}
public void setWeight(int w) {
weight = w;
}
public int getWeight() {
return weight;
}
}

@ -0,0 +1,18 @@
public class Item {
private String description;
private int weight;
public Item(String description, int weight) {
this.description = description;
this.weight = weight;
}
public int getWeight() {
return weight;
}
public String getDescription() {
return description;
}
}

@ -0,0 +1,77 @@
//The design among these 3 classes needs improvement, and the code has a couple of bugs, too.
//Improve the design and fix the bugs.
//The public interface of Player should remain the same as it is now.
//Hints:
//Avoid duplicate data
//Methods and instance data should have high cohesion
//Coupling should be loose between classes
import java.util.*;
public class Player {
private String name;
private CoinInventory coinInventory;
private ArrayList<Item> otherInventory;
private int encumbrance;
public Player(String name) {
this.name = name;
coinInventory = new CoinInventory();
otherInventory = new ArrayList<Item>();
encumbrance = 0;
}
public void addItem(Item item) {
otherInventory.add(item);
}
public void collectMoney(int cp, int sp, int ep, int gp, int pp) {
int[] moneys = coinInventory.getCoins();
moneys[0] += cp;
moneys[1] += sp;
moneys[2] += ep;
moneys[3] += gp;
moneys[4] += pp;
coinInventory.setCoins(moneys);
}
public double getRunningSpeed() {
double speed = 5 * (1 - getEncumbrance() / 1000.0); //Speed 5 if unencumbered; speed 0 if 1000 units carried or more.
if (speed < 0) {
return 0;
}
else {
return speed;
}
}
public double getMoneyValue() {
int[] moneys = coinInventory.getCoins();
return .01 * moneys[0] + .1 * moneys[1] + .5 * moneys[2] + 1 * moneys[3] + 5 * moneys[4];
}
public int getEncumbrance() {
int[] moneys = coinInventory.getCoins();
return moneys[0] + moneys[1] + moneys[2] + moneys[3] + moneys[4] + encumbrance;
}
//Test method.
public static void main(String[] args) {
Player p = new Player("Whistlestick");
Item sword = new Item("Magic sword +2", 20);
Item shield = new Item("Normal shield", 40);
p.addItem(sword);
p.addItem(shield);
if (p.getEncumbrance() != 60) throw new RuntimeException("getEncumbrance() should be 60, not " + p.getEncumbrance());
p.collectMoney(10,2,0,40,2);
if (p.getEncumbrance() != 60+54) throw new RuntimeException("getEncumbrance() should be 114, not " + p.getEncumbrance());
if (p.getMoneyValue() != 50.3) throw new RuntimeException("getMoneyValue() should be 50.3, not " + p.getMoneyValue());
p.collectMoney(0,0,0,6,0);
if (p.getEncumbrance() != 120) throw new RuntimeException("getEncumbrance() should be 120, not " + p.getEncumbrance());
if (p.getRunningSpeed() != 4.4) throw new RuntimeException("getRunningSpeed() should be 4.4, not " + p.getRunningSpeed());
System.out.println("All tests passed.");
}
}

@ -0,0 +1,5 @@
@ECHO OFF
C:
CD "\stuff\cs495\notes\Day 38 (class and function design)\Improve the design"
"C:\Program Files\Microsoft\jdk-11.0.12.7-hotspot\bin\java.exe" -cp .;"C:\Program Files\Java\javafx-sdk-17.0.0.1\lib\javafx.base.jar";"C:\Program Files\Java\javafx-sdk-17.0.0.1\lib\javafx.controls.jar";"C:\Program Files\Java\javafx-sdk-17.0.0.1\lib\javafx.fxml.jar";"C:\Program Files\Java\javafx-sdk-17.0.0.1\lib\javafx.graphics.jar";"C:\Program Files\Java\javafx-sdk-17.0.0.1\lib\javafx.media.jar";"C:\Program Files\Java\javafx-sdk-17.0.0.1\lib\javafx.swing.jar";"C:\Program Files\Java\javafx-sdk-17.0.0.1\lib\javafx.web.jar";"C:\Program Files\Java\javafx-sdk-17.0.0.1\lib\javafx-swt.jar" --module-path "C:\Program Files\Java\javafx-sdk-17.0.0.1\lib" --add-modules=javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web Player
PAUSE

@ -0,0 +1,18 @@
import java.util.*;
import java.io.*;
public class CS495 {
public static void main(String[] args) throws IOException {
ArrayList<Student> students = new ArrayList<Student>();
Scanner in = new Scanner(new File("superheroes.txt"));
while(in.hasNextLine()) {
String s = in.nextLine();
students.add(new Student(s));
}
in.close();
for(Student s : students) {
System.out.println(s);
}
}
}

@ -0,0 +1,17 @@
public class Student {
public static int nextStudentID = 1;
private int id;
private String name;
public Student(String name) {
id = nextStudentID;
nextStudentID++;
this.name = name;
}
public String toString() {
return "Student ID: " +id+ ", name: "+name;
}
}

@ -0,0 +1,12 @@
Clark Kent
Bruce Wayne
Hal Jordan
Oliver Queen
Steve Rogers
Barry Allen
Barbara Gordon
Tony Stark
Peter Parker
Billy Batson
Bruce Banner
Diana Prince

@ -0,0 +1,25 @@
// Two problems with information hiding in this example program.
public class CS495 {
public static int nextStudentID = 1;
public static void main(String[] args) {
Student[] students = new Student[12];
students[0] = new Student("Clark Kent");
students[1] = new Student("Bruce Wayne");
students[2] = new Student("Hal Jordan");
students[3] = new Student("Oliver Queen");
students[4] = new Student("Steve Rogers");
students[5] = new Student("Barry Allen");
students[6] = new Student("Barbara Gordon");
students[7] = new Student("Tony Stark");
students[8] = new Student("Peter Parker");
students[9] = new Student("Billy Batson");
students[10] = new Student("Bruce Banner");
students[11] = new Student("Diana Prince");
for(Student s : students) {
System.out.println(s);
}
}
}

@ -0,0 +1,15 @@
public class Student {
private int id;
private String name;
public Student(String name) {
id = CS495.nextStudentID;
CS495.nextStudentID++;
this.name = name;
}
public String toString() {
return "Student ID: " +id+ ", name: "+name;
}
}

@ -0,0 +1,25 @@
Most common reasons for project failure: Poor requirements/planning/management
Most common *technical* reason for project failure: unmanaged complexity
Abstraction: from the outside, we view an object or function as a coherent idea on a high level of detail
Information hiding / encapsulation: from the outside, internal implementation details are not viewable
Loose coupling:
* Size (prefer fewer methods and parameters)
* Visibility (e.g. avoid sneaking info between objects through a global variable)
* Flexibility (objects and functions can be rearanged with relative ease)
Example: Passing primitives is looser coupling than passing complex objects
Avoid: some object/function requires knowledge of *internal* workings of another object/function.
High cohesion: Methods and data in a class are highly related and belong together
All of this (abstraction, information hiding, loose coupling, high cohesion) mainly comes down to two motivations:
Limit the amount of complexity we deal with at a time
Limit the effects when a change is made to the code
This reduces the cognitive load required to understand any given part of the system at a time.
[The CouplingVsCohesion.svg image is public domain, obtained from https://upload.wikimedia.org/wikipedia/commons/0/09/CouplingVsCohesion.svg]
Loading…
Cancel
Save