diff --git a/.gitignore b/.gitignore index fa9bcb8820..a4f6f3d915 100644 --- a/.gitignore +++ b/.gitignore @@ -291,7 +291,6 @@ students/406400373/* students/549739951/* students/582161208/* students/592146505/* -students/740707954/* students/844620174/* students/87049319/* students/183549495/* diff --git a/students/1158154002/src/main/java/com/coderising/dp/builder/TagBuilder.java b/students/1158154002/src/main/java/com/coderising/dp/builder/TagBuilder.java new file mode 100644 index 0000000000..baefede533 --- /dev/null +++ b/students/1158154002/src/main/java/com/coderising/dp/builder/TagBuilder.java @@ -0,0 +1,43 @@ +package com.coderising.dp.builder; + +import java.util.List; + +public class TagBuilder { + private TagNode root; + private TagNode now; + private TagNode prev; + public TagBuilder(String rootTagName) { + root=new TagNode(rootTagName); + now=root; + } + + public TagBuilder addChild(String childTagName) { + prev=now; + now=new TagNode(childTagName); + prev.add(now); + + return this; + } + + public TagBuilder addSibling(String siblingTagName) { + List children=prev.getChildren(); + now=new TagNode(siblingTagName); + children.add(now); + return this; + + } + + public TagBuilder setAttribute(String name, String value) { + now.setAttribute(name, value); + return this; + } + + public TagBuilder setText(String value) { + + return this; + } + + public String toXML() { + return root.toXML(); + } +} diff --git a/students/1158154002/src/main/java/com/coderising/dp/builder/TagBuilderTest.java b/students/1158154002/src/main/java/com/coderising/dp/builder/TagBuilderTest.java new file mode 100644 index 0000000000..147e159b23 --- /dev/null +++ b/students/1158154002/src/main/java/com/coderising/dp/builder/TagBuilderTest.java @@ -0,0 +1,45 @@ +package com.coderising.dp.builder; + +import static org.junit.Assert.assertEquals; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class TagBuilderTest { + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testToXML() { + + TagBuilder builder = new TagBuilder("order"); + + String xml = builder.addChild("line-items") + .addChild("line-item").setAttribute("pid", "P3677").setAttribute("qty", "3") + .addSibling("line-item").setAttribute("pid", "P9877").setAttribute("qty", "10") + .toXML(); + + String expected = "" + + "" + + "" + + "" + + "" + + ""; + + System.out.println(xml); + assertEquals(expected, xml); + +// com.oracle.nio.BufferSecrets +// +// com.sun.corba.se.spi.extension.ServantCachingPolicy +// +// java.net.ProxySelector + } + +} diff --git a/students/1158154002/src/main/java/com/coderising/dp/builder/TagNode.java b/students/1158154002/src/main/java/com/coderising/dp/builder/TagNode.java new file mode 100644 index 0000000000..33b421cf10 --- /dev/null +++ b/students/1158154002/src/main/java/com/coderising/dp/builder/TagNode.java @@ -0,0 +1,83 @@ +package com.coderising.dp.builder; + +import java.util.ArrayList; +import java.util.List; + +public class TagNode { + private String tagName; + private String tagValue; + private List children = new ArrayList<>(); + private List attributes = new ArrayList<>(); + + public TagNode(String name){ + this.tagName = name; + } + public void add(TagNode child){ + this.children.add(child); + } + public void setAttribute(String name, String value) { + Attribute attr = findAttribute(name); + if(attr != null){ + attr.value = value; + return; + } + + attributes.add(new Attribute(name,value)); + } + private Attribute findAttribute(String name){ + for(Attribute attr : attributes){ + if(attr.name.equals(name)){ + return attr; + } + } + return null; + } + public void setValue(String value) { + this.tagValue = value; + + } + public String getTagName() { + return tagName; + } + public List getChildren() { + return children; + } + + private static class Attribute{ + public Attribute(String name, String value) { + this.name = name; + this.value = value; + } + String name; + String value; + + } + public String toXML(){ + return toXML(this); + } + private String toXML(TagNode node){ + StringBuilder buffer = new StringBuilder(); + buffer.append("<").append(node.tagName); + if(node.attributes.size()> 0){ + for(int i=0;i"); + return buffer.toString(); + } + buffer.append(">"); + for(TagNode childNode : node.children){ + buffer.append(toXML(childNode)); + } + buffer.append(""); + + + return buffer.toString(); + } + private String toXML(Attribute attr){ + return attr.name+"=\""+attr.value + "\""; + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderings/dp/builder/TagBuilder.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderings/dp/builder/TagBuilder.java new file mode 100644 index 0000000000..becc6a3d37 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderings/dp/builder/TagBuilder.java @@ -0,0 +1,49 @@ +package com.coderings.dp.builder; + +public class TagBuilder { + + final TagNode rootNode; + + TagNode iteratorNode; + + TagNode prevIteratorNode; + + public TagBuilder(String rootTagName) { + rootNode = new TagNode(rootTagName); + iteratorNode = rootNode; + prevIteratorNode = rootNode; + } + + public TagBuilder addChild(String childTagName) { + TagNode tagNode = new TagNode(childTagName); + iteratorNode.add(tagNode); + + prevIteratorNode = iteratorNode; + iteratorNode = tagNode; + + return this; + } + + public TagBuilder addSibling(String siblingTagName) { + TagNode tagNode = new TagNode(siblingTagName); + prevIteratorNode.add(tagNode); + + iteratorNode = tagNode; + + return this; + } + + public TagBuilder setAttribute(String name, String value) { + iteratorNode.setAttribute(name, value); + return this; + } + + public TagBuilder setText(String value) { + iteratorNode.setValue(value); + return this; + } + + public String toXML() { + return rootNode.toXML(); + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderings/dp/builder/TagBuilderTest.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderings/dp/builder/TagBuilderTest.java new file mode 100644 index 0000000000..2d6dae918b --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderings/dp/builder/TagBuilderTest.java @@ -0,0 +1,40 @@ +package com.coderings.dp.builder; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class TagBuilderTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testToXML() { + + TagBuilder builder = new TagBuilder("order"); + + String xml = builder.addChild("line-items") + .addChild("line-item").setAttribute("pid", "P3677").setAttribute("qty", "3") + .addSibling("line-item").setAttribute("pid", "P9877").setAttribute("qty", "10") + .toXML(); + + String expected = "" + + "" + + "" + + "" + + "" + + ""; + + System.out.println(xml); + assertEquals(expected, xml); + } + +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderings/dp/builder/TagNode.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderings/dp/builder/TagNode.java new file mode 100644 index 0000000000..28fb0f54b8 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderings/dp/builder/TagNode.java @@ -0,0 +1,83 @@ +package com.coderings.dp.builder; + +import java.util.ArrayList; +import java.util.List; + +public class TagNode { + private String tagName; + private String tagValue; + private List children = new ArrayList<>(); + private List attributes = new ArrayList<>(); + + public TagNode(String name){ + this.tagName = name; + } + public void add(TagNode child){ + this.children.add(child); + } + public void setAttribute(String name, String value) { + Attribute attr = findAttribute(name); + if(attr != null){ + attr.value = value; + return; + } + + attributes.add(new Attribute(name,value)); + } + private Attribute findAttribute(String name){ + for(Attribute attr : attributes){ + if(attr.name.equals(name)){ + return attr; + } + } + return null; + } + public void setValue(String value) { + this.tagValue = value; + + } + public String getTagName() { + return tagName; + } + public List getChildren() { + return children; + } + + private static class Attribute{ + public Attribute(String name, String value) { + this.name = name; + this.value = value; + } + String name; + String value; + + } + public String toXML(){ + return toXML(this); + } + private String toXML(TagNode node){ + StringBuilder buffer = new StringBuilder(); + buffer.append("<").append(node.tagName); + if(node.attributes.size()> 0){ + for(int i=0;i"); + return buffer.toString(); + } + buffer.append(">"); + for(TagNode childNode : node.children){ + buffer.append(toXML(childNode)); + } + buffer.append(""); + + + return buffer.toString(); + } + private String toXML(Attribute attr){ + return attr.name+"=\""+attr.value + "\""; + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderings/dp/singleton/jdk_singleton.md b/students/2816977791/ood/ood-assignment/src/main/java/com/coderings/dp/singleton/jdk_singleton.md new file mode 100644 index 0000000000..69df72e73d --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderings/dp/singleton/jdk_singleton.md @@ -0,0 +1,38 @@ +#Singleton in JDK + +## java.lang.Runtime + + private static Runtime currentRuntime = new Runtime(); + + public static Runtime getRuntime() { + return currentRuntime; + } + +## java.awt.Desktop + + private DesktopPeer peer; + + private Desktop() { + peer = Toolkit.getDefaultToolkit().createDesktopPeer(this); + } + + + public static synchronized Desktop getDesktop(){ + Desktop desktop = (Desktop)context.get(Desktop.class); + + if (desktop == null) { + desktop = new Desktop(); + context.put(Desktop.class, desktop); + } + + return desktop; + } + +## java.lang.System + + private static volatile SecurityManager security = null; + + public static SecurityManager getSecurityManager() { + return security; + } + \ No newline at end of file diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/Atm.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/Atm.java new file mode 100644 index 0000000000..9728b39bfb --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/Atm.java @@ -0,0 +1,166 @@ +package com.coderising.ood.atmSimulation.atm; + +import com.coderising.ood.atmSimulation.atm.console.SuperKeypad; +import com.coderising.ood.atmSimulation.atm.print.Printer; +import com.coderising.ood.atmSimulation.atm.proxy.BankProxy; +import com.coderising.ood.atmSimulation.atm.reader.CardReader; +import com.coderising.ood.atmSimulation.atm.slot.CashDepensier; +import com.coderising.ood.atmSimulation.atm.slot.DepositSlot; +import com.coderising.ood.atmSimulation.atm.transaction.*; +import com.coderising.ood.atmSimulation.card.Card; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class Atm { + //存钱口 + private DepositSlot depositSlot; + //取钱口 + private CashDepensier cashDepensier; + //超级键盘 + private SuperKeypad superKeypad; + //读卡器 + private CardReader cardReader; + //bankProxy + private BankProxy bankProxy; + //打印器 + private Printer printer; + + public Atm(DepositSlot depositSlot, CashDepensier cashDepensier, + SuperKeypad superKeypad, CardReader cardReader, BankProxy bankProxy, Printer printer) { + this.depositSlot = depositSlot; + this.cashDepensier = cashDepensier; + this.superKeypad = superKeypad; + this.cardReader = cardReader; + this.bankProxy = bankProxy; + this.printer = printer; + } + + //账号|密码 + private String account; + private String password; + + private List list = new ArrayList<>(); + + public String getAccount() { + return account; + } + + public String getPassword() { + return password; + } + + public boolean hasEnoughMoney(int amount) { + return cashDepensier.hasEnoughMoney(amount); + } + + public boolean dipenseMoney(int amount) { + return cashDepensier.dispenseMoney(amount); + } + + public int retriveMoney() { + Random random = new Random(); + int money = random.nextInt(10000); + return depositSlot.retriveMoney(money); + } + + //插卡 + public void insertCard(Card card) { + account = cardReader.readCard(card); + } + + //输入密码 + public void writePassword() { + int count = 1; + while (count <= 3) { + count++; + password = superKeypad.inputPassword(); + if (bankProxy.verify(account, password)) { + return; + } + } + superKeypad.display("吞卡啦,到前台吧~"); + throw new RuntimeException("atm eat card"); + } + + //查询 + public void query() { + superKeypad.display("查询"); + QueryBalanceTx tx = new QueryBalanceTx(); + if (tx.preProcess(this)) { + String response = bankProxy.process(tx, this); + tx.setAmount(Integer.valueOf(response)); + superKeypad.display("查询操作余额为:" + response); + } + list.add(tx); + tx.postProcess(this); + } + + //转账 + public void transfer() { + superKeypad.display("转账"); + String toCard = superKeypad.inputCardNumber(); + int amount = superKeypad.inputAmount(); + TransferTx tx = new TransferTx(toCard, amount); + if (tx.preProcess(this)) { + String response = bankProxy.process(tx, this); + superKeypad.display("转账后,余额为:" + response); + } + list.add(tx); + tx.postProcess(this); + } + + //取款 + public void dependesier() { + superKeypad.display("取款"); + int amount = superKeypad.inputAmount(); + WithdrawTx tx = new WithdrawTx(amount); + if (tx.preProcess(this)) { + String response = bankProxy.process(tx, this); + superKeypad.display("取款后,余额为:" + response); + } + list.add(tx); + tx.postProcess(this); + } + + //存钱 + public void deposit() { + superKeypad.display("存款"); + DepositTx tx = new DepositTx(retriveMoney()); + if (tx.preProcess(this)) { + String response = bankProxy.process(tx, this); + superKeypad.display("存钱后,余额为:" + response); + } + list.add(tx); + tx.postProcess(this); + } + + //打印 + public void print() { + superKeypad.display("------打印操作-------"); + printer.print(list); + superKeypad.display("------打印完毕-------"); + } + + //退卡 + public void ejectCard(Card card) { + cardReader.ejectCard(card); + superKeypad.display("退卡成功"); + } + + //引导 + public void showGuide() { + superKeypad.display("请选择操作:"); + superKeypad.display("1:查询"); + superKeypad.display("2:存钱"); + superKeypad.display("3:取款"); + superKeypad.display("4:转账"); + superKeypad.display("5:退卡"); + } + +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/Main.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/Main.java new file mode 100644 index 0000000000..caf9ef2869 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/Main.java @@ -0,0 +1,97 @@ +package com.coderising.ood.atmSimulation.atm; + +import com.coderising.ood.atmSimulation.atm.console.Display; +import com.coderising.ood.atmSimulation.atm.console.KeyBoard; +import com.coderising.ood.atmSimulation.atm.console.SuperKeypad; +import com.coderising.ood.atmSimulation.atm.print.Printer; +import com.coderising.ood.atmSimulation.atm.proxy.BankProxy; +import com.coderising.ood.atmSimulation.atm.proxy.Network; +import com.coderising.ood.atmSimulation.atm.reader.CardReader; +import com.coderising.ood.atmSimulation.atm.slot.CashDepensier; +import com.coderising.ood.atmSimulation.atm.slot.DepositSlot; +import com.coderising.ood.atmSimulation.atm.slot.MoneySlot; +import com.coderising.ood.atmSimulation.bank.Bank; +import com.coderising.ood.atmSimulation.bank.account.Account; +import com.coderising.ood.atmSimulation.bank.proxy.ATMProxy; +import com.coderising.ood.atmSimulation.card.Card; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** + * @author nvarchar + * date 2017/7/16 + */ +public class Main { + + public static void main(String[] args) { + //mock bank + List accounts = new ArrayList<>(); + Account account = new Account("55005500", "123456", 10000); + accounts.add(account); + Bank bank = new Bank(accounts); + + //mock atmproxy + ATMProxy atmproxy = new ATMProxy(bank); + + //mock network + Network network = new Network(atmproxy); + + //mock bankProxy + BankProxy bankProxy = new BankProxy(network); + + //mock atm + DepositSlot depositSlot = new DepositSlot(); + CashDepensier cashDepensier = new CashDepensier(); + + Display display = new Display(); + KeyBoard keyBoard = new KeyBoard(); + SuperKeypad superKeypad = new SuperKeypad(display, keyBoard); + CardReader cardReader = new CardReader(); + Printer printer = new Printer(); + Atm atm = new Atm(depositSlot, cashDepensier, superKeypad, cardReader, bankProxy, printer); + + MoneySlot.setMoney(1000000); + + //mock card + Card card = new Card("55005500"); + + + atm.insertCard(card); + atm.writePassword(); + + atm.showGuide(); + + Scanner sca = new Scanner(System.in); + + boolean exit = false; + while (!exit) { + int ch = sca.nextInt(); + switch (ch) { + case 1: + atm.query(); + break; + case 2: + atm.deposit(); + break; + case 3: + atm.dependesier(); + break; + case 4: + atm.transfer(); + break; + case 5: + atm.ejectCard(card); + exit = true; + break; + default: + exit = true; + break; + } + } + + atm.print(); + + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/console/Display.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/console/Display.java new file mode 100644 index 0000000000..bae9135b4f --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/console/Display.java @@ -0,0 +1,13 @@ +package com.coderising.ood.atmSimulation.atm.console; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class Display { + + public void showMessage(String message) { + System.out.println(message); + } + +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/console/KeyBoard.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/console/KeyBoard.java new file mode 100644 index 0000000000..8cbfa6fd71 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/console/KeyBoard.java @@ -0,0 +1,26 @@ +package com.coderising.ood.atmSimulation.atm.console; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class KeyBoard { + + public String input() { + + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + String input = ""; + + try { + input = in.readLine(); + } catch (IOException ioe) { + ioe.printStackTrace(); + } + return input; + } + +} \ No newline at end of file diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/console/SuperKeypad.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/console/SuperKeypad.java new file mode 100644 index 0000000000..97256872da --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/console/SuperKeypad.java @@ -0,0 +1,45 @@ +package com.coderising.ood.atmSimulation.atm.console; + +import com.coderising.ood.atmSimulation.atm.transaction.Trasaction; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class SuperKeypad { + private Display display; + private KeyBoard keyBoard; + + public SuperKeypad() { + } + + public SuperKeypad(Display display, KeyBoard keyBoard) { + this.display = display; + this.keyBoard = keyBoard; + } + + public void display(String message) { + display.showMessage(message); + } + + public String inputPassword() { + display("input your password: "); + String password = keyBoard.input(); + display(password.replaceAll("(?s).", "*")); + return password; + } + + public String inputCardNumber() { + display("input your transfer card number"); + return keyBoard.input(); + } + + public int inputAmount() { + display("input your amount"); + return Integer.valueOf(keyBoard.input()); + } + + public Trasaction getTrasaction() { + return null; + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/print/Printer.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/print/Printer.java new file mode 100644 index 0000000000..41d492cc77 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/print/Printer.java @@ -0,0 +1,17 @@ +package com.coderising.ood.atmSimulation.atm.print; + +import com.coderising.ood.atmSimulation.atm.transaction.Trasaction; + +import java.util.List; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class Printer { + public void print(List list) { + for (Trasaction trasaction : list) { + System.out.println(trasaction.toPrint()); + } + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/proxy/BankProxy.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/proxy/BankProxy.java new file mode 100644 index 0000000000..4f227e8959 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/proxy/BankProxy.java @@ -0,0 +1,29 @@ +package com.coderising.ood.atmSimulation.atm.proxy; + +import com.coderising.ood.atmSimulation.atm.Atm; +import com.coderising.ood.atmSimulation.atm.transaction.Trasaction; +import com.coderising.ood.atmSimulation.serialization.JsonConvert; +import com.coderising.ood.atmSimulation.serialization.NetPackage; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class BankProxy { + private Network network; + + public BankProxy(Network network) { + this.network = network; + } + + public String process(Trasaction tx, Atm atm) { + String response = network.sendData(tx.toNetWorkPackage(atm)); + return response; + } + + public boolean verify(String account, String password) { + NetPackage netPackage = new NetPackage(account, password); + String response = network.sendData(JsonConvert.encode(netPackage)); + return "true".equals(response); + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/proxy/Network.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/proxy/Network.java new file mode 100644 index 0000000000..a16917db06 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/proxy/Network.java @@ -0,0 +1,20 @@ +package com.coderising.ood.atmSimulation.atm.proxy; + +import com.coderising.ood.atmSimulation.bank.proxy.ATMProxy; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class Network { + + private ATMProxy atmProxy; + + public Network(ATMProxy atmProxy) { + this.atmProxy = atmProxy; + } + + public String sendData(String data) { + return atmProxy.getData(data); + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/reader/CardReader.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/reader/CardReader.java new file mode 100644 index 0000000000..a347337548 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/reader/CardReader.java @@ -0,0 +1,18 @@ +package com.coderising.ood.atmSimulation.atm.reader; + +import com.coderising.ood.atmSimulation.card.Card; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class CardReader { + + public String readCard(Card card) { + return card.getAccount(); + } + + public void ejectCard(Card card){ + System.out.println("退卡"); + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/slot/CashDepensier.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/slot/CashDepensier.java new file mode 100644 index 0000000000..256d4bb911 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/slot/CashDepensier.java @@ -0,0 +1,16 @@ +package com.coderising.ood.atmSimulation.atm.slot; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class CashDepensier { + public boolean hasEnoughMoney(int amount) { + return MoneySlot.getMoney() - amount >= 0; + } + + public boolean dispenseMoney(int amount) { + MoneySlot.minusMoney(amount); + return true; + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/slot/DepositSlot.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/slot/DepositSlot.java new file mode 100644 index 0000000000..2841e9f505 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/slot/DepositSlot.java @@ -0,0 +1,12 @@ +package com.coderising.ood.atmSimulation.atm.slot; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class DepositSlot { + public int retriveMoney(int amount) { + //mock put money + return amount; + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/slot/MoneySlot.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/slot/MoneySlot.java new file mode 100644 index 0000000000..171f9be15a --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/slot/MoneySlot.java @@ -0,0 +1,28 @@ +package com.coderising.ood.atmSimulation.atm.slot; + +/** + * manage atm money + * + * @author nvarchar + * date 2017/7/15 + */ +public class MoneySlot { + + private static long money; + + public static long getMoney() { + return money; + } + + public static void setMoney(long amount) { + MoneySlot.money = amount; + } + + public static void addMoney(long amount) { + money += amount; + } + + public static void minusMoney(long amount) { + money -= amount; + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/transaction/DepositTx.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/transaction/DepositTx.java new file mode 100644 index 0000000000..770fe603ea --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/transaction/DepositTx.java @@ -0,0 +1,43 @@ +package com.coderising.ood.atmSimulation.atm.transaction; + +import com.coderising.ood.atmSimulation.atm.Atm; +import com.coderising.ood.atmSimulation.serialization.JsonConvert; +import com.coderising.ood.atmSimulation.serialization.NetPackage; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class DepositTx implements Trasaction { + + private int amount; + + public int getAmount() { + return amount; + } + + public DepositTx(int amount) { + this.amount = amount; + } + + @Override + public String toPrint() { + return "存款" + amount; + } + + @Override + public String toNetWorkPackage(Atm atm) { + NetPackage nt = new NetPackage(NetPackage.Type.DEPOSIT, atm, amount, null); + return JsonConvert.encode(nt); + } + + @Override + public boolean preProcess(Atm atm) { + return true; + } + + @Override + public boolean postProcess(Atm atm) { + return false; + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/transaction/QueryBalanceTx.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/transaction/QueryBalanceTx.java new file mode 100644 index 0000000000..f0b8a54fb7 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/transaction/QueryBalanceTx.java @@ -0,0 +1,42 @@ +package com.coderising.ood.atmSimulation.atm.transaction; + +import com.coderising.ood.atmSimulation.atm.Atm; +import com.coderising.ood.atmSimulation.serialization.JsonConvert; +import com.coderising.ood.atmSimulation.serialization.NetPackage; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class QueryBalanceTx implements Trasaction { + + private int amount; + + public QueryBalanceTx() { + } + + public void setAmount(int amount) { + this.amount = amount; + } + + @Override + public String toPrint() { + return "查询账户,余额为:" + amount; + } + + @Override + public String toNetWorkPackage(Atm atm) { + NetPackage nt = new NetPackage(NetPackage.Type.QUERY, atm, null, null); + return JsonConvert.encode(nt); + } + + @Override + public boolean preProcess(Atm atm) { + return true; + } + + @Override + public boolean postProcess(Atm atm) { + return true; + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/transaction/TransferTx.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/transaction/TransferTx.java new file mode 100644 index 0000000000..c3cb593ccd --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/transaction/TransferTx.java @@ -0,0 +1,44 @@ +package com.coderising.ood.atmSimulation.atm.transaction; + +import com.coderising.ood.atmSimulation.atm.Atm; +import com.coderising.ood.atmSimulation.serialization.JsonConvert; +import com.coderising.ood.atmSimulation.serialization.NetPackage; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class TransferTx implements Trasaction { + private String toCard; + private int amount; + + public TransferTx(String toCard, int amount) { + this.toCard = toCard; + this.amount = amount; + } + + public int getAmount() { + return amount; + } + + @Override + public String toPrint() { + return "转账" + amount + "元到" + toCard; + } + + @Override + public String toNetWorkPackage(Atm atm) { + NetPackage nt = new NetPackage(NetPackage.Type.TRANSFER, atm, amount, toCard); + return JsonConvert.encode(nt); + } + + @Override + public boolean preProcess(Atm atm) { + return atm.hasEnoughMoney(getAmount()); + } + + @Override + public boolean postProcess(Atm atm) { + return true; + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/transaction/Trasaction.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/transaction/Trasaction.java new file mode 100644 index 0000000000..c3c58978ce --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/transaction/Trasaction.java @@ -0,0 +1,17 @@ +package com.coderising.ood.atmSimulation.atm.transaction; + +import com.coderising.ood.atmSimulation.atm.Atm; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public interface Trasaction { + public String toNetWorkPackage(Atm atm); + + public boolean preProcess(Atm atm); + + public boolean postProcess(Atm atm); + + public String toPrint(); +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/transaction/WithdrawTx.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/transaction/WithdrawTx.java new file mode 100644 index 0000000000..c783326e02 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/atm/transaction/WithdrawTx.java @@ -0,0 +1,42 @@ +package com.coderising.ood.atmSimulation.atm.transaction; + +import com.coderising.ood.atmSimulation.atm.Atm; +import com.coderising.ood.atmSimulation.serialization.JsonConvert; +import com.coderising.ood.atmSimulation.serialization.NetPackage; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class WithdrawTx implements Trasaction { + private int amount; + + public WithdrawTx(int amount) { + this.amount = amount; + } + + public int getAmount() { + return amount; + } + + @Override + public String toPrint() { + return "取款" + amount; + } + + @Override + public String toNetWorkPackage(Atm atm) { + NetPackage nt = new NetPackage(NetPackage.Type.WITHDRAW, atm, amount, null); + return JsonConvert.encode(nt); + } + + @Override + public boolean preProcess(Atm atm) { + return atm.hasEnoughMoney(getAmount()); + } + + @Override + public boolean postProcess(Atm atm) { + return atm.dipenseMoney(getAmount()); + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/Bank.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/Bank.java new file mode 100644 index 0000000000..02550318bb --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/Bank.java @@ -0,0 +1,97 @@ +package com.coderising.ood.atmSimulation.bank; + +import com.coderising.ood.atmSimulation.bank.account.Account; +import com.coderising.ood.atmSimulation.bank.transaction.DepositTx; +import com.coderising.ood.atmSimulation.bank.transaction.QueryBalanceTx; +import com.coderising.ood.atmSimulation.bank.transaction.TransferTx; +import com.coderising.ood.atmSimulation.bank.transaction.WithdrawTx; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class Bank { + private List accounts = new ArrayList<>(); + + public Bank(List accounts) { + this.accounts = accounts; + } + + //查询 + public String query(String cardNumber, String password) { + QueryBalanceTx tx = new QueryBalanceTx(cardNumber, password); + if (tx.preProcess(this)) { + return tx.process(this); + } + tx.postProcess(this); + return null; + } + + //转账 + public String transfer(String cardNumber, String password, + String toCard, int amount) { + TransferTx tx = new TransferTx(cardNumber, password, + toCard, amount); + + if (tx.preProcess(this)) { + return tx.process(this); + } + tx.postProcess(this); + return null; + } + + //取款 + public String withDraw(String cardNumber, String password, + int amount) { + WithdrawTx tx = new WithdrawTx(cardNumber, password, amount); + + if (tx.preProcess(this)) { + return tx.process(this); + } + tx.postProcess(this); + return null; + } + + //存钱 + public String deposit(String cardNumber, String password, + int amount) { + DepositTx tx = new DepositTx(cardNumber, password, amount); + + if (tx.preProcess(this)) { + return tx.process(this); + } + tx.postProcess(this); + return null; + } + + //验证 + public boolean verify(String account, String password) { + return isExist(account, password); + } + + //查询是否 + private boolean isExist(String cardNumber, String password) { + for (Account account : accounts) { + if (cardNumber.equals(account.getCardNumber()) + && password.equals(account.getPassword())) { + return true; + } + } + return false; + } + + //获取账户 + public Account getAccount(String cardNumber, String password) { + for (Account account : accounts) { + if (cardNumber.equals(account.getCardNumber()) + && password.equals(account.getPassword())) { + return account; + } + } + return null; + } + +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/account/Account.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/account/Account.java new file mode 100644 index 0000000000..3bbf50f600 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/account/Account.java @@ -0,0 +1,49 @@ +package com.coderising.ood.atmSimulation.bank.account; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class Account { + private String cardNumber; + private int money; + private String password; + + public Account() { + } + + public Account(String cardNumber, String password, int money) { + this.cardNumber = cardNumber; + this.money = money; + this.password = password; + } + + public String getCardNumber() { + return cardNumber; + } + + public int getMoney() { + return money; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public boolean hasEnoughMoney(int amount) { + return money >= amount; + } + + public boolean dipenseMoney(int amount) { + money -= amount; + return true; + } + + public void retriveMoney(int amount) { + money += amount; + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/proxy/ATMProxy.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/proxy/ATMProxy.java new file mode 100644 index 0000000000..a4083ff454 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/proxy/ATMProxy.java @@ -0,0 +1,34 @@ +package com.coderising.ood.atmSimulation.bank.proxy; + +import com.coderising.ood.atmSimulation.bank.Bank; +import com.coderising.ood.atmSimulation.serialization.JsonConvert; +import com.coderising.ood.atmSimulation.serialization.NetPackage; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class ATMProxy { + private Bank bank; + + public ATMProxy(Bank bank) { + this.bank = bank; + } + + public String getData(String data) { + NetPackage np = JsonConvert.decode(data); + switch (np.getType()) { + case QUERY: + return bank.query(np.getAccount(), np.getPassword()); + case Verify: + return String.valueOf(bank.verify(np.getAccount(), np.getPassword())); + case DEPOSIT: + return bank.deposit(np.getAccount(), np.getPassword(), np.getAmount()); + case TRANSFER: + return bank.transfer(np.getAccount(), np.getPassword(), np.getToCard(), np.getAmount()); + case WITHDRAW: + return bank.withDraw(np.getAccount(), np.getPassword(), np.getAmount()); + } + return "no such method"; + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/transaction/DepositTx.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/transaction/DepositTx.java new file mode 100644 index 0000000000..636df1e60d --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/transaction/DepositTx.java @@ -0,0 +1,38 @@ +package com.coderising.ood.atmSimulation.bank.transaction; + +import com.coderising.ood.atmSimulation.bank.Bank; +import com.coderising.ood.atmSimulation.bank.account.Account; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class DepositTx implements Trasaction { + + private String account; + private String password; + private int amount; + + public DepositTx(String account, String password, int amount) { + this.account = account; + this.password = password; + this.amount = amount; + } + + @Override + public boolean preProcess(Bank bank) { + return true; + } + + @Override + public boolean postProcess(Bank bank) { + return true; + } + + @Override + public String process(Bank bank) { + Account queryAccount = bank.getAccount(account, password); + queryAccount.retriveMoney(amount); + return String.valueOf(queryAccount.getMoney()); + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/transaction/QueryBalanceTx.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/transaction/QueryBalanceTx.java new file mode 100644 index 0000000000..c14bac18e0 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/transaction/QueryBalanceTx.java @@ -0,0 +1,38 @@ +package com.coderising.ood.atmSimulation.bank.transaction; + +import com.coderising.ood.atmSimulation.bank.Bank; +import com.coderising.ood.atmSimulation.bank.account.Account; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class QueryBalanceTx implements Trasaction { + + private String account; + private String password; + + public QueryBalanceTx(String account, String password) { + this.account = account; + this.password = password; + } + + @Override + public boolean preProcess(Bank bank) { + return true; + } + + @Override + public boolean postProcess(Bank bank) { + return false; + } + + @Override + public String process(Bank bank) { + Account queryAccount = bank.getAccount(account, password); + if (account != null) { + return String.valueOf(queryAccount.getMoney()); + } + return null; + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/transaction/TransferTx.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/transaction/TransferTx.java new file mode 100644 index 0000000000..91d0b82ed8 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/transaction/TransferTx.java @@ -0,0 +1,42 @@ +package com.coderising.ood.atmSimulation.bank.transaction; + +import com.coderising.ood.atmSimulation.bank.Bank; +import com.coderising.ood.atmSimulation.bank.account.Account; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class TransferTx implements Trasaction { + + private String account; + private String password; + private String toCard; + private int amount; + + public TransferTx(String account, String password, String toCard, int amount) { + this.account = account; + this.password = password; + this.toCard = toCard; + this.amount = amount; + } + + @Override + public boolean preProcess(Bank bank) { + Account queryAccount = bank.getAccount(account, password); + return queryAccount.hasEnoughMoney(amount); + } + + @Override + public boolean postProcess(Bank bank) { + return true; + } + + @Override + public String process(Bank bank) { + Account queryAccount = bank.getAccount(account, password); + queryAccount.dipenseMoney(amount); + //mock add money to toCard + return String.valueOf(queryAccount.getMoney()); + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/transaction/Trasaction.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/transaction/Trasaction.java new file mode 100644 index 0000000000..cd09230fd3 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/transaction/Trasaction.java @@ -0,0 +1,16 @@ +package com.coderising.ood.atmSimulation.bank.transaction; + +import com.coderising.ood.atmSimulation.bank.Bank; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public interface Trasaction { + + public boolean preProcess(Bank bank); + + public boolean postProcess(Bank bank); + + public String process(Bank bank); +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/transaction/WithdrawTx.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/transaction/WithdrawTx.java new file mode 100644 index 0000000000..5ff8efec7a --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/bank/transaction/WithdrawTx.java @@ -0,0 +1,39 @@ +package com.coderising.ood.atmSimulation.bank.transaction; + +import com.coderising.ood.atmSimulation.bank.Bank; +import com.coderising.ood.atmSimulation.bank.account.Account; + +/** + * @author nvarchar + * date 2017/7/14 + */ +public class WithdrawTx implements Trasaction{ + + private String account; + private String password; + private int amount; + + public WithdrawTx(String account, String password, int amount) { + this.account = account; + this.password = password; + this.amount = amount; + } + + @Override + public boolean preProcess(Bank bank) { + Account queryAccount = bank.getAccount(account, password); + return queryAccount.hasEnoughMoney(amount); + } + + @Override + public boolean postProcess(Bank bank) { + return true; + } + + @Override + public String process(Bank bank) { + Account queryAccount = bank.getAccount(account, password); + queryAccount.dipenseMoney(amount); + return String.valueOf(queryAccount.getMoney()); + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/card/Card.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/card/Card.java new file mode 100644 index 0000000000..e1103c02ef --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/card/Card.java @@ -0,0 +1,17 @@ +package com.coderising.ood.atmSimulation.card; + +/** + * @author nvarchar + * date 2017/7/15 + */ +public class Card { + private String account; + + public Card(String account) { + this.account = account; + } + + public String getAccount() { + return account; + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/serialization/JsonConvert.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/serialization/JsonConvert.java new file mode 100644 index 0000000000..be1934944b --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/serialization/JsonConvert.java @@ -0,0 +1,19 @@ +package com.coderising.ood.atmSimulation.serialization; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; + +/** + * @author nvarchar + * date 2017/7/16 + */ +public class JsonConvert { + + public static String encode(NetPackage np) { + return JSON.toJSONString(np); + } + + public static NetPackage decode(String code) { + return JSONObject.parseObject(code, NetPackage.class); + } +} diff --git a/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/serialization/NetPackage.java b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/serialization/NetPackage.java new file mode 100644 index 0000000000..99246a3d41 --- /dev/null +++ b/students/2816977791/ood/ood-assignment/src/main/java/com/coderising/ood/atmSimulation/serialization/NetPackage.java @@ -0,0 +1,76 @@ +package com.coderising.ood.atmSimulation.serialization; + +import com.coderising.ood.atmSimulation.atm.Atm; + +/** + * @author nvarchar + * date 2017/7/16 + */ +public class NetPackage { + + public enum Type {Verify, QUERY, TRANSFER, DEPOSIT, WITHDRAW} + + private String account; + private String password; + private Integer amount; + private Type type; + private String toCard; + + public void setAccount(String account) { + this.account = account; + } + + public void setPassword(String password) { + this.password = password; + } + + public void setAmount(Integer amount) { + this.amount = amount; + } + + public void setType(Type type) { + this.type = type; + } + + public void setToCard(String toCard) { + this.toCard = toCard; + } + + public String getAccount() { + return account; + } + + public String getPassword() { + return password; + } + + public Integer getAmount() { + return amount; + } + + public Type getType() { + return type; + } + + public String getToCard() { + return toCard; + } + + public NetPackage(Type type, Atm atm, Integer amount, String toCard) { + this.account = atm.getAccount(); + this.password = atm.getPassword(); + this.amount = amount; + this.type = type; + this.toCard = toCard; + } + + public NetPackage(String account, String password) { + this.type = Type.Verify; + this.account = account; + this.password = password; + } + + public NetPackage() { + } +} + diff --git a/students/495232796/OOD/builderpattern/pom.xml b/students/495232796/OOD/builderpattern/pom.xml new file mode 100644 index 0000000000..84bf4627e3 --- /dev/null +++ b/students/495232796/OOD/builderpattern/pom.xml @@ -0,0 +1,42 @@ + + 4.0.0 + com.coderising + ood-assignment + 0.0.1-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.7 + 1.7 + + + + + jar + + ood-assignment + http://maven.apache.org + + + UTF-8 + + + + + + junit + junit + 4.12 + + + + + + aliyunmaven + http://maven.aliyun.com/nexus/content/groups/public/ + + + \ No newline at end of file diff --git a/students/495232796/OOD/builderpattern/src/main/java/com/coderising/dp/builder/TagBuilder.java b/students/495232796/OOD/builderpattern/src/main/java/com/coderising/dp/builder/TagBuilder.java new file mode 100644 index 0000000000..cf143e1ee6 --- /dev/null +++ b/students/495232796/OOD/builderpattern/src/main/java/com/coderising/dp/builder/TagBuilder.java @@ -0,0 +1,41 @@ +package com.coderising.dp.builder; + +public class TagBuilder { + private TagNode rootNode = null; + private TagNode curNode = null; + private TagNode parentNode = null; + + public TagBuilder(String rootTagName){ + rootNode = new TagNode(rootTagName); + curNode = rootNode; + } + + public TagBuilder addChild(String childTagName){ + TagNode tn = new TagNode(childTagName); + curNode.add(tn); + parentNode = curNode; + curNode = tn; + + return this; + } + public TagBuilder addSibling(String siblingTagName){ + TagNode tn = new TagNode(siblingTagName); + parentNode.add(tn); + curNode = tn; + + return this; + } + public TagBuilder setAttribute(String name, String value){ + curNode.setAttribute(name, value); + + return this; + } + public TagBuilder setText(String value){ + curNode.setValue(value); + + return this; + } + public String toXML(){ + return rootNode.toXML(); + } +} diff --git a/students/495232796/OOD/builderpattern/src/main/java/com/coderising/dp/builder/TagBuilderTest.java b/students/495232796/OOD/builderpattern/src/main/java/com/coderising/dp/builder/TagBuilderTest.java new file mode 100644 index 0000000000..e98cfae947 --- /dev/null +++ b/students/495232796/OOD/builderpattern/src/main/java/com/coderising/dp/builder/TagBuilderTest.java @@ -0,0 +1,41 @@ +package com.coderising.dp.builder; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class TagBuilderTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testToXML() { + + TagBuilder builder = new TagBuilder("order"); + + String xml = builder.addChild("line-items") + .addChild("line-item").setAttribute("pid", "P3677").setAttribute("qty", "3") + .addSibling("line-item").setAttribute("pid", "P9877").setAttribute("qty", "10") + .toXML(); + + String expected = "" + + "" + + "" + + "" + + "" + + ""; + + System.out.println(xml); + System.out.println(expected.equals(xml)); + assertEquals(expected, xml); + } + +} diff --git a/students/495232796/OOD/builderpattern/src/main/java/com/coderising/dp/builder/TagNode.java b/students/495232796/OOD/builderpattern/src/main/java/com/coderising/dp/builder/TagNode.java new file mode 100644 index 0000000000..6a31e04192 --- /dev/null +++ b/students/495232796/OOD/builderpattern/src/main/java/com/coderising/dp/builder/TagNode.java @@ -0,0 +1,82 @@ +package com.coderising.dp.builder; + +import java.util.ArrayList; +import java.util.List; + +public class TagNode { + private String tagName; + private String tagValue; + private List children = new ArrayList<>(); + private List attributes = new ArrayList<>(); + + public TagNode(String name){ + this.tagName = name; + } + public void add(TagNode child){ + this.children.add(child); + } + public void setAttribute(String name, String value) { + Attribute attr = findAttribute(name); + if(attr != null){ + attr.value = value; + } else { + attributes.add(new Attribute(name,value)); + } + } + private Attribute findAttribute(String name){ + for(Attribute attr : attributes){ + if(attr.name.equals(name)){ + return attr; + } + } + return null; + } + public void setValue(String value) { + this.tagValue = value; + + } + public String getTagName() { + return tagName; + } + public List getChildren() { + return children; + } + + private static class Attribute{ + public Attribute(String name, String value) { + this.name = name; + this.value = value; + } + String name; + String value; + + } + public String toXML(){ + return toXML(this); + } + private String toXML(TagNode node){ + StringBuilder buffer = new StringBuilder(); + buffer.append("<").append(node.tagName); + if(node.attributes.size()> 0){ + for(int i=0;i"); + return buffer.toString(); + } + buffer.append(">"); + for(TagNode childNode : node.children){ + buffer.append(toXML(childNode)); + } + buffer.append(""); + + + return buffer.toString(); + } + private String toXML(Attribute attr){ + return attr.name+"=\""+attr.value + "\""; + } +} diff --git a/students/495232796/OOD/builderpattern/src/main/java/com/coderising/dp/main/TestAll.java b/students/495232796/OOD/builderpattern/src/main/java/com/coderising/dp/main/TestAll.java new file mode 100644 index 0000000000..d5ab3b0f05 --- /dev/null +++ b/students/495232796/OOD/builderpattern/src/main/java/com/coderising/dp/main/TestAll.java @@ -0,0 +1,17 @@ +package com.coderising.dp.main; + +import com.coderising.dp.builder.TagBuilderTest; + +public class TestAll { + + public void testTag() { + TagBuilderTest tt = new TagBuilderTest(); + tt.testToXML(); + } + + public static void main(String[] args) { + TestAll ta = new TestAll(); + ta.testTag(); + } + +} diff --git a/students/513274874/ood/ood-assignment/src/main/java/com/coderising/ood/builder/Attribute.java b/students/513274874/ood/ood-assignment/src/main/java/com/coderising/ood/builder/Attribute.java new file mode 100644 index 0000000000..6ee7739309 --- /dev/null +++ b/students/513274874/ood/ood-assignment/src/main/java/com/coderising/ood/builder/Attribute.java @@ -0,0 +1,11 @@ +package com.coderising.dp.builder; + +public class Attribute{ + public Attribute(String name, String value) { + this.name = name; + this.value = value; + } + String name; + String value; + + } \ No newline at end of file diff --git a/students/513274874/ood/ood-assignment/src/main/java/com/coderising/ood/builder/TagBuilder.java b/students/513274874/ood/ood-assignment/src/main/java/com/coderising/ood/builder/TagBuilder.java new file mode 100644 index 0000000000..59c9dd8066 --- /dev/null +++ b/students/513274874/ood/ood-assignment/src/main/java/com/coderising/ood/builder/TagBuilder.java @@ -0,0 +1,46 @@ +package com.coderising.dp.builder; + +public class TagBuilder { + TagNode root; + TagNode parNode; + TagNode curNode; + + + public TagBuilder(String rootTagName) { + root = new TagNode(rootTagName); + curNode = root; + parNode = root; + } + + public TagBuilder addChild(String childTagName) { + TagNode node = new TagNode(childTagName); + curNode.add(node); + parNode = curNode; + curNode = node; + return this; + } + + public TagBuilder addSibling(String siblingTagName) { + TagNode node = new TagNode(siblingTagName); + parNode.add(node); + parNode = curNode; + curNode = node; + return this; + + } + + public TagBuilder setAttribute(String name, String value) { + curNode.setAttribute(name, value); + return this; + } + + public TagBuilder setText(String value) { + curNode.setValue(value); + return this; + } + + public String toXML() { + return root.toXML(); + } + +} diff --git a/students/513274874/ood/ood-assignment/src/main/java/com/coderising/ood/builder/TagBuilderTest.java b/students/513274874/ood/ood-assignment/src/main/java/com/coderising/ood/builder/TagBuilderTest.java new file mode 100644 index 0000000000..e30d20285b --- /dev/null +++ b/students/513274874/ood/ood-assignment/src/main/java/com/coderising/ood/builder/TagBuilderTest.java @@ -0,0 +1,40 @@ +package com.coderising.dp.builder; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class TagBuilderTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testToXML() { + + TagBuilder builder = new TagBuilder("order"); + + String xml = builder.addChild("line-items") + .addChild("line-item").setAttribute("pid", "P3677").setAttribute("qty", "3") + .addSibling("line-item").setAttribute("pid", "P9877").setAttribute("qty", "10") + .toXML(); + + String expected = "" + + "" + + "" + + "" + + "" + + ""; + + System.out.println(xml); + assertEquals(expected, xml); + } + +} diff --git a/students/513274874/ood/ood-assignment/src/main/java/com/coderising/ood/builder/TagNode.java b/students/513274874/ood/ood-assignment/src/main/java/com/coderising/ood/builder/TagNode.java new file mode 100644 index 0000000000..0a28545af0 --- /dev/null +++ b/students/513274874/ood/ood-assignment/src/main/java/com/coderising/ood/builder/TagNode.java @@ -0,0 +1,78 @@ +package com.coderising.dp.builder; + +import java.util.ArrayList; +import java.util.List; + +public class TagNode { + private String tagName; + private String tagValue; + private List children = new ArrayList<>(); + private List attributes = new ArrayList<>(); + + public TagNode(String name){ + this.tagName = name; + } + public void add(TagNode child){ + this.children.add(child); + } + public void setAttribute(String name, String value) { + Attribute attr = findAttribute(name); + if(attr != null){ + attr.value = value; + return; + } + + attributes.add(new Attribute(name,value)); + } + private Attribute findAttribute(String name){ + for(Attribute attr : attributes){ + if(attr.name.equals(name)){ + return attr; + } + } + return null; + } + public void setValue(String value) { + this.tagValue = value; + } + public String getTagName() { + return tagName; + } + public List getChildren() { + return children; + } + + public String toXML(){ + return toXML(this); + } + private String toXML(TagNode node){ + StringBuilder buffer = new StringBuilder(); + buffer.append("<").append(node.tagName); + if(node.attributes.size()> 0){ + for(int i=0;i"); + return buffer.toString(); + } + buffer.append(">"); + for(TagNode childNode : node.children){ + buffer.append(toXML(childNode)); + } + buffer.append(""); + + + return buffer.toString(); + } + private String toXML(Attribute attr){ + return attr.name+"=\""+attr.value + "\""; + } + + public TagNode(TagBuilder builder){ + + + } +} diff --git a/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/Bridage.java b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/Bridage.java new file mode 100644 index 0000000000..0b5f606a67 --- /dev/null +++ b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/Bridage.java @@ -0,0 +1,32 @@ +package com.github.orajavac.coding2017.ood.dp.bridge; + +public abstract class Bridage { + + private GraphicLibraryInter1 g1; + + public GraphicLibraryInter1 getG1() { + return g1; + } + + public void setG1(GraphicLibraryInter1 g1) { + this.g1 = g1; + } + + public GraphicLibraryInter2 getG2() { + return g2; + } + + public void setG2(GraphicLibraryInter2 g2) { + this.g2 = g2; + } + + private GraphicLibraryInter2 g2; + + public void drawAGraph(){ + + } + + public void drawGraph(){ + + } +} diff --git a/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/GraphicLibrary1.java b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/GraphicLibrary1.java new file mode 100644 index 0000000000..327caf7645 --- /dev/null +++ b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/GraphicLibrary1.java @@ -0,0 +1,10 @@ +package com.github.orajavac.coding2017.ood.dp.bridge; + +public class GraphicLibrary1 implements GraphicLibraryInter1{ + public void draw_a_line(int x1,int y1,int x2,int y2){ + System.out.println("draw_a_line"); + } + public void draw_a_circle(int x,int y, int r){ + System.out.println("draw_a_circle"); + } +} diff --git a/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/GraphicLibrary2.java b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/GraphicLibrary2.java new file mode 100644 index 0000000000..903f7e8869 --- /dev/null +++ b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/GraphicLibrary2.java @@ -0,0 +1,10 @@ +package com.github.orajavac.coding2017.ood.dp.bridge; + +public class GraphicLibrary2 implements GraphicLibraryInter2{ + public void drawLine(int x1,int x2,int y1,int y2){ + System.out.println("drawLine"); + } + public void drawCircle(int x,int y, int r){ + System.out.println("drawCircle"); + } +} diff --git a/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/GraphicLibraryInter1.java b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/GraphicLibraryInter1.java new file mode 100644 index 0000000000..514ea4362d --- /dev/null +++ b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/GraphicLibraryInter1.java @@ -0,0 +1,6 @@ +package com.github.orajavac.coding2017.ood.dp.bridge; + +public interface GraphicLibraryInter1 { + public void draw_a_line(int x1,int y1,int x2,int y2); + public void draw_a_circle(int x,int y, int r); +} diff --git a/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/GraphicLibraryInter2.java b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/GraphicLibraryInter2.java new file mode 100644 index 0000000000..55946c6419 --- /dev/null +++ b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/GraphicLibraryInter2.java @@ -0,0 +1,6 @@ +package com.github.orajavac.coding2017.ood.dp.bridge; + +public interface GraphicLibraryInter2 { + public void drawLine(int x1,int x2,int y1,int y2); + public void drawCircle(int x,int y, int r); +} diff --git a/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/MyBridge.java b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/MyBridge.java new file mode 100644 index 0000000000..30762d49f9 --- /dev/null +++ b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/bridge/MyBridge.java @@ -0,0 +1,14 @@ +package com.github.orajavac.coding2017.ood.dp.bridge; + +public class MyBridge extends Bridage{ + + public void drawAGraph(){ + getG1().draw_a_circle(1,2,3); + getG1().draw_a_line(1, 2,3,4); + } + + public void drawGraph(){ + getG2().drawLine(1,2,3,4); + getG2().drawCircle(1, 2,3); + } +} diff --git a/students/562768642/src/com/github/orajavac/coding2017/ood/dp/builder/TagBuilder.java b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/builder/TagBuilder.java new file mode 100644 index 0000000000..9fa50d3529 --- /dev/null +++ b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/builder/TagBuilder.java @@ -0,0 +1,38 @@ +package com.github.orajavac.coding2017.ood.dp.builder; + +public class TagBuilder { + + private TagNode rootNode; + private TagNode currentNode; + private TagNode parentNode; + public TagBuilder(String rootTagName){ + rootNode = new TagNode(rootTagName); + currentNode = rootNode; + parentNode = null; + } + + public TagBuilder addChild(String childTagName){ + parentNode = this.currentNode; + this.currentNode = new TagNode(childTagName); + parentNode.add(currentNode); + return this; + } + public TagBuilder addSibling(String siblingTagName){ + + this.currentNode = new TagNode(siblingTagName); + parentNode.add(this.currentNode); + return this; + + } + public TagBuilder setAttribute(String name, String value){ + this.currentNode.setAttribute(name, value); + return this; + } + public TagBuilder setText(String value){ + this.currentNode.setValue(value); + return this; + } + public String toXML(){ + return this.rootNode.toXML(); + } +} \ No newline at end of file diff --git a/students/562768642/src/com/github/orajavac/coding2017/ood/dp/builder/TagBuilderTest.java b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/builder/TagBuilderTest.java new file mode 100644 index 0000000000..4922057b53 --- /dev/null +++ b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/builder/TagBuilderTest.java @@ -0,0 +1,39 @@ +package com.github.orajavac.coding2017.ood.dp.builder; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class TagBuilderTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testToXML() { + +TagBuilder builder = new TagBuilder("order"); + + String xml = builder.addChild("line-items") + .addChild("line-item").setAttribute("pid", "P3677").setAttribute("qty", "3") + .addSibling("line-item").setAttribute("pid", "P9877").setAttribute("qty", "10") + .toXML(); + + String expected = "" + + "" + + "" + + "" + + "" + + ""; + + System.out.println(xml); + assertEquals(expected, xml); + } +} \ No newline at end of file diff --git a/students/562768642/src/com/github/orajavac/coding2017/ood/dp/builder/TagNode.java b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/builder/TagNode.java new file mode 100644 index 0000000000..dd305c8c0f --- /dev/null +++ b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/builder/TagNode.java @@ -0,0 +1,83 @@ +package com.github.orajavac.coding2017.ood.dp.builder; + +import java.util.ArrayList; +import java.util.List; + +public class TagNode { + private String tagName; + private String tagValue; + private List children = new ArrayList<>(); + private List attributes = new ArrayList<>(); + + public TagNode(String name){ + this.tagName = name; + } + public void add(TagNode child){ + this.children.add(child); + } + public void setAttribute(String name, String value) { + Attribute attr = findAttribute(name); + if(attr != null){ + attr.value = value; + return; + } + + attributes.add(new Attribute(name,value)); + } + private Attribute findAttribute(String name){ + for(Attribute attr : attributes){ + if(attr.name.equals(name)){ + return attr; + } + } + return null; + } + public void setValue(String value) { + this.tagValue = value; + + } + public String getTagName() { + return tagName; + } + public List getChildren() { + return children; + } + + private static class Attribute{ + public Attribute(String name, String value) { + this.name = name; + this.value = value; + } + String name; + String value; + + } + public String toXML(){ + return toXML(this); + } + private String toXML(TagNode node){ + StringBuilder buffer = new StringBuilder(); + buffer.append("<").append(node.tagName); + if(node.attributes.size()> 0){ + for(int i=0;i"); + return buffer.toString(); + } + buffer.append(">"); + for(TagNode childNode : node.children){ + buffer.append(toXML(childNode)); + } + buffer.append(""); + + + return buffer.toString(); + } + private String toXML(Attribute attr){ + return attr.name+"=\""+attr.value + "\""; + } +} \ No newline at end of file diff --git a/students/562768642/src/com/github/orajavac/coding2017/ood/dp/composite/Line.java b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/composite/Line.java new file mode 100644 index 0000000000..fd0187f8f7 --- /dev/null +++ b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/composite/Line.java @@ -0,0 +1,9 @@ +package com.github.orajavac.coding2017.ood.dp.composite; + +public class Line implements Shape{ + @Override + public void draw() { + + + } +} diff --git a/students/562768642/src/com/github/orajavac/coding2017/ood/dp/composite/Rectangle.java b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/composite/Rectangle.java new file mode 100644 index 0000000000..0c48433bd1 --- /dev/null +++ b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/composite/Rectangle.java @@ -0,0 +1,9 @@ +package com.github.orajavac.coding2017.ood.dp.composite; + +public class Rectangle implements Shape{ + @Override + public void draw() { + // TODO Auto-generated method stub + + } +} diff --git a/students/562768642/src/com/github/orajavac/coding2017/ood/dp/composite/Shape.java b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/composite/Shape.java new file mode 100644 index 0000000000..4760261807 --- /dev/null +++ b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/composite/Shape.java @@ -0,0 +1,5 @@ +package com.github.orajavac.coding2017.ood.dp.composite; + +public interface Shape { + public void draw(); +} diff --git a/students/562768642/src/com/github/orajavac/coding2017/ood/dp/composite/Square.java b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/composite/Square.java new file mode 100644 index 0000000000..4c722ef6b0 --- /dev/null +++ b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/composite/Square.java @@ -0,0 +1,9 @@ +package com.github.orajavac.coding2017.ood.dp.composite; + +public class Square implements Shape{ + @Override + public void draw() { + // TODO Auto-generated method stub + + } +} diff --git a/students/562768642/src/com/github/orajavac/coding2017/ood/dp/composite/Text.java b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/composite/Text.java new file mode 100644 index 0000000000..0f964c516e --- /dev/null +++ b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/composite/Text.java @@ -0,0 +1,9 @@ +package com.github.orajavac.coding2017.ood.dp.composite; + +public class Text implements Shape{ + @Override + public void draw() { + // TODO Auto-generated method stub + + } +} diff --git a/students/562768642/src/com/github/orajavac/coding2017/ood/dp/decorator/Email.java b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/decorator/Email.java new file mode 100644 index 0000000000..b7ad769be7 --- /dev/null +++ b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/decorator/Email.java @@ -0,0 +1,5 @@ +package com.github.orajavac.coding2017.ood.dp.decorator; + +public interface Email { + public String getContent(); +} diff --git a/students/562768642/src/com/github/orajavac/coding2017/ood/dp/decorator/EmailDecorator.java b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/decorator/EmailDecorator.java new file mode 100644 index 0000000000..4a441ae7c4 --- /dev/null +++ b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/decorator/EmailDecorator.java @@ -0,0 +1,14 @@ +package com.github.orajavac.coding2017.ood.dp.decorator; + +public class EmailDecorator implements Email{ + + private Email email; + + public EmailDecorator(Email e){ + this.email = e; + } + + public String getContent(){ + return email.getContent()+",本邮件仅为个人观点,并不代表公司立场"; + } +} diff --git a/students/562768642/src/com/github/orajavac/coding2017/ood/dp/decorator/EmailEncryptDecorator.java b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/decorator/EmailEncryptDecorator.java new file mode 100644 index 0000000000..56c653fcfe --- /dev/null +++ b/students/562768642/src/com/github/orajavac/coding2017/ood/dp/decorator/EmailEncryptDecorator.java @@ -0,0 +1,13 @@ +package com.github.orajavac.coding2017.ood.dp.decorator; + +public class EmailEncryptDecorator implements Email{ + private Email email; + + public EmailEncryptDecorator(Email e){ + this.email = e; + } + + public String getContent(){ + return "$a^@ + 4.0.0 + + 740707954 + 740707954 + 1.0-SNAPSHOT + jar + + 740707954 + http://maven.apache.org + + + UTF-8 + + + + + junit + junit + 4.11 + test + + + diff --git a/students/740707954/readMe b/students/740707954/readMe deleted file mode 100644 index f831579269..0000000000 --- a/students/740707954/readMe +++ /dev/null @@ -1,2 +0,0 @@ -TEST1 -2017.06.17 \ No newline at end of file diff --git a/students/740707954/src/main/java/dp/Attribute.java b/students/740707954/src/main/java/dp/Attribute.java new file mode 100644 index 0000000000..3ec9ee6dbf --- /dev/null +++ b/students/740707954/src/main/java/dp/Attribute.java @@ -0,0 +1,25 @@ +package dp; + +/** + * Created by lx on 2017/7/22. + */ +public class Attribute { + private String name; + private String value; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/students/740707954/src/main/java/dp/TagBuilder.java b/students/740707954/src/main/java/dp/TagBuilder.java new file mode 100644 index 0000000000..ea2c63df43 --- /dev/null +++ b/students/740707954/src/main/java/dp/TagBuilder.java @@ -0,0 +1,68 @@ +package dp; + +import java.util.List; + +/** + * 标签构造 + * Created by lx on 2017/7/22. + */ +public class TagBuilder { + private TagNode root;// 根节点 + private TagNode currentNode;// 当前节点 + private TagNode prevNode;// 上一节点 + + public TagBuilder(String order) { + root = new TagNode(order); + currentNode = root; + } + + /** + * 添加子标签 + * @param nodeName 节点名称 + * @return TagBuilder + */ + public TagBuilder addChild(String nodeName) { + TagNode node = new TagNode(nodeName); + List children = currentNode.getChildren(); + children.add(node); + prevNode = currentNode; + currentNode = node; + return this; + } + + /** + * 添加当前标签属性 + * @param key + * @param value + * @return TagBuilder + */ + public TagBuilder setAttribute(String key, String value) { + currentNode.setAttribute(key, value); + return this; + } + + /** + * 添加兄弟标签 + * @param nodeName 节点名称 + * @return TagBuilder + */ + public TagBuilder addSibling(String nodeName) { + TagNode node = new TagNode(nodeName); + prevNode.getChildren().add(node); + currentNode = node; + return this; + } + + /** + * 设置文本值 + * @param value + * @return 节点名称 + */ + public TagBuilder setText(String value) { + return null; + } + + public String toXML() { + return root.toXML(); + } +} diff --git a/students/740707954/src/main/java/dp/TagBuilderTest.java b/students/740707954/src/main/java/dp/TagBuilderTest.java new file mode 100644 index 0000000000..be4815e202 --- /dev/null +++ b/students/740707954/src/main/java/dp/TagBuilderTest.java @@ -0,0 +1,41 @@ +package dp; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; +/** + * Created by lx on 2017/7/23. + */ +public class TagBuilderTest { + + @Before + public void setUp() throws Exception{ + System.out.println("up"); + } + + @After + public void tearDown() { + System.out.println("down"); + } + + @Test + public void testToXML() { + TagBuilder builder = new TagBuilder("order"); + + String xml = builder.addChild("line-items") + .addChild("line-item").setAttribute("pid", "P3677").setAttribute("qty", "3") + .addSibling("line-item").setAttribute("pid", "P9877").setAttribute("qty", "10") + .toXML(); + + String expected = "" + + "" + + "" + + "" + + "" + + ""; + + System.out.println(xml); + assertEquals(expected, xml); + } +} diff --git a/students/740707954/src/main/java/dp/TagNode.java b/students/740707954/src/main/java/dp/TagNode.java new file mode 100644 index 0000000000..8bf58f772e --- /dev/null +++ b/students/740707954/src/main/java/dp/TagNode.java @@ -0,0 +1,130 @@ +package dp; + +import java.util.ArrayList; +import java.util.List; + +/** + * 标签 + * Created by lx on 2017/7/22. + */ +public class TagNode { + private String tagName; + private String tagValue; + private List children = new ArrayList<>(); + private List attributes = new ArrayList<>(); + + public TagNode(String tagName) { + this.tagName = tagName; + } + + /** + * 添加子标签 + * @param node + */ + public void add(TagNode node) { + children.add(node); + } + + /** + * 设置属性 + * @param key + * @param value + */ + public void setAttribute(String key, String value) { + Attribute attr = new Attribute(); + attr.setName(key); + attr.setValue(value); + attributes.add(attr); + } + + /** + * 查找当前标签属性 + * @param name + * @return + */ + private Attribute findAttribute(String name) { + for (Attribute attr : attributes) { + if (attr.getName().equals(name)) { + return attr; + } + } + return null; + } + + /** + * 转成xml字符串 + * @return + */ + public String toXML() { + return toXML(this); + } + + /** + * 将标签转成xml + * @param node + * @return + */ + private String toXML(TagNode node) { + StringBuilder buffer = new StringBuilder(); + buffer.append("<").append(node.tagName); + if (node.attributes.size() > 0) { + for (Attribute attr : node.attributes) { + buffer.append(" ").append(toXML(attr)); + } + } + + if (node.children.size() == 0) { + buffer.append("/>"); + return buffer.toString(); + } + + buffer.append(">"); + for (TagNode childrenNode : node.children) { + buffer.append(toXML(childrenNode)); + } + + buffer.append(""); + return buffer.toString(); + } + + /** + * 将属性转成xml + * @param attr + * @return + */ + private String toXML(Attribute attr) { + return attr.getName() + "=\"" + attr.getValue() + "\""; + } + + public String getTagName() { + return tagName; + } + + public void setTagName(String tagName) { + this.tagName = tagName; + } + + public String getTagValue() { + return tagValue; + } + + public void setTagValue(String tagValue) { + this.tagValue = tagValue; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + + public List getAttributes() { + return attributes; + } + + public void setAttributes(List attributes) { + this.attributes = attributes; + } +} diff --git "a/students/740707954/src/main/java/dp/\350\256\276\350\256\241\346\250\241\345\274\217\344\275\234\344\270\232" "b/students/740707954/src/main/java/dp/\350\256\276\350\256\241\346\250\241\345\274\217\344\275\234\344\270\232" new file mode 100644 index 0000000000..e69de29bb2 diff --git a/students/740707954/src/ood/oldSrp/ConfigurationKeys.java b/students/740707954/src/main/java/ood/srp1/ConfigurationKeys.java similarity index 91% rename from students/740707954/src/ood/oldSrp/ConfigurationKeys.java rename to students/740707954/src/main/java/ood/srp1/ConfigurationKeys.java index 154ea2c77c..65f5e77dc4 100644 --- a/students/740707954/src/ood/oldSrp/ConfigurationKeys.java +++ b/students/740707954/src/main/java/ood/srp1/ConfigurationKeys.java @@ -1,4 +1,4 @@ -package ood.oldSrp; +package ood.srp1; public class ConfigurationKeys { diff --git a/students/740707954/src/ood/newSrp/MailSender.java b/students/740707954/src/main/java/ood/srp1/MailSender.java similarity index 90% rename from students/740707954/src/ood/newSrp/MailSender.java rename to students/740707954/src/main/java/ood/srp1/MailSender.java index 14604b2c14..410c9ab27f 100644 --- a/students/740707954/src/ood/newSrp/MailSender.java +++ b/students/740707954/src/main/java/ood/srp1/MailSender.java @@ -1,10 +1,10 @@ -package ood.newSrp; +package ood.srp1; -import ood.newSrp.entity.Email; -import ood.newSrp.entity.Product; -import ood.newSrp.server.MainSmtpFactory; -import ood.newSrp.server.SmtpServer; -import ood.newSrp.server.TempSmtpFactory; +import ood.srp1.entity.Email; +import ood.srp1.entity.Product; +import ood.srp1.server.MainSmtpFactory; +import ood.srp1.server.SmtpServer; +import ood.srp1.server.TempSmtpFactory; import java.io.IOException; import java.util.List; @@ -25,7 +25,7 @@ public class MailSender { * @param p 产品信息 * @param sendUserList 用户信息 * @param d - * @throws IOException + * @throws java.io.IOException */ public void batchSendEMail(Product p, List sendUserList, boolean d) throws IOException { System.out.println("--------开始发送邮件-------"); diff --git a/students/740707954/src/ood/newSrp/PromotionMail.java b/students/740707954/src/main/java/ood/srp1/PromotionMail.java similarity index 85% rename from students/740707954/src/ood/newSrp/PromotionMail.java rename to students/740707954/src/main/java/ood/srp1/PromotionMail.java index 74cb9741da..865ae00896 100644 --- a/students/740707954/src/ood/newSrp/PromotionMail.java +++ b/students/740707954/src/main/java/ood/srp1/PromotionMail.java @@ -1,8 +1,8 @@ -package ood.newSrp; +package ood.srp1; -import ood.newSrp.entity.Product; -import ood.newSrp.server.UserServer; -import ood.newSrp.server.ProductServer; +import ood.srp1.entity.Product; +import ood.srp1.server.UserServer; +import ood.srp1.server.ProductServer; import java.util.List; import java.util.Map; diff --git a/students/740707954/src/ood/newSrp/conf/Configuration.java b/students/740707954/src/main/java/ood/srp1/conf/Configuration.java similarity index 90% rename from students/740707954/src/ood/newSrp/conf/Configuration.java rename to students/740707954/src/main/java/ood/srp1/conf/Configuration.java index 37bf3f3a58..d1fa32b6bf 100644 --- a/students/740707954/src/ood/newSrp/conf/Configuration.java +++ b/students/740707954/src/main/java/ood/srp1/conf/Configuration.java @@ -1,6 +1,7 @@ -package ood.newSrp.conf; +package ood.srp1.conf; + +import ood.srp1.ConfigurationKeys; -import ood.oldSrp.ConfigurationKeys; import java.util.HashMap; import java.util.Map; diff --git a/students/740707954/src/ood/newSrp/entity/Email.java b/students/740707954/src/main/java/ood/srp1/entity/Email.java similarity index 97% rename from students/740707954/src/ood/newSrp/entity/Email.java rename to students/740707954/src/main/java/ood/srp1/entity/Email.java index 17159b916b..57103bb760 100644 --- a/students/740707954/src/ood/newSrp/entity/Email.java +++ b/students/740707954/src/main/java/ood/srp1/entity/Email.java @@ -1,4 +1,4 @@ -package ood.newSrp.entity; +package ood.srp1.entity; /** * 邮件 diff --git a/students/740707954/src/ood/newSrp/entity/Product.java b/students/740707954/src/main/java/ood/srp1/entity/Product.java similarity index 96% rename from students/740707954/src/ood/newSrp/entity/Product.java rename to students/740707954/src/main/java/ood/srp1/entity/Product.java index 4fc38aacb4..0eed36cb74 100644 --- a/students/740707954/src/ood/newSrp/entity/Product.java +++ b/students/740707954/src/main/java/ood/srp1/entity/Product.java @@ -1,4 +1,4 @@ -package ood.newSrp.entity; +package ood.srp1.entity; /** * 产品信息 diff --git a/students/740707954/src/ood/newSrp/product_promotion.txt b/students/740707954/src/main/java/ood/srp1/product_promotion.txt similarity index 100% rename from students/740707954/src/ood/newSrp/product_promotion.txt rename to students/740707954/src/main/java/ood/srp1/product_promotion.txt diff --git a/students/740707954/src/ood/newSrp/server/MainSmtpFactory.java b/students/740707954/src/main/java/ood/srp1/server/MainSmtpFactory.java similarity index 87% rename from students/740707954/src/ood/newSrp/server/MainSmtpFactory.java rename to students/740707954/src/main/java/ood/srp1/server/MainSmtpFactory.java index 5dcfdc5a5b..644ef5988e 100644 --- a/students/740707954/src/ood/newSrp/server/MainSmtpFactory.java +++ b/students/740707954/src/main/java/ood/srp1/server/MainSmtpFactory.java @@ -1,4 +1,4 @@ -package ood.newSrp.server; +package ood.srp1.server; /** * Created by lx on 2017/6/17. diff --git a/students/740707954/src/ood/newSrp/server/MainSmtpServer.java b/students/740707954/src/main/java/ood/srp1/server/MainSmtpServer.java similarity index 86% rename from students/740707954/src/ood/newSrp/server/MainSmtpServer.java rename to students/740707954/src/main/java/ood/srp1/server/MainSmtpServer.java index 6e9be0a9ab..127d0fbef9 100644 --- a/students/740707954/src/ood/newSrp/server/MainSmtpServer.java +++ b/students/740707954/src/main/java/ood/srp1/server/MainSmtpServer.java @@ -1,7 +1,7 @@ -package ood.newSrp.server; +package ood.srp1.server; -import ood.newSrp.conf.Configuration; -import ood.oldSrp.ConfigurationKeys; +import ood.srp1.ConfigurationKeys; +import ood.srp1.conf.Configuration; /** * 主要服务器 diff --git a/students/740707954/src/ood/newSrp/server/ProductServer.java b/students/740707954/src/main/java/ood/srp1/server/ProductServer.java similarity index 90% rename from students/740707954/src/ood/newSrp/server/ProductServer.java rename to students/740707954/src/main/java/ood/srp1/server/ProductServer.java index db8efa8bc3..94dbea20e4 100644 --- a/students/740707954/src/ood/newSrp/server/ProductServer.java +++ b/students/740707954/src/main/java/ood/srp1/server/ProductServer.java @@ -1,6 +1,6 @@ -package ood.newSrp.server; +package ood.srp1.server; -import ood.newSrp.entity.Product; +import ood.srp1.entity.Product; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; @@ -24,10 +24,10 @@ public class ProductServer { /** * 生成优惠产品信息 * @return - * @throws IOException + * @throws java.io.IOException */ private static void initSpecialProductList() throws IOException { - String filePath = System.getProperty("user.dir") + "/src/ood/oldSrp/product_promotion.txt"; + String filePath = System.getProperty("user.dir") + "/src/main/java/ood/srp1/product_promotion.txt"; BufferedReader br = null; try { br = new BufferedReader(new FileReader(filePath)); diff --git a/students/740707954/src/ood/newSrp/server/SmtpFactory.java b/students/740707954/src/main/java/ood/srp1/server/SmtpFactory.java similarity index 80% rename from students/740707954/src/ood/newSrp/server/SmtpFactory.java rename to students/740707954/src/main/java/ood/srp1/server/SmtpFactory.java index efdf3ec25b..07606ca9c2 100644 --- a/students/740707954/src/ood/newSrp/server/SmtpFactory.java +++ b/students/740707954/src/main/java/ood/srp1/server/SmtpFactory.java @@ -1,4 +1,4 @@ -package ood.newSrp.server; +package ood.srp1.server; /** * Created by lx on 2017/6/17. diff --git a/students/740707954/src/ood/newSrp/server/SmtpServer.java b/students/740707954/src/main/java/ood/srp1/server/SmtpServer.java similarity index 92% rename from students/740707954/src/ood/newSrp/server/SmtpServer.java rename to students/740707954/src/main/java/ood/srp1/server/SmtpServer.java index ff35288d1f..7bc254ede3 100644 --- a/students/740707954/src/ood/newSrp/server/SmtpServer.java +++ b/students/740707954/src/main/java/ood/srp1/server/SmtpServer.java @@ -1,4 +1,4 @@ -package ood.newSrp.server; +package ood.srp1.server; /** * Created by Administrator on 2017/6/15 0015. diff --git a/students/740707954/src/ood/newSrp/server/TempSmtpFactory.java b/students/740707954/src/main/java/ood/srp1/server/TempSmtpFactory.java similarity index 87% rename from students/740707954/src/ood/newSrp/server/TempSmtpFactory.java rename to students/740707954/src/main/java/ood/srp1/server/TempSmtpFactory.java index ae16252fd0..1360c42c84 100644 --- a/students/740707954/src/ood/newSrp/server/TempSmtpFactory.java +++ b/students/740707954/src/main/java/ood/srp1/server/TempSmtpFactory.java @@ -1,4 +1,4 @@ -package ood.newSrp.server; +package ood.srp1.server; /** * Created by lx on 2017/6/17. diff --git a/students/740707954/src/ood/newSrp/server/TempSmtpServer.java b/students/740707954/src/main/java/ood/srp1/server/TempSmtpServer.java similarity index 86% rename from students/740707954/src/ood/newSrp/server/TempSmtpServer.java rename to students/740707954/src/main/java/ood/srp1/server/TempSmtpServer.java index 417cd8acd0..9c2ffebac1 100644 --- a/students/740707954/src/ood/newSrp/server/TempSmtpServer.java +++ b/students/740707954/src/main/java/ood/srp1/server/TempSmtpServer.java @@ -1,7 +1,7 @@ -package ood.newSrp.server; +package ood.srp1.server; -import ood.newSrp.conf.Configuration; -import ood.oldSrp.ConfigurationKeys; +import ood.srp1.ConfigurationKeys; +import ood.srp1.conf.Configuration; /** * 备用服务器 diff --git a/students/740707954/src/ood/newSrp/server/UserServer.java b/students/740707954/src/main/java/ood/srp1/server/UserServer.java similarity index 85% rename from students/740707954/src/ood/newSrp/server/UserServer.java rename to students/740707954/src/main/java/ood/srp1/server/UserServer.java index 0c9864eab7..952aca1d60 100644 --- a/students/740707954/src/ood/newSrp/server/UserServer.java +++ b/students/740707954/src/main/java/ood/srp1/server/UserServer.java @@ -1,6 +1,6 @@ -package ood.newSrp.server; +package ood.srp1.server; -import ood.newSrp.util.DBUtil; +import ood.srp1.util.DBUtil; import java.util.List; import java.util.Map; diff --git a/students/740707954/src/ood/oldSrp/DBUtil.java b/students/740707954/src/main/java/ood/srp1/util/DBUtil.java similarity index 95% rename from students/740707954/src/ood/oldSrp/DBUtil.java rename to students/740707954/src/main/java/ood/srp1/util/DBUtil.java index 2397e15ad1..715051d3c0 100644 --- a/students/740707954/src/ood/oldSrp/DBUtil.java +++ b/students/740707954/src/main/java/ood/srp1/util/DBUtil.java @@ -1,4 +1,4 @@ -package ood.oldSrp; +package ood.srp1.util; import java.util.ArrayList; import java.util.HashMap; import java.util.List; diff --git a/students/740707954/src/main/java/payroll/Employee.java b/students/740707954/src/main/java/payroll/Employee.java new file mode 100644 index 0000000000..65ac530d81 --- /dev/null +++ b/students/740707954/src/main/java/payroll/Employee.java @@ -0,0 +1,72 @@ +package payroll; + +import payroll.affiliation.Affiliation; +import payroll.classify.PaymentClassification; +import payroll.method.PaymentMethod; +import payroll.schedule.PaymentSchedule; + +import java.util.Date; + +/** + * 员工 + * Created by lx on 2017/7/8. + */ +public class Employee { + private String id; + private String name; + private String address; + private Affiliation affiliation; + + private PaymentClassification classification; + private PaymentSchedule schedule; + private PaymentMethod paymentMethod; + + public Employee(String name, String address) { + this.name = name; + this.address = address; + } + + /** + * 计算员工薪水 + * @param pc + */ + public void calculatePay(PayCheck pc) { + double grossPay = classification.calculdatePay(pc); + double deductions = affiliation.calculateDeductions(pc); + double netPay = grossPay - deductions; + pc.setGrossPay(grossPay); + pc.setDeductions(deductions); + pc.setNetPay(netPay); + paymentMethod.pay(pc); + } + + /** + * 是否为支付日 + * @param d + * @return + */ + public boolean isPayDay(Date d) { + return schedule.isPayDate(d); + } + + /** + * 获取支付的起始时间 + * @param d + * @return + */ + public Date getPayPeriodStartDate(Date d) { + return schedule.getPayPeriodStartDate(d); + } + + public void setClassifcation(PaymentClassification classifcation) { + this.classification = classifcation; + } + + public void setSchedule(PaymentSchedule schedule) { + this.schedule = schedule; + } + + public void setPaymentMethod(PaymentMethod paymentMethod) { + this.paymentMethod = paymentMethod; + } +} diff --git a/students/740707954/src/main/java/payroll/PayCheck.java b/students/740707954/src/main/java/payroll/PayCheck.java new file mode 100644 index 0000000000..b469890593 --- /dev/null +++ b/students/740707954/src/main/java/payroll/PayCheck.java @@ -0,0 +1,40 @@ +package payroll; + +import java.util.Date; + +/** + * 可以检查是否重复执行 + * Created by lx on 2017/7/8. + */ +public class PayCheck { + private Date payPeriodStart; + private Date payPeriodEnd; + private double grossPay;// 应付 + private double netPay;// 实付 + private double deductions;// 扣除 + + public PayCheck(Date payPeriodStart, Date payPeriodEnd) { + this.payPeriodStart = payPeriodStart; + this.payPeriodEnd = payPeriodEnd; + } + + public Date getPayPeriodEnd() { + return payPeriodEnd; + } + + public Date getPayPeriodStart() { + return payPeriodStart; + } + + public void setGrossPay(double grossPay) { + this.grossPay = grossPay; + } + + public void setNetPay(double netPay) { + this.netPay = netPay; + } + + public void setDeductions(double deductions) { + this.deductions = deductions; + } +} diff --git a/students/740707954/src/main/java/payroll/PaySystem.java b/students/740707954/src/main/java/payroll/PaySystem.java new file mode 100644 index 0000000000..ac81d79d22 --- /dev/null +++ b/students/740707954/src/main/java/payroll/PaySystem.java @@ -0,0 +1,30 @@ +package payroll; + +import payroll.service.IPayrollService; +import payroll.service.PayrollServiceImpl; +import java.util.Date; +import java.util.List; + +/** + * 薪水支付系统 + * Created by lx on 2017/7/8. + */ +public class PaySystem { + private static IPayrollService payrollService; + + static { + payrollService = new PayrollServiceImpl(); + } + + public static void main(String[] args) { + Date date = new Date(); + List employees = payrollService.getAllEmployees(); + for (Employee e : employees) { + if (e.isPayDay(date)) { + PayCheck pc = new PayCheck(e.getPayPeriodStartDate(date), date); + e.calculatePay(pc); + payrollService.savePaycheck(pc); + } + } + } +} diff --git a/students/740707954/src/main/java/payroll/TimeCard.java b/students/740707954/src/main/java/payroll/TimeCard.java new file mode 100644 index 0000000000..db41ff2da3 --- /dev/null +++ b/students/740707954/src/main/java/payroll/TimeCard.java @@ -0,0 +1,19 @@ +package payroll; + +import java.util.Date; + +/** + * Created by lx on 2017/7/8. + */ +public class TimeCard { + private Date date; + private int hours; + + public Date getDate(){ + return date; + } + + public int getHours() { + return hours; + } +} diff --git a/students/740707954/src/main/java/payroll/affiliation/Affiliation.java b/students/740707954/src/main/java/payroll/affiliation/Affiliation.java new file mode 100644 index 0000000000..15b2a4b41b --- /dev/null +++ b/students/740707954/src/main/java/payroll/affiliation/Affiliation.java @@ -0,0 +1,17 @@ +package payroll.affiliation; + +import payroll.PayCheck; + +/** + * Affiliation 会员 + * Created by lx on 2017/7/8. + */ +public interface Affiliation { + + /** + * 计算服务费 + * @param pc + * @return + */ + double calculateDeductions(PayCheck pc); +} diff --git a/students/740707954/src/main/java/payroll/affiliation/NonAffiliation.java b/students/740707954/src/main/java/payroll/affiliation/NonAffiliation.java new file mode 100644 index 0000000000..0bd2232001 --- /dev/null +++ b/students/740707954/src/main/java/payroll/affiliation/NonAffiliation.java @@ -0,0 +1,14 @@ +package payroll.affiliation; + +import payroll.PayCheck; + +/** + * 非会员 + * Created by lx on 2017/7/8. + */ +public class NonAffiliation implements Affiliation { + @Override + public double calculateDeductions(PayCheck pc) { + return 0; + } +} diff --git a/students/740707954/src/main/java/payroll/affiliation/ServiceCharge.java b/students/740707954/src/main/java/payroll/affiliation/ServiceCharge.java new file mode 100644 index 0000000000..7d89f17e27 --- /dev/null +++ b/students/740707954/src/main/java/payroll/affiliation/ServiceCharge.java @@ -0,0 +1,28 @@ +package payroll.affiliation; + +import java.util.Date; + +/** + * 服务费用 + * Created by lx on 2017/7/8. + */ +public class ServiceCharge { + private Date date; + private double amount; + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public double getAmount() { + return amount; + } + + public void setAmount(double amount) { + this.amount = amount; + } +} diff --git a/students/740707954/src/main/java/payroll/affiliation/UnionAffiliation.java b/students/740707954/src/main/java/payroll/affiliation/UnionAffiliation.java new file mode 100644 index 0000000000..44f482dda8 --- /dev/null +++ b/students/740707954/src/main/java/payroll/affiliation/UnionAffiliation.java @@ -0,0 +1,40 @@ +package payroll.affiliation; + +import payroll.PayCheck; +import payroll.util.DateUtil; +import java.util.Date; +import java.util.Map; + +/** + * 会员 + * Created by lx on 2017/7/8. + */ +public class UnionAffiliation implements Affiliation { + private int memeberId = 0; + private double weekDue = 0; + private Map charege; + + /** + * 计算服务费用 + * @param pc + * @return + */ + @Override + public double calculateDeductions(PayCheck pc) { + int fridays = DateUtil.getFridaysBetween(pc.getPayPeriodStart(), pc.getPayPeriodEnd()); + double totalDue = fridays * weekDue; + double totalCharge = 0.0d; + for (Map.Entry entry : charege.entrySet()) { + ServiceCharge sc = entry.getValue(); + totalCharge += sc.getAmount(); +// calculateCharge(sc); + } + return totalCharge + totalDue; + } + +// private double calculateCharge(ServiceCharge sc) { +// return sc.getAmount(); +// } + + +} diff --git a/students/740707954/src/main/java/payroll/classify/CommissionClassification.java b/students/740707954/src/main/java/payroll/classify/CommissionClassification.java new file mode 100644 index 0000000000..6fa1705c03 --- /dev/null +++ b/students/740707954/src/main/java/payroll/classify/CommissionClassification.java @@ -0,0 +1,36 @@ +package payroll.classify; + +import payroll.PayCheck; +import payroll.util.DateUtil; + +import java.util.Date; +import java.util.Map; + +/** + * 佣金雇员 + * Created by lx on 2017/7/8. + */ +public class CommissionClassification implements PaymentClassification { + private Map salesReceipt;// 销售凭条 + private double salary;//薪水 + private double rate;//单价 + + /** + * 计算薪水 + * @param pc + * @return + */ + @Override + public double calculdatePay(PayCheck pc) { + //1 统计销售凭条在pc.getStartDate 和 pc.getEndDate之间 + //2 加上基本工资,计算薪水 + double commission = 0.0d; + for (Map.Entry entry : salesReceipt.entrySet()) { + SalesReceipt receipt = entry.getValue(); + if (DateUtil.between(receipt.getDate(), pc.getPayPeriodStart(), pc.getPayPeriodEnd())) { + commission = receipt.getAmount() * rate; + } + } + return commission + salary; + } +} diff --git a/students/740707954/src/main/java/payroll/classify/HourlyClassification.java b/students/740707954/src/main/java/payroll/classify/HourlyClassification.java new file mode 100644 index 0000000000..30e4f5c59f --- /dev/null +++ b/students/740707954/src/main/java/payroll/classify/HourlyClassification.java @@ -0,0 +1,50 @@ +package payroll.classify; + +import payroll.PayCheck; +import payroll.util.DateUtil; + +import java.util.Date; +import java.util.Map; + +/** + * 小时工 + * Created by lx on 2017/7/8. + */ +public class HourlyClassification implements PaymentClassification { + private Map timeCards; + private double rate;// 价格 + + /** + * 统计时间卡在pc.getStartDate 和 pc.getEndDate之间 + * 并计算薪水 + * + * @param pc + * @return + */ + @Override + public double calculdatePay(PayCheck pc) { + double totalPay = 0.0d; + for (Map.Entry entry : timeCards.entrySet()) { + TimeCard tc = entry.getValue(); + if (DateUtil.between(tc.getDate(), pc.getPayPeriodStart(), pc.getPayPeriodEnd())) { + totalPay += calculatePayForTimeCard(tc); + } + } + return totalPay; + } + + /** + * 计算每个时间卡的薪水 + * + * @param tc + * @return + */ + public double calculatePayForTimeCard(TimeCard tc) { + int hours = tc.getHours(); + if (tc.getHours() > 8) { + return 8 * rate + (hours - 8) * 1.5 * rate; + } else { + return 8 * rate; + } + } +} diff --git a/students/740707954/src/main/java/payroll/classify/PaymentClassification.java b/students/740707954/src/main/java/payroll/classify/PaymentClassification.java new file mode 100644 index 0000000000..6cb2dafeee --- /dev/null +++ b/students/740707954/src/main/java/payroll/classify/PaymentClassification.java @@ -0,0 +1,11 @@ +package payroll.classify; + +import payroll.PayCheck; + +/** + * 分类 + * Created by lx on 2017/7/8. + */ +public interface PaymentClassification { + public double calculdatePay(PayCheck pc); +} diff --git a/students/740707954/src/main/java/payroll/classify/SalariedClassification.java b/students/740707954/src/main/java/payroll/classify/SalariedClassification.java new file mode 100644 index 0000000000..863d42e381 --- /dev/null +++ b/students/740707954/src/main/java/payroll/classify/SalariedClassification.java @@ -0,0 +1,21 @@ +package payroll.classify; + +import payroll.PayCheck; + +/** + * 月薪雇员 + * Created by lx on 2017/7/8. + */ +public class SalariedClassification implements PaymentClassification { + private double salary; + + /** + * 计算支付 + * @param pc + * @return + */ + @Override + public double calculdatePay(PayCheck pc) { + return salary; + } +} diff --git a/students/740707954/src/main/java/payroll/classify/SalesReceipt.java b/students/740707954/src/main/java/payroll/classify/SalesReceipt.java new file mode 100644 index 0000000000..2eae0fe092 --- /dev/null +++ b/students/740707954/src/main/java/payroll/classify/SalesReceipt.java @@ -0,0 +1,28 @@ +package payroll.classify; + +import java.util.Date; + +/** + * 销售凭条 + * Created by lx on 2017/7/8. + */ +public class SalesReceipt { + private Date date; + private double amount; + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public double getAmount() { + return amount; + } + + public void setAmount(double amount) { + this.amount = amount; + } +} diff --git a/students/740707954/src/main/java/payroll/classify/TimeCard.java b/students/740707954/src/main/java/payroll/classify/TimeCard.java new file mode 100644 index 0000000000..86b760083f --- /dev/null +++ b/students/740707954/src/main/java/payroll/classify/TimeCard.java @@ -0,0 +1,28 @@ +package payroll.classify; + +import java.util.Date; + +/** + * 时间卡 + * Created by lx on 2017/7/8. + */ +public class TimeCard { + private int hours;// 上班时间 + private Date date;// 那天上班 + + public int getHours() { + return hours; + } + + public void setHours(int hours) { + this.hours = hours; + } + + public void setDate(Date date) { + this.date = date; + } + + public Date getDate() { + return date; + } +} diff --git a/students/740707954/src/main/java/payroll/method/BankMethod.java b/students/740707954/src/main/java/payroll/method/BankMethod.java new file mode 100644 index 0000000000..4009040157 --- /dev/null +++ b/students/740707954/src/main/java/payroll/method/BankMethod.java @@ -0,0 +1,14 @@ +package payroll.method; + +import payroll.PayCheck; + +/** + * 银行卡支付 + * Created by lx on 2017/7/8. + */ +public class BankMethod implements PaymentMethod { + @Override + public void pay(PayCheck pc) { + + } +} diff --git a/students/740707954/src/main/java/payroll/method/HoldMethod.java b/students/740707954/src/main/java/payroll/method/HoldMethod.java new file mode 100644 index 0000000000..2261593191 --- /dev/null +++ b/students/740707954/src/main/java/payroll/method/HoldMethod.java @@ -0,0 +1,14 @@ +package payroll.method; + +import payroll.PayCheck; + +/** + * 从财务那里支付 + * Created by lx on 2017/7/8. + */ +public class HoldMethod implements PaymentMethod { + @Override + public void pay(PayCheck pc) { + + } +} diff --git a/students/740707954/src/main/java/payroll/method/MailMethod.java b/students/740707954/src/main/java/payroll/method/MailMethod.java new file mode 100644 index 0000000000..41ae0ff02e --- /dev/null +++ b/students/740707954/src/main/java/payroll/method/MailMethod.java @@ -0,0 +1,14 @@ +package payroll.method; + +import payroll.PayCheck; + +/** + * 邮递支付 + * Created by lx on 2017/7/8. + */ +public class MailMethod implements PaymentMethod{ + @Override + public void pay(PayCheck pc) { + + } +} diff --git a/students/740707954/src/main/java/payroll/method/PaymentMethod.java b/students/740707954/src/main/java/payroll/method/PaymentMethod.java new file mode 100644 index 0000000000..23ca7f954a --- /dev/null +++ b/students/740707954/src/main/java/payroll/method/PaymentMethod.java @@ -0,0 +1,11 @@ +package payroll.method; + +import payroll.PayCheck; + +/** + * 支付方式 + * Created by lx on 2017/7/8. + */ +public interface PaymentMethod { + public void pay(PayCheck pc); +} diff --git a/students/740707954/src/main/java/payroll/schedule/BiWeeklySchedule.java b/students/740707954/src/main/java/payroll/schedule/BiWeeklySchedule.java new file mode 100644 index 0000000000..6bb0dd22f6 --- /dev/null +++ b/students/740707954/src/main/java/payroll/schedule/BiWeeklySchedule.java @@ -0,0 +1,35 @@ +package payroll.schedule; + +import payroll.util.DateUtil; + +import java.util.Date; + +/** + * 每隔一周支付 + * Created by lx on 2017/7/8. + */ +public class BiWeeklySchedule implements PaymentSchedule { + Date firstPayFriday = DateUtil.parse("2017-07-07"); + + /** + * 是否为支付日 + * @param date + * @return + */ + @Override + public boolean isPayDate(Date date) { +// return DateUtil.add(date, -13) == firstPayFriday; + int interval = DateUtil.getDaysBetween(firstPayFriday, date); + return interval % 14 == 0; + } + + /** + * 获取支付薪水日期的起始时间 + * @param payPeriodEndDate + * @return + */ + @Override + public Date getPayPeriodStartDate(Date payPeriodEndDate) { + return DateUtil.add(payPeriodEndDate, -13); + } +} diff --git a/students/740707954/src/main/java/payroll/schedule/MonthSchedule.java b/students/740707954/src/main/java/payroll/schedule/MonthSchedule.java new file mode 100644 index 0000000000..b229cb7e2f --- /dev/null +++ b/students/740707954/src/main/java/payroll/schedule/MonthSchedule.java @@ -0,0 +1,31 @@ +package payroll.schedule; + +import payroll.util.DateUtil; + +import java.util.Date; + +/** + * 每月月底支付 + * Created by lx on 2017/7/8. + */ +public class MonthSchedule implements PaymentSchedule { + /** + * 是否为支付日 + * @param date + * @return + */ + @Override + public boolean isPayDate(Date date) { + return DateUtil.isLastDayOfMonth(date); + } + + /** + * 获取支付薪水日期的起始时间 + * @param payPeriodEndDate + * @return + */ + @Override + public Date getPayPeriodStartDate(Date payPeriodEndDate) { + return DateUtil.getFirstDayOfMonth(payPeriodEndDate); + } +} diff --git a/students/740707954/src/main/java/payroll/schedule/PaymentSchedule.java b/students/740707954/src/main/java/payroll/schedule/PaymentSchedule.java new file mode 100644 index 0000000000..f7445d2d3d --- /dev/null +++ b/students/740707954/src/main/java/payroll/schedule/PaymentSchedule.java @@ -0,0 +1,11 @@ +package payroll.schedule; + +import java.util.Date; + +/** + * Created by lx on 2017/7/8. + */ +public interface PaymentSchedule { + public boolean isPayDate(Date date); + public Date getPayPeriodStartDate(Date payPeriodEndDate); +} diff --git a/students/740707954/src/main/java/payroll/schedule/WeeklySchedule.java b/students/740707954/src/main/java/payroll/schedule/WeeklySchedule.java new file mode 100644 index 0000000000..8bf4fed61a --- /dev/null +++ b/students/740707954/src/main/java/payroll/schedule/WeeklySchedule.java @@ -0,0 +1,32 @@ +package payroll.schedule; + +import payroll.util.DateUtil; + +import java.util.Date; + +/** + * 每周五支付 + * Created by lx on 2017/7/8. + */ +public class WeeklySchedule implements PaymentSchedule{ + + /** + * 是否为支付日 + * @param date + * @return + */ + @Override + public boolean isPayDate(Date date) { + return DateUtil.isFriday(date); + } + + /** + * 获取支付薪水日期的起始时间 + * @param payPeriodEndDate + * @return + */ + @Override + public Date getPayPeriodStartDate(Date payPeriodEndDate) { + return DateUtil.add(payPeriodEndDate, -6); + } +} diff --git a/students/740707954/src/main/java/payroll/service/IPayrollService.java b/students/740707954/src/main/java/payroll/service/IPayrollService.java new file mode 100644 index 0000000000..ea0bf8f78f --- /dev/null +++ b/students/740707954/src/main/java/payroll/service/IPayrollService.java @@ -0,0 +1,14 @@ +package payroll.service; + +import payroll.Employee; +import payroll.PayCheck; +import java.util.List; + +/** + * Created by lx on 2017/7/8. + */ +public interface IPayrollService { + List getAllEmployees(); + + boolean savePaycheck(PayCheck pc); +} diff --git a/students/740707954/src/main/java/payroll/service/PayrollServiceImpl.java b/students/740707954/src/main/java/payroll/service/PayrollServiceImpl.java new file mode 100644 index 0000000000..1df829008d --- /dev/null +++ b/students/740707954/src/main/java/payroll/service/PayrollServiceImpl.java @@ -0,0 +1,31 @@ +package payroll.service; + +import payroll.Employee; +import payroll.PayCheck; +import java.util.List; + +/** + * Created by lx on 2017/7/8. + */ +public class PayrollServiceImpl implements IPayrollService { + + /** + * 获取所有员工信息 + * @return + */ + @Override + public List getAllEmployees() { + return null; + } + + /** + * 保存paycheck + * @param pc + * @return + */ + @Override + public boolean savePaycheck(PayCheck pc) { + System.out.println("保存。。。。。"); + return true; + } +} diff --git a/students/740707954/src/main/java/payroll/util/DateUtil.java b/students/740707954/src/main/java/payroll/util/DateUtil.java new file mode 100644 index 0000000000..f3e7f02d6c --- /dev/null +++ b/students/740707954/src/main/java/payroll/util/DateUtil.java @@ -0,0 +1,80 @@ +package payroll.util; + +import java.util.Date; + +/** + * 日期工具类 + * Created by lx on 2017/7/8. + */ +public class DateUtil { + /** + * 是否为周五 + * @param date + * @return + */ + public static boolean isFriday(Date date) { + return false; + } + + /** + * 返回对指定日期+i的日期 + * @param payPeriodEndDate + * @param i + * @return + */ + public static Date add(Date payPeriodEndDate, int i) { + return null; + } + + /** + * 是否为本月的最后一天 + * @param date + * @return + */ + public static boolean isLastDayOfMonth(Date date) { + return false; + } + + /** + * 获取本月的第一天 + * @param payPeriodEndDate + * @return + */ + public static Date getFirstDayOfMonth(Date payPeriodEndDate) { + return null; + } + + /** + * 将字符串转换为日期 + * @param s + * @return + */ + public static Date parse(String s) { + return null; + } + + /** + * 计算两个日期之间相差的天数 + * @param firstPayFriday + * @param date + * @return + */ + public static int getDaysBetween(Date firstPayFriday, Date date) { + return 0; + } + + public static boolean between(Date date, Date payPeriodStart, Date payPeriodEnd) { + + return false; + } + + /** + * 获取两个时间段中有几个周五 + * @param payPeriodStart + * @param payPeriodEnd + * @return + */ + public static int getFridaysBetween(Date payPeriodStart, Date payPeriodEnd) { + return 0; + } +} diff --git "a/students/740707954/src/main/java/payroll/\351\234\200\346\261\202" "b/students/740707954/src/main/java/payroll/\351\234\200\346\261\202" new file mode 100644 index 0000000000..1e2abc7bc0 --- /dev/null +++ "b/students/740707954/src/main/java/payroll/\351\234\200\346\261\202" @@ -0,0 +1,16 @@ +该系统由一个公司数据库以及和雇员相关的数据(例如工作时间卡)组成,系统需要准时地按照规则给员工支付薪水, +同时,必须从薪水中扣除各种扣款有些雇员是钟点工, 会按照他们雇员记录中每小时的报酬字段的值对他们进行支付, +他们每天提交工作时间卡,其中记录了日期以及工作小时数,如果每天工作超过8小时,按1.5倍进行支付。 +每周五对他们进行支付。有些雇员完全以月薪进行支付,每个月的最后一个工作日对他们进行支付, +在他们的雇员记录中有个月薪字段 同时,对于一些带薪的雇员,会根据他们的销售情况,支付给他们一定数量的佣金, +他们会提交销售凭条,其中记录了销售的日期和数量。在他们的雇员记录中有一个酬金报酬字段。 +每隔一周的周五对他们进行支付。雇员可以选择支付方式,可以把支票邮寄到他们指定的邮政地址, +也可以保存在财务那里随时支取,或者要求直接存入他们指定的银行账户 一些雇员会加入协会,在他们的雇员记录中有一个每周应付款项字段, +这些应付款需要从他们的薪水中扣除。协会有时会针对单个会员征收服务费用。 +协会每周会提交这些服务费用,服务费用从相应雇员的薪水总额中扣除。薪水支付程序每个工作日运行一次, 并在当天对相应的雇员进行支付, +系统会被告知雇员的支付日期,这样它会计算从雇员上次支付日期到规定的支付日期间应付的数额。 + + +雇员类型:小时工、领月薪的、带薪的 +支付方式:打到银行卡、邮递、保存在财务那里 +支付时间:每周五、每隔一周、每个月 diff --git a/students/740707954/src/ood/newSrp/util/DBUtil.java b/students/740707954/src/ood/newSrp/util/DBUtil.java deleted file mode 100644 index c1866fd925..0000000000 --- a/students/740707954/src/ood/newSrp/util/DBUtil.java +++ /dev/null @@ -1,25 +0,0 @@ -package ood.newSrp.util; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -public class DBUtil { - - /** - * 应该从数据库读, 但是简化为直接生成。 - * @param sql - * @return - */ - public static List query(String sql){ - - List userList = new ArrayList(); - for (int i = 1; i <= 3; i++) { - HashMap userInfo = new HashMap(); - userInfo.put("NAME", "User" + i); - userInfo.put("EMAIL", "aa@bb.com"); - userList.add(userInfo); - } - - return userList; - } -} diff --git a/students/740707954/src/ood/oldSrp/Configuration.java b/students/740707954/src/ood/oldSrp/Configuration.java deleted file mode 100644 index 9a1a4d075c..0000000000 --- a/students/740707954/src/ood/oldSrp/Configuration.java +++ /dev/null @@ -1,23 +0,0 @@ -package ood.oldSrp; -import java.util.HashMap; -import java.util.Map; - -public class Configuration { - - static Map configurations = new HashMap<>(); - static{ - configurations.put(ConfigurationKeys.SMTP_SERVER, "smtp.163.com"); - configurations.put(ConfigurationKeys.ALT_SMTP_SERVER, "smtp1.163.com"); - configurations.put(ConfigurationKeys.EMAIL_ADMIN, "admin@company.com"); - } - /** - * 应该从配置文件读, 但是这里简化为直接从一个map 中去读 - * @param key - * @return - */ - public String getProperty(String key) { - - return configurations.get(key); - } - -} diff --git a/students/740707954/src/ood/oldSrp/MailUtil.java b/students/740707954/src/ood/oldSrp/MailUtil.java deleted file mode 100644 index 71c229b37d..0000000000 --- a/students/740707954/src/ood/oldSrp/MailUtil.java +++ /dev/null @@ -1,18 +0,0 @@ -package ood.oldSrp; - -public class MailUtil { - - public static void sendEmail(String toAddress, String fromAddress, String subject, String message, String smtpHost, - boolean debug) { - //假装发了一封邮件 - StringBuilder buffer = new StringBuilder(); - buffer.append("From:").append(fromAddress).append("\n"); - buffer.append("To:").append(toAddress).append("\n"); - buffer.append("Subject:").append(subject).append("\n"); - buffer.append("Content:").append(message).append("\n"); - System.out.println(buffer.toString()); - - } - - -} diff --git a/students/740707954/src/ood/oldSrp/PromotionMail.java b/students/740707954/src/ood/oldSrp/PromotionMail.java deleted file mode 100644 index 2edbd5bf46..0000000000 --- a/students/740707954/src/ood/oldSrp/PromotionMail.java +++ /dev/null @@ -1,180 +0,0 @@ -package ood.oldSrp; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -public class PromotionMail { - - - protected String sendMailQuery = null; - - - protected String smtpHost = null; - protected String altSmtpHost = null; - protected String fromAddress = null; - protected String toAddress = null; - protected String subject = null; - protected String message = null; - - protected String productID = null; - protected String productDesc = null; - - private static Configuration config; - - - private static final String NAME_KEY = "NAME"; - private static final String EMAIL_KEY = "EMAIL"; - - - public static void main(String[] args) throws Exception { - - File f = new File(System.getProperty("user.dir") + "/src/ood/oldSrp/product_promotion.txt"); - boolean emailDebug = false; - - PromotionMail pe = new PromotionMail(f, emailDebug); - - } - - - public PromotionMail(File file, boolean mailDebug) throws Exception { - - //读取配置文件, 文件中只有一行用空格隔开, 例如 P8756 iPhone8 - readFile(file); - - - config = new Configuration(); - - setSMTPHost(); - setAltSMTPHost(); - - - setFromAddress(); - - - setLoadQuery(); - - sendEMails(mailDebug, loadMailingList()); - - - } - - - protected void setProductID(String productID) { - this.productID = productID; - - } - - protected String getproductID() { - return productID; - } - - protected void setLoadQuery() throws Exception { - - sendMailQuery = "Select name from subscriptions " - + "where product_id= '" + productID + "' " - + "and send_mail=1 "; - - - System.out.println("loadQuery set"); - } - - - protected void setSMTPHost() { - smtpHost = config.getProperty(ConfigurationKeys.SMTP_SERVER); - } - - - protected void setAltSMTPHost() { - altSmtpHost = config.getProperty(ConfigurationKeys.ALT_SMTP_SERVER); - - } - - - protected void setFromAddress() { - fromAddress = config.getProperty(ConfigurationKeys.EMAIL_ADMIN); - } - - protected void setMessage(HashMap userInfo) throws IOException { - - String name = (String) userInfo.get(NAME_KEY); - - subject = "您关注的产品降价了"; - message = "尊敬的 " + name + ", 您关注的产品 " + productDesc + " 降价了,欢迎购买!"; - - - } - - - protected void readFile(File file) throws IOException // @02C - { - BufferedReader br = null; - try { - br = new BufferedReader(new FileReader(file)); - String temp = br.readLine(); - String[] data = temp.split(" "); - - setProductID(data[0]); - setProductDesc(data[1]); - - System.out.println("产品ID = " + productID + "\n"); - System.out.println("产品描述 = " + productDesc + "\n"); - - } catch (IOException e) { - throw new IOException(e.getMessage()); - } finally { - br.close(); - } - } - - private void setProductDesc(String desc) { - this.productDesc = desc; - } - - - protected void configureEMail(HashMap userInfo) throws IOException { - toAddress = (String) userInfo.get(EMAIL_KEY); - if (toAddress.length() > 0) - setMessage(userInfo); - } - - protected List loadMailingList() throws Exception { - return DBUtil.query(this.sendMailQuery); - } - - - protected void sendEMails(boolean debug, List mailingList) throws IOException { - - System.out.println("开始发送邮件"); - - - if (mailingList != null) { - Iterator iter = mailingList.iterator(); - while (iter.hasNext()) { - configureEMail((HashMap) iter.next()); - try { - if (toAddress.length() > 0) - MailUtil.sendEmail(toAddress, fromAddress, subject, message, smtpHost, debug); - } catch (Exception e) { - - try { - MailUtil.sendEmail(toAddress, fromAddress, subject, message, altSmtpHost, debug); - - } catch (Exception e2) { - System.out.println("通过备用 SMTP服务器发送邮件失败: " + e2.getMessage()); - } - } - } - - - } else { - System.out.println("没有邮件发送"); - - } - - } -} diff --git a/students/740707954/src/ood/oldSrp/product_promotion.txt b/students/740707954/src/ood/oldSrp/product_promotion.txt deleted file mode 100644 index b7a974adb3..0000000000 --- a/students/740707954/src/ood/oldSrp/product_promotion.txt +++ /dev/null @@ -1,4 +0,0 @@ -P8756 iPhone8 -P3946 XiaoMi10 -P8904 Oppo_R15 -P4955 Vivo_X20 \ No newline at end of file diff --git a/students/740707954/src/test/java/test b/students/740707954/src/test/java/test new file mode 100644 index 0000000000..30d74d2584 --- /dev/null +++ b/students/740707954/src/test/java/test @@ -0,0 +1 @@ +test \ No newline at end of file diff --git "a/students/949603184/homework06-XML\347\273\223\347\202\271\347\224\237\346\210\220\345\231\250/DoubleLevelNesting/TagBuilder.java" "b/students/949603184/homework06-XML\347\273\223\347\202\271\347\224\237\346\210\220\345\231\250/DoubleLevelNesting/TagBuilder.java" new file mode 100644 index 0000000000..be8b594844 --- /dev/null +++ "b/students/949603184/homework06-XML\347\273\223\347\202\271\347\224\237\346\210\220\345\231\250/DoubleLevelNesting/TagBuilder.java" @@ -0,0 +1,71 @@ +package DoubleLevelNesting; + +import java.util.ArrayList; + +/** + * Tag构造器 + * + * @author LanyuanXiaoyao + * @create 2017-07-18 + */ +public class TagBuilder { + + private TagNode root; + private TagBuilder rootBuilder; + + public TagBuilder(String rootName) { + this.root = new TagNode(rootName); + this.root.setChildren(new ArrayList<>()); + this.root.setAttributes(new ArrayList<>()); + } + + public TagBuilder(String rootName, TagBuilder tagBuilder) { + this.root = new TagNode(rootName); + this.root.setChildren(new ArrayList<>()); + this.root.setAttributes(new ArrayList<>()); + this.rootBuilder = tagBuilder; + } + + public TagBuilder addChild(String childName) { + TagBuilder childBuilder = new TagBuilder(childName, this); + if (rootBuilder == null) + root.getChildren().add(childBuilder.build()); + else + rootBuilder.build().getChildren().add(childBuilder.build()); + return childBuilder; + } + + public TagBuilder setAttribute(String name, String value) { + TagNode.Attribute attribute = new TagNode.Attribute(name, value); + root.getAttributes().add(attribute); + return this; + } + + public TagBuilder end() { + return rootBuilder; + } + + public void toXML() { + if (rootBuilder == null) + System.out.println(root.toXML()); + else + rootBuilder.toXML(); + } + + public TagNode build() { + return root; + } + + public static void main(String[] args) { + new TagBuilder("root") + .setAttribute("attr3", "value") + .setAttribute("attr4", "value") + .addChild("child") + .setAttribute("attr1", "value") + .setAttribute("attr2", "value") + .addChild("child2") + .setAttribute("attr5", "value") + .setAttribute("attr6", "value") + .toXML(); + } +} diff --git "a/students/949603184/homework06-XML\347\273\223\347\202\271\347\224\237\346\210\220\345\231\250/DoubleLevelNesting/TagNode.java" "b/students/949603184/homework06-XML\347\273\223\347\202\271\347\224\237\346\210\220\345\231\250/DoubleLevelNesting/TagNode.java" new file mode 100644 index 0000000000..45fc5ac9b6 --- /dev/null +++ "b/students/949603184/homework06-XML\347\273\223\347\202\271\347\224\237\346\210\220\345\231\250/DoubleLevelNesting/TagNode.java" @@ -0,0 +1,94 @@ +package DoubleLevelNesting; + +import java.util.ArrayList; +import java.util.List; + +/** + * Tag节点 + * + * @author LanyuanXiaoyao + * @create 2017-07-18 + */ +public class TagNode { + private String tagName; + private String tagValue; + private List children = new ArrayList<>(); + private List attributes = new ArrayList<>(); + + public TagNode(String tagName) { + this.tagName = tagName; + } + + public String getTagName() { + return tagName; + } + + public void setTagName(String tagName) { + this.tagName = tagName; + } + + public String getTagValue() { + return tagValue; + } + + public void setTagValue(String tagValue) { + this.tagValue = tagValue; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + + public List getAttributes() { + return attributes; + } + + public void setAttributes(List attributes) { + this.attributes = attributes; + } + + public static class Attribute { + public Attribute(String name, String value) { + this.name = name; + this.value = value; + } + + String name; + String value; + } + + public String toXML() { + return toXML(this); + } + + private String toXML(TagNode node) { + StringBuilder buffer = new StringBuilder(); + buffer.append("<").append(node.tagName); + if (node.attributes.size() > 0) { + for (int i = 0; i < node.attributes.size(); i++) { + Attribute attr = node.attributes.get(i); + buffer.append(" ").append(toXML(attr)); + } + } + if (node.children.size() == 0) { + buffer.append("/>"); + return buffer.toString(); + } + System.out.println(node.children.size()); + buffer.append(">"); + for (TagNode childNode : node.children) { + buffer.append(toXML(childNode)); + } + buffer.append(""); + + return buffer.toString(); + } + + private String toXML(Attribute attr) { + return attr.name + "=\"" + attr.value + "\""; + } +} diff --git "a/students/949603184/homework06-XML\347\273\223\347\202\271\347\224\237\346\210\220\345\231\250/MultiLevelNesting/TagBuilder.java" "b/students/949603184/homework06-XML\347\273\223\347\202\271\347\224\237\346\210\220\345\231\250/MultiLevelNesting/TagBuilder.java" new file mode 100644 index 0000000000..64b3a3d51a --- /dev/null +++ "b/students/949603184/homework06-XML\347\273\223\347\202\271\347\224\237\346\210\220\345\231\250/MultiLevelNesting/TagBuilder.java" @@ -0,0 +1,73 @@ +package MultiLevelNesting; + +import java.util.ArrayList; + +/** + * Tag构造器 + * + * @author LanyuanXiaoyao + * @create 2017-07-18 + */ +public class TagBuilder { + + private TagNode root; + private TagBuilder rootBuilder; + + public TagBuilder(String rootName) { + this.root = new TagNode(rootName); + this.root.setChildren(new ArrayList<>()); + this.root.setAttributes(new ArrayList<>()); + } + + public TagBuilder(String rootName, TagBuilder tagBuilder) { + this.root = new TagNode(rootName); + this.root.setChildren(new ArrayList<>()); + this.root.setAttributes(new ArrayList<>()); + this.rootBuilder = tagBuilder; + } + + public TagBuilder addChild(String childName) { + TagBuilder childBuilder = new TagBuilder(childName, this); + root.getChildren().add(childBuilder.toTagTreeNode()); + return childBuilder; + } + + public TagBuilder setAttribute(String name, String value) { + TagNode.Attribute attribute = new TagNode.Attribute(name, value); + root.getAttributes().add(attribute); + return this; + } + + public TagBuilder and() { + return rootBuilder; + } + + public void toXML() { + if (rootBuilder == null) + System.out.println(root.toXML()); + else + rootBuilder.toXML(); + } + + public TagNode toTagTreeNode() { + return root; + } + + public static void main(String[] args) { + new TagBuilder("root") + .setAttribute("attr0","0") + .addChild("child") + .setAttribute("attr1","1") + .setAttribute("attr1","1") + .setAttribute("attr1","1") + .addChild("child2") + .setAttribute("attr2","2") + .setAttribute("attr2","2") + .setAttribute("attr2","2") + .and() + .and() + .addChild("child3") + .setAttribute("attr3","3") + .toXML(); + } +} diff --git "a/students/949603184/homework06-XML\347\273\223\347\202\271\347\224\237\346\210\220\345\231\250/MultiLevelNesting/TagNode.java" "b/students/949603184/homework06-XML\347\273\223\347\202\271\347\224\237\346\210\220\345\231\250/MultiLevelNesting/TagNode.java" new file mode 100644 index 0000000000..421ca50850 --- /dev/null +++ "b/students/949603184/homework06-XML\347\273\223\347\202\271\347\224\237\346\210\220\345\231\250/MultiLevelNesting/TagNode.java" @@ -0,0 +1,93 @@ +package MultiLevelNesting; + +import java.util.ArrayList; +import java.util.List; + +/** + * Tag节点 + * + * @author LanyuanXiaoyao + * @create 2017-07-18 + */ +public class TagNode { + private String tagName; + private String tagValue; + private List children = new ArrayList<>(); + private List attributes = new ArrayList<>(); + + public TagNode(String tagName) { + this.tagName = tagName; + } + + public String getTagName() { + return tagName; + } + + public void setTagName(String tagName) { + this.tagName = tagName; + } + + public String getTagValue() { + return tagValue; + } + + public void setTagValue(String tagValue) { + this.tagValue = tagValue; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + + public List getAttributes() { + return attributes; + } + + public void setAttributes(List attributes) { + this.attributes = attributes; + } + + public static class Attribute { + public Attribute(String name, String value) { + this.name = name; + this.value = value; + } + + String name; + String value; + } + + public String toXML() { + return toXML(this); + } + + private String toXML(TagNode node) { + StringBuilder buffer = new StringBuilder(); + buffer.append("<").append(node.tagName); + if (node.attributes.size() > 0) { + for (int i = 0; i < node.attributes.size(); i++) { + Attribute attr = node.attributes.get(i); + buffer.append(" ").append(toXML(attr)); + } + } + if (node.children.size() == 0) { + buffer.append("/>"); + return buffer.toString(); + } + buffer.append(">"); + for (TagNode childNode : node.children) { + buffer.append(toXML(childNode)); + } + buffer.append(""); + + return buffer.toString(); + } + + private String toXML(Attribute attr) { + return attr.name + "=\"" + attr.value + "\""; + } +} diff --git "a/students/949603184/homework06-XML\347\273\223\347\202\271\347\224\237\346\210\220\345\231\250/\345\210\206\345\210\253\345\256\236\347\216\260\344\272\206\344\270\244\345\261\202\345\265\214\345\245\227\345\222\214\345\244\232\345\261\202\345\265\214\345\245\227" "b/students/949603184/homework06-XML\347\273\223\347\202\271\347\224\237\346\210\220\345\231\250/\345\210\206\345\210\253\345\256\236\347\216\260\344\272\206\344\270\244\345\261\202\345\265\214\345\245\227\345\222\214\345\244\232\345\261\202\345\265\214\345\245\227" new file mode 100644 index 0000000000..e69de29bb2 diff --git a/students/977996067/pom.xml b/students/977996067/pom.xml new file mode 100644 index 0000000000..2c2630e332 --- /dev/null +++ b/students/977996067/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + cc.javaone.coding2017 + ood-assignment + 1.0-SNAPSHOT + + + junit + junit + 4.12 + + + org.projectlombok + lombok + 1.16.18 + + + + + \ No newline at end of file diff --git a/students/977996067/src/main/java/com/coderising/dp/week1/TagBuilder.java b/students/977996067/src/main/java/com/coderising/dp/week1/TagBuilder.java new file mode 100644 index 0000000000..a31514a6fe --- /dev/null +++ b/students/977996067/src/main/java/com/coderising/dp/week1/TagBuilder.java @@ -0,0 +1,63 @@ +package com.coderising.dp.week1; + +import java.util.List; +import java.util.concurrent.atomic.AtomicReference; + +public class TagBuilder { + + private TagNode rootTag; + + private AtomicReference tempParentNode = new AtomicReference<>(); + + private AtomicReference currentNode = new AtomicReference<>(); + + public TagBuilder(String rootTagName) { + this.rootTag = new TagNode(); + rootTag.setTagName(rootTagName); + tempParentNode.set(rootTag); + currentNode.set(rootTag); + } + + public TagBuilder addChild(String childTagName) { + TagNode node = currentNode.get(); + tempParentNode.set(node); + currentNode.set(doAddChildren(node, childTagName)); + return this; + } + + private TagNode doAddChildren(TagNode node, String childTagName) { + List children = node.getChildren(); + TagNode childTag = new TagNode(); + childTag.setTagName(childTagName); + children.add(childTag); + return childTag; + } + + public TagBuilder addSibling(String childTagName) { + TagNode tagNode = tempParentNode.get(); + TagNode childTag = doAddChildren(tagNode, childTagName); + currentNode.set(childTag); + return this; + } + + public TagBuilder setAttribute(String key, String value) { + TagNode tagNode = currentNode.get(); + List attributes = tagNode.getAttributes(); + + TagNode.Attribute attribute = new TagNode.Attribute(); + attribute.setName(key); + attribute.setValue(value); + attributes.add(attribute); + return this; + } + + public String toXML() { + return rootTag.toString(); + } +} + + +// ~ HomeWork2 +// ======================================================================================================== + +// 单例的类: java.lang.Runtime \ No newline at end of file diff --git a/students/977996067/src/main/java/com/coderising/dp/week1/TagNode.java b/students/977996067/src/main/java/com/coderising/dp/week1/TagNode.java new file mode 100644 index 0000000000..6fa56abfdf --- /dev/null +++ b/students/977996067/src/main/java/com/coderising/dp/week1/TagNode.java @@ -0,0 +1,91 @@ +package com.coderising.dp.week1; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class TagNode { + private String tagName; + private String tagValue; + private List children = new ArrayList<>(); + private List attributes = new ArrayList<>(); + + public String getTagName() { + return tagName; + } + + public void setTagName(String tagName) { + this.tagName = tagName; + } + + public String getTagValue() { + return tagValue; + } + + public void setTagValue(String tagValue) { + this.tagValue = tagValue; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + + public List getAttributes() { + return attributes; + } + + public void setAttributes(List attributes) { + this.attributes = attributes; + } + + public static class Attribute { + String name; + String value; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + @Override + public String toString() { + String lineBreaker = System.getProperty("line.separator"); + StringBuilder sb = new StringBuilder(); + sb.append("<").append(this.tagName); + if (!isEmpty(this.attributes)) { + attributes.forEach(attribute -> sb.append(" ") + .append(attribute.getName()) + .append("=\"") + .append(attribute.getValue()) + .append("\"")); + } + sb.append(">"); + if (!isEmpty(this.children)) { + sb.append(lineBreaker); + children.forEach(child -> sb.append(child.toString())); + } + sb.append(lineBreaker).append("").append(lineBreaker); + return sb.toString(); + + } + + private boolean isEmpty(Collection c) { + return c == null || c.size() == 0; + } +} diff --git a/students/977996067/src/test/java/com/coderising/dp/week1/TagNodeTest.java b/students/977996067/src/test/java/com/coderising/dp/week1/TagNodeTest.java new file mode 100644 index 0000000000..554ae1fda4 --- /dev/null +++ b/students/977996067/src/test/java/com/coderising/dp/week1/TagNodeTest.java @@ -0,0 +1,20 @@ +package com.coderising.dp.week1; + +import org.junit.Test; + +public class TagNodeTest { + + @Test + public void testBuilder() { + + TagBuilder builder = new TagBuilder("order"); + + + String xml = builder.addChild("line-items") + .addChild("line-item").setAttribute("pid", "p3333").setAttribute("qty", "3") + .addSibling("line-item").setAttribute("pid", "p9876").setAttribute("qty", "10") + .toXML(); + + System.out.println(xml); + } +} \ No newline at end of file