📄 bank.java
字号:
package server;import java.io.*;import java.util.ArrayList;import java.net.*;/** * A bank contains customers with bank accounts. */public class Bank { /** * Constructs a bank with no customers. */ public Bank() { customers = new ArrayList(); } /** * Reads the customer numbers and pins and initializes the bank accounts. * * @param filename * the name of the customer file */ public void readCustomers(String filename) throws IOException { URLConnection con = getServletConnection("login"); OutputStream outstream = con.getOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(outstream); oos.writeObject(null); oos.flush(); oos.close(); // receive result from servlet InputStream instr = con.getInputStream(); ObjectInputStream inputFromServlet = new ObjectInputStream(instr); try { ArrayList<String> result = (ArrayList<String>) inputFromServlet.readObject(); for(String s :result) { String[] a = s.split("&"); Customer c = new Customer(Integer.parseInt(a[0]),Integer.parseInt(a[1])); addCustomer(c); } } catch (Exception e) { e.printStackTrace(); } inputFromServlet.close(); instr.close(); } /** * Adds a customer to the bank. * * @param c * the customer to add */ public void addCustomer(Customer c) { customers.add(c); } /** * Finds a customer in the bank. * * @param aNumber * a customer number * @param aPin * a personal identification number * @return the matching customer, or null if no customer matches */ public Customer findCustomer(int aNumber, int aPin) { for (int i = 0; i < customers.size(); i++) { Customer c = (Customer) customers.get(i); if (c.match(aNumber, aPin)) return c; } return null; } private URLConnection getServletConnection(String addr) throws MalformedURLException, IOException { // Connection zum Servlet 鰂fnen URL urlServlet = new URL("http://localhost:8080/mid3t/" + addr); URLConnection con = urlServlet.openConnection(); // konfigurieren con.setDoInput(true); con.setDoOutput(true); con.setUseCaches(false); con.setRequestProperty("Content-Type", "application/x-java-serialized-object"); // und zur點kliefern return con; } private ArrayList customers;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -