Skip to content

Commit

Permalink
Week2
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiongzj5 committed May 1, 2018
1 parent 5d4dea9 commit ec16f33
Show file tree
Hide file tree
Showing 110 changed files with 5,152 additions and 0 deletions.
1 change: 1 addition & 0 deletions Week2/Part2/.sonar/ZBug_java-module/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd"><!-- Generated by Sonar --><module name="Checker"><module name="SuppressionCommentFilter"/><module name="TreeWalker"><module name="FileContentsHolder"/> <module name="BooleanExpressionComplexity"><property name="severity" value="warning"/></module><module name="InnerAssignment"><property name="severity" value="warning"/></module><module name="UnusedImports"><property name="severity" value="info"/><property name="processJavadoc" value="false"/></module><module name="RedundantModifier"><property name="severity" value="info"/></module><module name="IllegalThrows"><property name="severity" value="warning"/></module><module name="SimplifyBooleanReturn"><property name="severity" value="warning"/></module><module name="TrailingComment"><property name="severity" value="info"/><property name="format" value="^[\s\}\);]*$"/></module><module name="RedundantThrows"><property name="severity" value="info"/><property name="suppressLoadErrors" value="true"/></module><module name="LocalFinalVariableName"><property name="severity" value="warning"/><property name="format" value="^[a-z][a-zA-Z0-9]*$"/></module><module name="StringLiteralEquality"><property name="severity" value="warning"/></module><module name="ParameterName"><property name="severity" value="warning"/><property name="format" value="^[a-z][a-zA-Z0-9]*$"/></module><module name="VisibilityModifier"><property name="severity" value="warning"/></module><module name="ParameterAssignment"><property name="severity" value="warning"/></module><module name="SimplifyBooleanExpression"><property name="severity" value="warning"/></module><module name="EqualsHashCode"><property name="severity" value="error"/></module><module name="MagicNumber"><property name="severity" value="info"/><property name="ignoreHashCodeMethod" value="false"/><property name="ignoreAnnotation" value="false"/></module><module name="DefaultComesLast"><property name="severity" value="warning"/></module><module name="FinalClass"><property name="severity" value="warning"/></module><module name="HiddenField"><property name="severity" value="warning"/><property name="tokens" value="VARIABLE_DEF"/><property name="ignoreConstructorParameter" value="true"/><property name="ignoreSetter" value="true"/><property name="ignoreAbstractMethods" value="true"/></module><module name="ModifierOrder"><property name="severity" value="info"/></module><module name="StaticVariableName"><property name="severity" value="warning"/><property name="format" value="^[a-z][a-zA-Z0-9]*$"/><property name="applyToPublic" value="true"/><property name="applyToProtected" value="true"/><property name="applyToPackage" value="true"/><property name="applyToPrivate" value="true"/></module><module name="HideUtilityClassConstructor"><property name="severity" value="warning"/></module><module name="EmptyStatement"><property name="severity" value="info"/></module><module name="AnonInnerLength"><property name="severity" value="warning"/></module></module></module>
220 changes: 220 additions & 0 deletions Week2/Part2/.sonar/ZBug_java-module/pmd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset>
<rule ref="rulesets/basic.xml/UnusedNullCheckInEquals">
<priority>3</priority>
</rule>
<rule ref="rulesets/strings.xml/StringInstantiation">
<priority>3</priority>
</rule>
<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod">
<priority>3</priority>
</rule>
<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE">
<priority>3</priority>
</rule>
<rule ref="rulesets/strictexception.xml/AvoidRethrowingException">
<priority>3</priority>
</rule>
<rule ref="rulesets/migrating.xml/ReplaceEnumerationWithIterator">
<priority>3</priority>
</rule>
<rule ref="rulesets/optimizations.xml/AvoidArrayLoops">
<priority>3</priority>
</rule>
<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter">
<priority>3</priority>
</rule>
<rule ref="rulesets/basic.xml/ClassCastExceptionWithToArray">
<priority>3</priority>
</rule>
<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException">
<priority>3</priority>
</rule>
<rule ref="rulesets/unusedcode.xml/UnusedPrivateField">
<priority>3</priority>
</rule>
<rule ref="rulesets/design.xml/CompareObjectsWithEquals">
<priority>3</priority>
</rule>
<rule ref="rulesets/strings.xml/UseIndexOfChar">
<priority>3</priority>
</rule>
<rule ref="rulesets/basic.xml/BigIntegerInstantiation">
<priority>3</priority>
</rule>
<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic">
<priority>4</priority>
</rule>
<rule ref="rulesets/naming.xml/SuspiciousEqualsMethodName">
<priority>2</priority>
</rule>
<rule ref="rulesets/design.xml/InstantiationToGetClass">
<priority>3</priority>
</rule>
<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName">
<priority>3</priority>
</rule>
<rule ref="rulesets/coupling.xml/LooseCoupling">
<priority>3</priority>
</rule>
<rule ref="rulesets/unusedcode.xml/UnusedLocalVariable">
<priority>3</priority>
</rule>
<rule ref="rulesets/strings.xml/UnnecessaryCaseChange">
<priority>4</priority>
</rule>
<rule ref="rulesets/design.xml/SingularField">
<priority>4</priority>
</rule>
<rule ref="rulesets/design.xml/CloseResource">
<priority>3</priority>
</rule>
<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable">
<priority>2</priority>
</rule>
<rule ref="rulesets/basic.xml/CollapsibleIfStatements">
<priority>4</priority>
</rule>
<rule ref="rulesets/basic.xml/UselessOperationOnImmutable">
<priority>2</priority>
</rule>
<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable">
<priority>3</priority>
</rule>
<rule ref="rulesets/basic.xml/UselessOverridingMethod">
<priority>3</priority>
</rule>
<rule ref="rulesets/controversial.xml/UnusedModifier">
<priority>5</priority>
</rule>
<rule ref="rulesets/design.xml/PreserveStackTrace">
<priority>3</priority>
</rule>
<rule ref="rulesets/optimizations.xml/UseArraysAsList">
<priority>3</priority>
</rule>
<rule ref="rulesets/design.xml/EqualsNull">
<priority>2</priority>
</rule>
<rule ref="rulesets/basic.xml/BrokenNullCheck">
<priority>2</priority>
</rule>
<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging">
<priority>3</priority>
</rule>
<rule ref="rulesets/strings.xml/InefficientStringBuffering">
<priority>3</priority>
</rule>
<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly">
<priority>2</priority>
</rule>
<rule ref="rulesets/finalizers.xml/FinalizeOverloaded">
<priority>3</priority>
</rule>
<rule ref="rulesets/controversial.xml/DontImportSun">
<priority>4</priority>
</rule>
<rule ref="rulesets/imports.xml/DontImportJavaLang">
<priority>4</priority>
</rule>
<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass">
<priority>3</priority>
</rule>
<rule ref="rulesets/strings.xml/StringBufferInstantiationWithChar">
<priority>3</priority>
</rule>
<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector">
<priority>3</priority>
</rule>
<rule ref="rulesets/strings.xml/StringToString">
<priority>3</priority>
</rule>
<rule ref="rulesets/design.xml/SimplifyConditional">
<priority>3</priority>
</rule>
<rule ref="rulesets/migrating.xml/ReplaceVectorWithList">
<priority>3</priority>
</rule>
<rule ref="rulesets/codesize.xml/NcssMethodCount">
<priority>3</priority>
<properties>
<property name="minimum" value="50" />
</properties>
</rule>
<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace">
<priority>3</priority>
</rule>
<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass">
<priority>3</priority>
</rule>
<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName">
<priority>3</priority>
</rule>
<rule ref="rulesets/codesize.xml/NcssTypeCount">
<priority>3</priority>
<properties>
<property name="minimum" value="800" />
</properties>
</rule>
<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause">
<priority>4</priority>
</rule>
<rule ref="rulesets/migrating.xml/IntegerInstantiation">
<priority>3</priority>
</rule>
<rule ref="rulesets/migrating.xml/AvoidAssertAsIdentifier">
<priority>3</priority>
</rule>
<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn">
<priority>3</priority>
</rule>
<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize">
<priority>3</priority>
</rule>
<rule ref="rulesets/basic.xml/BooleanInstantiation">
<priority>3</priority>
</rule>
<rule ref="rulesets/basic.xml/UnconditionalIfStatement">
<priority>2</priority>
</rule>
<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException">
<priority>3</priority>
</rule>
<rule ref="rulesets/migrating.xml/ReplaceHashtableWithMap">
<priority>3</priority>
</rule>
<rule ref="rulesets/basic.xml/AvoidDecimalLiteralsInBigDecimalConstructor">
<priority>3</priority>
</rule>
<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException">
<priority>3</priority>
</rule>
<rule ref="rulesets/finalizers.xml/EmptyFinalizer">
<priority>3</priority>
</rule>
<rule ref="rulesets/design.xml/IdempotentOperations">
<priority>3</priority>
</rule>
<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl">
<priority>3</priority>
</rule>
<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize">
<priority>3</priority>
</rule>
<rule ref="rulesets/strings.xml/UseStringBufferLength">
<priority>4</priority>
</rule>
<rule ref="rulesets/migrating.xml/AvoidEnumAsIdentifier">
<priority>3</priority>
</rule>
<rule ref="rulesets/logging-java.xml/SystemPrintln">
<priority>3</priority>
</rule>
<rule ref="rulesets/strings.xml/UselessStringValueOf">
<priority>4</priority>
</rule>
<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals">
<priority>3</priority>
</rule>
</ruleset>

Binary file added Week2/Part2/CircleBug/CircleBug.class
Binary file not shown.
Binary file added Week2/Part2/CircleBug/CircleBug.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions Week2/Part2/CircleBug/CircleBug.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* AP(r) Computer Science GridWorld Case Study:
* Copyright(c) 2005-2006 Cay S. Horstmann (http://horstmann.com)
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* @author Cay Horstmann
* @author Chris Nevison
* @author Barbara Cloud Wells
*/

import info.gridworld.actor.Bug;

/**
* A <code>CircleBug</code> traces out a square "box" of a given size. <br />
* The implementation of this class is testable on the AP CS A and AB exams.
*/
public class CircleBug extends Bug
{
private int steps;
private int sideLength;

/**
* Constructs a box bug that traces a square of a given side length
* @param length the side length
*/
public CircleBug(int length)
{
steps = 0;
sideLength = length;
}

/**
* Moves to the next location of the square.
*/
public void act()
{
if (steps < sideLength && canMove())
{
move();
steps++;
}
else
{
turn();
steps = 0;
}
}
}
Binary file added Week2/Part2/CircleBug/CircleBugRunner.class
Binary file not shown.
40 changes: 40 additions & 0 deletions Week2/Part2/CircleBug/CircleBugRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* AP(r) Computer Science GridWorld Case Study:
* Copyright(c) 2005-2006 Cay S. Horstmann (http://horstmann.com)
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* @author Cay Horstmann
* @author Chris Nevison
* @author Barbara Cloud Wells
*/

import info.gridworld.actor.ActorWorld;
import info.gridworld.grid.Location;

import java.awt.Color;

/**
* This class runs a world that contains box bugs. <br />
* This class is not tested on the AP CS A and AB exams.
*/
public class CircleBugRunner
{
public static void main(String[] args)
{
ActorWorld world = new ActorWorld();
CircleBug alice = new CircleBug(4);// this parameter may be sidelength
alice.setColor(Color.ORANGE);
//CircleBug bob = new CircleBug(3);
world.add(new Location(2, 4), alice);
//world.add(new Location(5, 5), bob);
world.show();
}
}
Binary file added Week2/Part2/DancingBug/DancingBug.class
Binary file not shown.
57 changes: 57 additions & 0 deletions Week2/Part2/DancingBug/DancingBug.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* AP(r) Computer Science GridWorld Case Study:
* Copyright(c) 2005-2006 Cay S. Horstmann (http://horstmann.com)
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* @author Cay Horstmann
* @author Chris Nevison
* @author Barbara Cloud Wells
*/

import info.gridworld.actor.Bug;

/**
* A <code>DancingBug</code> traces out a square "box" of a given size. <br />
* The implementation of this class is testable on the AP CS A and AB exams.
*/
public class DancingBug extends Bug
{
private int times = 0;
private int []array = new int[9];
/**
* Constructs a box bug that traces a square of a given side length
* @param length the side length
*/
public DancingBug(int[] arr)
{
for(int i=0;i<9;i++)
{
array[i] = arr[i];
}
}

/**
* Moves to the next location of the square.
*/
public void act()
{
if(times == 9)
{
times = 0;
}
for(int i=0;i < array[times]; ++i)
{
turn();
}
move();
times++;
}
}
Binary file added Week2/Part2/DancingBug/DancingBugRunner.class
Binary file not shown.
Loading

0 comments on commit ec16f33

Please sign in to comment.