id
stringlengths
36
36
text
stringlengths
1
1.25M
a3721d77-8c0b-41a1-afae-4989fc78d0c1
public String getResponse(String statement) { String response = ""; if (statement.length() == 0) { response = "Say something, please."; } else if (findKeyword(statement, "no") >= 0) { response = "Why so negative?"; } else if (findKeyword(statement, "mother") >= 0 || findKeyword(statement, "f...
d5ad5da3-3773-4ff4-b680-bd8ed2df1a9a
private String transformIWantToStatement(String statement) { // Remove the final period, if there is one statement = statement.trim(); String lastChar = statement.substring(statement .length() - 1); if (lastChar.equals(".")) { statement = statement.substring(0, statement .length() - 1); } in...
58968fc8-2e97-4316-a6e8-38e57ddeb51b
private String transformIWantStatement(String statement) { // Remove the final period, if there is one statement = statement.trim(); String lastChar = statement.substring(statement .length() - 1); if (lastChar.equals(".")) { statement = statement.substring(0, statement .length() - 1); } int ...
0d788f2c-df4d-4e1c-b6f7-6af74d81c5c9
private String transformYouMeStatement(String statement) { // Remove the final period, if there is one statement = statement.trim(); String lastChar = statement.substring(statement .length() - 1); if (lastChar.equals(".")) { statement = statement.substring(0, statement .length() - 1); } i...
7ff55013-d955-4ccc-93a8-92185df48aae
private String transformIYouStatement(String statement) { // Remove the final period, if there is one statement = statement.trim(); String lastChar = statement.substring(statement .length() - 1); if (lastChar.equals(".")) { statement = statement.substring(0, statement .length() - 1); } in...
9b753808-7eae-4edf-837c-0298ca6a37a0
private int findKeyword(String statement, String goal, int startPos) { String phrase = statement.trim(); // The only change to incorporate the startPos is in the line below int psn = phrase.toLowerCase().indexOf(goal.toLowerCase(), startPos); // Refinement--make sure the goal isn't part of a word while...
0689f45b-be81-469a-a284-1b45a03bdc84
private int findKeyword(String statement, String goal) { return findKeyword (statement, goal, 0); }
9aa54490-b521-46e2-bbf4-ee8c61ad3e4d
private String getRandomResponse () { Random r = new Random (); return randomResponses [r.nextInt(randomResponses.length)]; }
90b0299a-a26f-4f32-a343-ddc313992e89
public static void main(String[] args) { Magpie5 maggie = new Magpie5(); System.out.println (maggie.getGreeting()); Scanner in = new Scanner (System.in); String statement = in.nextLine(); while (!statement.equals("Bye")) { System.out.println (maggie.getResponse(statement)); statement = in.nextL...
8b579a2b-f0d1-4d21-a423-8db491e50d4c
@Test public void testGetStr() { StrModel sm = new StrModel("Hello"); assertTrue(sm.getStr().equals("Hello")); }
ad6c2d1e-89e8-4f13-b99f-a70575ac4825
@Test public void testSetStr() { StrModel sm = new StrModel(""); sm.setStr("Hello"); assertTrue(sm.getStr().equals("Hello")); assertTrue(sm.getRevstr().equals("olleH")); }
c963a86d-9922-4018-9b9a-cbdc2a1d8828
@Test public void testReverse() { StrModel sm = new StrModel(""); char [] arr = {'H', 'e', 'l', 'l','o'}; char [] exp = {'o', 'l', 'l', 'e', 'H'}; sm.reverse(arr); Arrays.equals(exp, arr); }
d647c007-9e4d-4eb4-8e22-dac67b564aa3
@Test public void testReverse2() { StrModel sm = new StrModel(""); String str = "Hello"; String exp = "olleH"; String res = sm.reverse(str); assertTrue(exp.equals(res)); }
a168c02c-30f2-4abd-b1c1-d7e6c2874581
public StrModel(String str) { this.str = str; this.revstr = reverse(str); }
954513d0-cdad-4f7b-b7bb-c23b23788120
public String getStr() { return str; }
5408ce5a-9d76-4371-b7ea-da4579e5cb73
public void setStr(String str) { this.str = str; this.revstr = reverse(str); }
e49d2d16-bc0e-4181-8aa7-7c92a4b66c1d
public String getRevstr() { return revstr; }
4b712d0e-c12a-4e38-9397-d28b3ac03b69
public String reverse(String str) { char [] arr = str.toCharArray(); reverse(arr); return new String(arr); }
54d830b6-b933-4c08-863c-72f383cfa587
public void reverse(char [] arr) { int len = arr.length; char temp; for (int i=0; i<len/2; ++i) { temp = arr[i]; arr[i] = arr[len-i-1]; arr[len-i-1] = temp; } }
af3cafc4-fbc8-4d6f-b167-e863a07d0963
public StrView() { super("Reverse String"); setLayout(new FlowLayout()); textFieldInput = new JTextField("", 20); add(textFieldInput); textFieldOutput = new JTextField("", 20); textFieldOutput.setEditable(false); add(textFieldOutput); ...
caa4ada8-ecef-432f-b894-450e017e86aa
public void register(StrController strController) { revButton.addActionListener(strController); clrButton.addActionListener(strController); }
9a3fa339-cec5-4bbf-818b-d71def85226d
public void update(StrModel strModel) { textFieldInput.setText(strModel.getStr()); textFieldOutput.setText(strModel.getRevstr()); }
4f7945a4-cad7-4fde-9fbc-481bb9d5b3f7
public JTextField getTextFieldInput() { return textFieldInput; }
33e55a07-5dcb-428c-9b6a-a2ae2cd3e736
public void setTextFieldInput(JTextField textFieldInput) { this.textFieldInput = textFieldInput; }
9b11ca09-d735-4227-a803-541304a71bce
public JTextField getTextFieldOutput() { return textFieldOutput; }
8fa39fae-d00a-4c84-a418-1a9d87990c71
public void setTextFieldOutput(JTextField textFieldOutput) { this.textFieldOutput = textFieldOutput; }
3c9fd8df-ef72-4cea-9c94-11153c49a586
public JButton getRevButton() { return revButton; }
3018696f-70bc-4e74-98c3-e4dd4e4784e6
public JButton getClrButton() { return clrButton; }
2ae5ee95-8708-4e69-83d7-79c5abb0e77f
public static void main(String[] args) { StrModel model = new StrModel(""); StrView view = new StrView(); StrController controller = new StrController(view, model); view.register(controller); view.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); view.setS...
2b59bebe-be3a-4cf8-8cdc-f8f2e6d2743c
public StrController(StrView strView, StrModel strModel) { this.strView = strView; this.strModel = strModel; }
e883d706-0eb5-47a2-8423-0164f0830076
@Override public void actionPerformed(ActionEvent event) { // JOptionPane.showMessageDialog(this.strView, "hehe"); if (event.getSource() == strView.getRevButton()) { strModel.setStr(strView.getTextFieldInput().getText()); strView.update(strModel); } ...
4e65136d-509d-4037-bad9-e7a4ab7f15cb
@Override public double getDiscount(double qty, double price) { double discount = 0; if (qty >= minQty) { discount = price * qty * pct; } return discount; }
b27a534f-ed02-4d52-8696-c9d34fc4e2b2
public double getPct() { return pct; }
416e5b6f-23c4-43e2-8e27-1f72b2a855ff
public void setPct(double pct) { this.pct = pct; }
b04d77e0-4820-443e-8bbf-dcb79e5d5a91
public double getMinQty() { return minQty; }
9f21ab51-d06d-4884-b1a8-09a5022b7fce
public void setMinQty(double minQty) { this.minQty = minQty; }
428f8f49-04da-4037-a81a-730fc2605454
public Customer (String name, String Id){ this.name = name; this.Id = Id; }
c729948b-1318-4c1a-9452-d3760069b77f
public String getId() { return Id; }
bda1aeb5-c1aa-4672-8595-c5ee8759e84a
public void setId(String Id) { this.Id = Id; }
01d60e42-857b-4d16-ac0c-4299aa2824f8
public String getName() { return name; }
345adc6e-e811-477e-bef9-9fcb54704c3a
public void setName(String name) { this.name = name; }
a39f2f2b-0b3a-4524-a2e0-1cfd2b534d8e
public double getPct() { return pct; }
4f01e49e-d6b8-4090-97ea-646d97edb97c
public void setPct(double pct) { this.pct = pct; }
468ab623-dc41-4489-bc84-6c3be8918af5
@Override public double getDiscount(double qty, double price) { return qty * price * pct; }
3bb317fc-c295-4c28-939c-f1dfdc4644db
public Receipt getReceipt() { return receipt; }
9cb89fff-e330-482a-8e0b-536a426bb108
public void setReceipt(Receipt receipt) { this.receipt = receipt; }
0f5ec781-3f36-432f-99d8-92773e9899f9
public void startNewSale(String customerId) { receipt = new Receipt(customerId); }
3692b910-2ac4-4ab8-8303-944fc1527908
public void purchaseProduct(String productId, double qty) { receipt.addNewLineItem(productId, qty); }
fba04867-cc48-44a2-8b91-dbf57d8ef9e3
public void finalizeAndDisplaySalesReceipt() { System.out.println(receipt.getReceiptInfo()); }
f381c813-f71a-4c58-a175-9f5f75dcb38e
public Receipt(String customerId){ lineItems = new LineItem[0]; customer = findCustomerById(customerId); }
511e3d31-4233-41d5-bd94-5c647502fa2d
private Customer findCustomerById(String id) { Customer cust = null; for(Customer c : customerArray) { if(id.equals(c.getId())) { cust = c; break; } } return cust; }
97f94afc-6eb7-4cc5-9e72-b6e056fdeb52
public void addNewLineItem(String productId, double qty) { LineItem lineItem = new LineItem(productId, qty); // add lineItem to array addItem(lineItem); // for (LineItem lineItem1 : lineItems) { // System.out.println(lineItem1); // } }
616d818e-93ba-4283-8f89-0324d89b2031
public void addItem(LineItem item) { LineItem[] temp = new LineItem[lineItems.length + 1]; System.arraycopy(lineItems, 0, temp, 0, lineItems.length); temp[temp.length-1] = item; lineItems = temp; }
3a19a7f8-9b73-42f1-9310-5d94c3f520fe
public Customer getCustomer() { return customer; }
0943fcdb-a051-4db2-a564-9bb50a2246ee
public void setCustomer(Customer customer) { this.customer = customer; }
8006282a-f7a7-4527-9c55-d768a067026d
public LineItem[] getLineItems() { return lineItems; }
6ef818a5-eccc-47c0-92f8-8719e0666e68
public void setLineItems(LineItem[] lineItems) { this.lineItems = lineItems; }
e5ba3a9f-eafb-4d57-9a3d-85d71f35c160
public String getReceiptInfo() { double grandTotalPaid = 0; double grandTotalDiscount = 0; NumberFormat nf = NumberFormat.getCurrencyInstance(); // Start receipt with customer info String info = "Cutomer ID: " + this.customer.getId() + "\n" + "Customer Name: " + c...
79173e0d-646d-43f5-a3cb-290f618f3102
public Product(){ }
e4ec1775-09a1-4cb1-b728-2beb751f9496
public Product(String id, String name, double price, DiscountStrategy discountStrategy) { this.id = id; this.name = name; this.price = price; this.discountStrategy = discountStrategy; }
e2d31a67-ccf6-4e1c-baa7-ea07ab126497
public double getDiscount(double qty) { return discountStrategy.getDiscount(qty,price); }
943da4c8-333e-4cde-b7a1-059c4bd60713
public DiscountStrategy getDiscountStrategy() { return discountStrategy; }
76e27948-1d31-4b68-9f02-2ff4234492c4
public void setDiscountStrategy(DiscountStrategy discountStrategy) { this.discountStrategy = discountStrategy; }
0888e63e-0dd9-475a-a36e-f55bb966a000
public String getId() { return id; }
80bd99d9-cb76-4537-91b0-cf7278c55d77
public void setId(String id) { this.id = id; }
abf48570-ad56-4003-91ec-bdf7623df3b0
public String getName() { return name; }
ac19cfe1-9c70-485c-bccf-f7230d3e3c31
public void setName(String name) { this.name = name; }
bd742103-8386-4986-bc79-ba0e9cb9277c
public double getPrice() { return price; }
d4706386-8c0e-490c-ba07-e8fcbf891839
public void setPrice(double price) { this.price = price; }
294bcca1-efd2-4e2f-9d49-1cfd1d0b9f19
public static void main(String[] args) { DiscountStrategy ds = new QuantityDiscount(); Product product = new Product("A100", "Pen", 10.00, ds); double actual = product.getDiscount(6); double expected = 12; if(expected == actual) { System.out.println("Test passes"); ...
20d4e769-dc3a-4f2a-97d6-ff56b13dc16d
@Override public double getDiscount(double qty, double price) { return dollarAmt; }
d27bceb8-0879-4066-a10f-36bb6ca549a9
public double getDollarAmt() { return dollarAmt; }
4413c19a-08c2-4c0e-aab1-2fb1b8d785ca
public void setDollarAmt(double dollarAmt) { this.dollarAmt = dollarAmt; }
c8b60037-99d5-4d0e-837d-e9cc721a8afc
public static void main(String[] args) { DiscountStrategy ds = new DollarDiscount(); double expectedDiscount = 5.00; double actualDiscount = ds.getDiscount(2, 10.00); if(expectedDiscount == actualDiscount) { System.out.println("Test passes"); } else { Syst...
b6fbe0f3-8239-46a1-9648-de421e6cd2e0
public abstract double getDiscount(double qty, double price);
35e58744-bd45-4227-b39a-a99054ef9ff7
public LineItem(String productId, double qty) { this.qty = qty; product = findProductById(productId); }
9cac9e85-ca79-491d-8397-0c750a6e7a0d
public String getLineItemData() { return product.getId() + " " + product.getName() + " " + qty + " " + product.getPrice() + " \t" + product.getDiscount(qty) + " \t" + getSubTotal(); // return getProductId() + " " + getName(); }
c781c525-13c0-4763-962a-87c349992e1b
public double getSubTotal() { return qty * product.getPrice() - product.getDiscount(qty); }
613ff868-6951-4503-98af-2f9c27f7e45f
public double getDiscountAmt() { return product.getDiscount(qty); }
711ad38f-47ff-4769-93dd-4f00ca5fd21b
private Product findProductById(String id) { Product prod = null; for(Product p : productDb) { if(id.equals(p.getId())) { prod = p; break; } } return prod; }
a873f05f-6ab8-49b3-947e-c503e18bb6f7
public Product getProduct() { return product; }
a0fbd7e6-44da-4c77-bcad-a15fea865b3c
public void setProduct(Product product) { this.product = product; }
89755d10-f03b-427c-ae62-89e9aeaab2a7
public double getQty() { return qty; }
0b0b87ef-1343-4cb5-a4e5-bcc296b9c6ea
public void setQty(double qty) { this.qty = qty; }
6aa7dde9-a648-4ab2-9f29-6b4fca23589c
public static void main(String[] args) { LineItem item = new LineItem("B101", 2); System.out.println(item.getLineItemData()); }
9d56d9fb-bb46-4ed0-82ae-96fa9535934e
@Override public double getDiscount(double qty, double price) { return 0; }
558f2232-e64f-499e-8217-e2df25df5b00
public static void main(String[] args) { CashRegister cr = new CashRegister(); cr.startNewSale("JG101"); cr.purchaseProduct("A101", 2); cr.purchaseProduct("B101", 9); cr.purchaseProduct("C101", 5); // cr.finalizeAndDisplaySalesReceipt(); ...
007c91cb-9161-4a09-8b67-60488e5ca511
public HawkTask(Hawk main) { this.main = main; }
4c9ace6a-83ac-41fc-aebb-3a4977afb128
public void run() { for (final String playername : Hawk.getFlyingPlayersNames()) { Player player = main.getServer().getPlayer(playername); HawkPlayerStatus status = Hawk.getPlayerStatus(player); if (player != null) { switch (status.getState()) { case FLY: doFly(player); break; case HOVER:...
b100ed67-2c22-4c5a-8761-8c5353aa5a46
private static void doFly(Player player){ Vector view = player.getLocation().getDirection(); player.setVelocity(view.multiply(HawkConfiguration.getFly_boost())); }
4b814b28-d844-464a-9c8f-b48c0547f8c4
private static void doHover(Player player){ if (player.isSneaking()) { player.setVelocity(HOVER_BOOST); } else { player.setVelocity(HOVER); } }
cc57f434-89f6-4f22-8876-4f553b67e27e
private static void performConsume(Player player, HawkPlayerStatus status){ if (HawkConfiguration.consume_item()) { int limit = 20 * (status.getState() == Flystate.FLY ? HawkConfiguration.getConsume_Seconds_Fly() : HawkConfiguration.getConsume_Seconds_Hover()); int current = status.getTime_sin...
11bdbd74-b3cd-4765-9006-6a1fb1a53d0d
public void onDisable() {}
9958eeef-95fe-4705-8ff0-766a3e1eeba1
public void onEnable() { log = getLogger(); log.setFilter(this); HawkConfiguration.loadConfiguration(this); HawkPlayerListener player_listener = new HawkPlayerListener(); HawkEntityListener entity_listener = new HawkEntityListener(); getServer().getPluginManager().registerEvents(player_listener, this);...
34a79da1-5d09-4fbe-aa9c-55dc2e87450b
public static void toLogger(String msg){ log.info(msg); }
e2c4194b-d099-4fd6-8aed-c0d339f5a80e
public boolean isLoggable(LogRecord record) { return !record.getMessage().contains("was kicked for floating too long!"); }
06256f62-a738-46ed-802f-ab5c5fdf2a56
public static void performSwitchToFly(Player player){ if (player.hasPermission("hawk.fly")) { if (HawkConfiguration.consume_item()) { if (!player.getInventory().contains(HawkConfiguration.getConsume_Item())) { return; } } flyingPlayers.put(player.getName(), new HawkPlayerStatus()); player.sen...
ba785619-66d6-4819-8aaa-27e7b76f0504
public static void performSwitchToHover(Player player, HawkPlayerStatus status){ status.setState(Flystate.HOVER); dmgImmunePlayers.remove(player.getName()); player.sendMessage(ChatColor.BLUE + PREFIX + ChatColor.WHITE + HawkConfiguration.getMessage_Hover()); }
3fa396da-5897-449e-908c-dfb80610710a
public static void performSwitchToLand(Player player){ flyingPlayers.remove(player.getName()); dmgImmunePlayers.add(player.getName()); player.sendMessage(ChatColor.BLUE + Hawk.PREFIX + ChatColor.WHITE + HawkConfiguration.getMessage_Land()); }
a3607e01-d0df-4cac-a530-fdbe1caf40af
public static boolean isFlyingOrHovering(Player player){ return flyingPlayers.containsKey(player.getName()); }