Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.lu.ics.inlämningsuppgifter;
- import javax.swing.JFrame;
- public class Controller {
- PersonRegister persons;
- JFrame frame;
- public Controller (PersonRegister personReg, JFrame frame) {
- this.persons=personReg;
- this.frame=frame;
- }
- public void addPerson (String pNbr, String pName) {
- Person tmpPerson = new Person(pNbr, pName);
- persons.addPerson(tmpPerson);
- }
- public void addPersonAccount (String pNbr, String pName, String accNbr) {
- Person tmpPerson = new Person(pNbr, pName);
- Account account = new Account(accNbr);
- tmpPerson.setAccounts(account);
- }
- public String[] findPerson(String pNbrFind) {
- Person p;
- String[] aPerson = null;
- p = persons.findPerson(pNbrFind);
- if (p != null && p.getAccounts() != null) {
- aPerson = new String[4];
- aPerson[0] = p.getPNbr();
- aPerson[1] = p.getName();
- aPerson[2] = p.getAccounts();
- } else if (p != null) {
- aPerson = new String[2];
- aPerson[0] = p.getPNbr();
- aPerson[1] = p.getName();
- }
- return aPerson;
- }
- }
- package org.lu.ics.inlämningsuppgifter;
- public class Account {
- private String nbr;
- private double balance;
- private Person owner;
- public Person getOwner() {
- return owner;
- }
- public void setOwner(Person newOwner) {
- owner = newOwner;
- }
- public void setNbr(String newNbr) {
- nbr = newNbr;
- }
- public String getNbr() {
- return nbr;
- }
- public Account (String accNbr) {
- balance = 0.00;
- this.setNbr(accNbr);
- }
- public void setBalance(double newBalance) {
- balance = newBalance;
- this.setBalance(newBalance);
- }
- public double getBalance() {
- return balance;
- }
- public void credit(double amount) {
- balance = balance + amount;
- }
- public void withdraw(double amount) {
- balance = balance - amount;
- }
- }
- import java.util.*;
- public class Person {
- private String pNbr;
- private String name;
- private ArrayList<Account> accounts = new ArrayList<Account>();
- public Person(String pNbr, String pName) {
- this.setPNbr(pNbr);
- this.setName(pName);
- }
- public ArrayList<Account> getAccount() {
- return accounts;
- }
- public void setPNbr(String newPNbr) {
- pNbr = newPNbr;
- }
- public String getPNbr() {
- return pNbr;
- }
- public void setName(String newName) {
- name = newName;
- }
- public String getName() {
- return name;
- }
- public void setAccounts(ArrayList<Account> newAccounts) {
- accounts = newAccounts;
- }
- public ArrayList<Account> getAccounts() {
- return accounts;
- }
- public void addAccount(Account anAccount) {
- this.getAccounts().add(anAccount);
- }
- }
- package org.lu.ics.inlämningsuppgifter;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JButton;
- import javax.swing.JTable;
- import javax.swing.table.DefaultTableModel;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JScrollPane;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- public class PersonApplication {
- private JFrame frame;
- private final JTable tblAccounts = new JTable();
- private JTextField textField;
- private JTextField textField_1;
- private JTextField textField_AccNbr;
- private Controller controller;
- private PersonRegister personRegister;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- PersonApplication window = new PersonApplication();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public PersonApplication() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- JFrame frame = new JFrame("Accounts");
- frame.setBounds(100, 100, 840, 524);
- frame.getContentPane();
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- String col[] = {"Account", "Balance"};
- DefaultTableModel tableModel = new DefaultTableModel(col, 2);
- JTable table = new JTable(tableModel);
- JButton btnAddPerson = new JButton("Add person");
- btnAddPerson.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- }
- });
- btnAddPerson.setBounds(35, 296, 105, 23);
- frame.getContentPane().add(btnAddPerson);
- JButton btnRemovePerson = new JButton("Remove person");
- btnRemovePerson.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- }
- });
- btnRemovePerson.setBounds(35, 330, 107, 23);
- frame.getContentPane().add(btnRemovePerson);
- JButton btnFindPerson = new JButton("Find person");
- btnFindPerson.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- String accNumber = textField_AccNbr.getText();
- //String[] tmpCustomer = controller.
- }
- });
- btnFindPerson.setBounds(35, 364, 91, 23);
- frame.getContentPane().add(btnFindPerson);
- JButton btnAddAccount = new JButton("Add Account");
- btnAddAccount.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- }
- });
- btnAddAccount.setBounds(269, 296, 99, 23);
- frame.getContentPane().add(btnAddAccount);
- JButton btnShowAccount = new JButton("Show Accounts");
- btnShowAccount.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- DefaultTableModel model=(DefaultTableModel)
- tblAccounts.getModel();
- }
- });
- btnShowAccount.setBounds(439, 451, 105, 23);
- frame.getContentPane().add(btnShowAccount);
- tblAccounts.setBounds(439, 300, 352, 132);
- frame.getContentPane().add(tblAccounts);
- JLabel lblName = new JLabel("Name:");
- lblName.setBounds(47, 29, 31, 14);
- frame.getContentPane().add(lblName);
- textField = new JTextField();
- textField.setBounds(139, 26, 86, 20);
- frame.getContentPane().add(textField);
- textField.setColumns(10);
- JLabel lblPnmbr = new JLabel("PNmbr:");
- lblPnmbr.setBounds(47, 57, 35, 14);
- frame.getContentPane().add(lblPnmbr);
- textField_1 = new JTextField();
- textField_1.setBounds(139, 51, 86, 20);
- frame.getContentPane().add(textField_1);
- textField_1.setColumns(10);
- JLabel lblAccountNumber = new JLabel("Account number:");
- lblAccountNumber.setBounds(47, 90, 82, 14);
- frame.getContentPane().add(lblAccountNumber);
- textField_AccNbr = new JTextField();
- textField_AccNbr.setBounds(139, 87, 86, 20);
- frame.getContentPane().add(textField_AccNbr);
- textField_AccNbr.setColumns(10);
- }
- }
- package org.lu.ics.inlämningsuppgifter;
- import java.util.*;
- public class PersonRegister {
- private ArrayList<Person> persons = new ArrayList<Person>();
- public ArrayList<Person> getPersoner() {
- return persons;
- }
- public void setPersons(ArrayList<Person> newPersons) {
- persons = newPersons;
- }
- public void addPerson(Person newPerson) {
- persons.add(newPerson);
- }
- public Person findPerson(String pNbr) {
- for (Person p : this.persons) {
- if (p.getPNbr().equals(pNbr)) {
- return p;
- }
- }
- return null;
- }
- public Person removePerson(String pNbr) {
- Person p = findPerson(pNbr);
- if (p != null) {
- persons.remove(p);
- }
- return null;
- }
- }
Add Comment
Please, Sign In to add comment