From ggc
|
001 packagepackage is used to name the directory or folder a class is in FA;
002
003
004 /**
005 * The program tests the methods of the classclass is a group of fields and methods used for making objects, Purse.
006 * @authorthis is the Javadoc tag for documenting who created the source code Frank Anderson
007 * @authorthis is the Javadoc tag for documenting who created the source code Derrick Dixon
008 */
009 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects PurseTest
010 {open braces start code blocks and must be matched with a close brace
011
012 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) voidvoid means the method does not return a value mainThe main method is the place where applications begin executing.(String[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays args)
013 {open braces start code blocks and must be matched with a close brace
014 /** model through model6 are purses that contain coins forfor is a looping structure for repeatedly executing a block of code testing the Purse classclass is a group of fields and methods used for making objects. */
015 Purse model =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Purse();
016 Purse model2 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Purse();
017 Purse model3 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Purse();
018 Purse model4 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Purse();
019 Purse model5 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Purse();
020 Purse model6 =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor Purse();
021
022 /** Create the original purse */
023 model.addCoin("quarter");
024 model.addCoin("nickel");
025 model.addCoin("dime");
026 model.addCoin("penny");
027
028 /** model6 is the same as the original model. */
029 model6.addCoin("quarter");
030 model6.addCoin("nickel");
031 model6.addCoin("dime");
032 model6.addCoin("penny");
033
034 /** purse2 to be added to original purse */
035 model2.addCoin("nickel");
036 model2.addCoin("dime");
037 model2.addCoin("penny");
038
039 /** purse3 is the same as the orignial purse; same contents, same order. */
040 model3.addCoin("quarter");
041 model3.addCoin("nickel");
042 model3.addCoin("dime");
043 model3.addCoin("penny");
044
045 /** purse4 has the same contents as the original but in a different order. */
046 model4.addCoin("quarter");
047 model4.addCoin("nickel");
048 model4.addCoin("penny");
049 model4.addCoin("dime");
050
051 /** purse5 has one more element than the original purse. */
052 model5.addCoin("quarter");
053 model5.addCoin("nickel");
054 model5.addCoin("dime");
055 model5.addCoin("penny");
056 model5.addCoin("penny");
057
058 /** Print the coins in the oringal order of entry. */
059 System.out.println("The original purse is: ");
060 System.out.println(model);
061 System.out.println();
062
063 /** Testing .reverse(). Print the coins in the reverse order of entry. */
064 System.out.println("The original list in reverse order:");
065 System.out.println(model.reverse());
066 System.out.println();
067
068 /** Testing .transfer(). Transfer the coins in purse2 to the original purse
069 * and empty the contents of purse2 */
070 System.out.println("Transfer the contents of " +adds two numbers together or concatenates Strings togethermodel2.toString());
071 System.out.println(" to "+adds two numbers together or concatenates Strings togethermodel.toString());
072 model.transfer(model2);
073 System.out.println(model.toString());
074 System.out.println("The contens of model2 should now be empty. Model2=");
075 System.out.println(model2.toString());
076 System.out.println();
077
078 /** Testing .sameContents(). Check to see ifif executes the next statement only if the condition in parenthesis evaluates to true the contents are the same.
079 * model and model6 are the same.*/
080 System.out.println("The contents of model3 and the original model6 should be the same.");
081 System.out.println(" model3 = "+adds two numbers together or concatenates Strings togethermodel3.toString());
082 System.out.println(" model6 = "+adds two numbers together or concatenates Strings togethermodel6.toString());
083 System.out.println(model3.sameContents(model6));
084 System.out.println("Expected result above: true");
085 System.out.println();
086
087 /** Testing .sameContents().Check to see ifif executes the next statement only if the condition in parenthesis evaluates to true the contents are the same.
088 * model and model4 are the same. */
089 System.out.println("The contents of model4 and the original model should NOT be the same.");
090 System.out.println("original purse = "+adds two numbers together or concatenates Strings togethermodel.toString());
091 System.out.println(" purse 4 = "+adds two numbers together or concatenates Strings togethermodel4.toString());
092 System.out.println(model6.sameContents(model4));
093 System.out.println("Expected result above: false");
094 System.out.println();
095
096 /** Testing .sameCoins(). Check to see ifif executes the next statement only if the condition in parenthesis evaluates to true the coin counts are the same.
097 * model3 and model4 have different order.*/
098 System.out.println("Check to see if the coins in the purse are the same.");
099 System.out.println(model3.toString()+adds two numbers together or concatenates Strings together" has the same coins as");
100 System.out.println(model4.toString());
101 System.out.println(model3.sameCoins(model4));
102 System.out.println("Expected result above: true");
103 System.out.println();
104
105 /** Testing .sameCoins(). Check to see ifif executes the next statement only if the condition in parenthesis evaluates to true the two purses have the same contents,
106 * regardless of order.*/
107 System.out.println("Check to see if the coins in the purse are the same.");
108 System.out.println("original purse: "+adds two numbers together or concatenates Strings togethermodel6.toString());
109 System.out.println(" purse5 :" +adds two numbers together or concatenates Strings together model5.toString());
110 System.out.println(model6.sameCoins(model5));
111 System.out.println("Expected results above: false.");
112
113 }close braces end code blocks and must match an earlier open brace
114 }close braces end code blocks and must match an earlier open brace
|
Download/View FA/PurseTest.java