diff --git a/.project b/.project index ceb4c39..6d1d6e8 100644 --- a/.project +++ b/.project @@ -1,6 +1,6 @@ - 210Project-2021 + 210Project-2021-Julie diff --git a/checkLogin.txt b/checkLogin.txt new file mode 100644 index 0000000..38ba80d --- /dev/null +++ b/checkLogin.txt @@ -0,0 +1,6 @@ +User1111 +Password1111 +User2222 +Password2222 +User3333 +Password3333 \ No newline at end of file diff --git a/src/Currency.java b/src/Currency.java index c5b6c8b..318825d 100644 --- a/src/Currency.java +++ b/src/Currency.java @@ -1,6 +1,20 @@ public class Currency { - public double rate; - public String name; + private double rate = 0; + private String name = ""; + + public String getCurrency() { + return "Rate: " + this.rate + ", Name: " + this.name; + } + public double getRate() { + return this.rate; + } + public String getName() { + return this.name; + } + public Currency(double rate, String name) { + this.rate = rate; + this.name = name; + } } diff --git a/src/EWalletApp.java b/src/EWalletApp.java index d6106ce..3fe403b 100644 --- a/src/EWalletApp.java +++ b/src/EWalletApp.java @@ -1,8 +1,69 @@ +/**This class is used for all GUI components, the login, and the main screen(list of options user can choose from). + * @author SENG 210 - Joseph Castro, Julie Chambers, Cameron Basham + */ +import java.util.Scanner; import java.util.ArrayList; +import javax.swing.JFrame; +import javax.swing.JTextField; + + + +/*Teacher notes: + * this is the app class, has the GUI and create one object of your expense + * calculator class. The expense calculator class is the implementation of the Expenser interface + */ public class EWalletApp { - //this is the app class, has the GUI and create one object of your expense calculator class. The expense calculator class is the implementation of the Expenser interface - private ArrayList AllData; + + private static ArrayList AllData = new ArrayList(); + public void CreateUser(String username, String password) {} + public static User u = new User(); + public static ExpenseCalculator brain = new ExpenseCalculator(u); + + + public static void main(String[] args) { + System.out.println("Login"); + LoginFrame lFrame = new LoginFrame(brain); + + /*String name = ""; + Scanner scnr = new Scanner(System.in); + name = scnr.next(); + + for (User u : AllData) { + if (u.username.equals(name)) { + brain.userAtHand = u; + } + } + + if (brain.userAtHand == null) { + User u1 = new User(); + u1.username = name; + AllData.add(u1); + brain.userAtHand = u1; + + } + //add eve3nt handler + Expense e1 = new Expense(); + + System.out.println("enter the source"); + //e1.source = scnr.next(); + + System.out.println("enter amount"); + //e1.amount = scnr.nextDouble(); + + System.out.println("yearly frequency"); + //e1.yearlyFrequency = scnr.nextInt(); + + //adding expense + brain.addExpense(e1); + brain.userAtHand.printExpenses(); + + //adding monthly income + //brain.addMonthlyIncome(null); + } + */ + +} } diff --git a/src/Expense.java b/src/Expense.java index c386160..cae32b9 100644 --- a/src/Expense.java +++ b/src/Expense.java @@ -1,7 +1,119 @@ +/**This class allows a user to enter an expense, its source, and designate how often the cost occurs(options include monthly,biweekly or yearly) + * + * @author SENG 210 - Joseph Castro, Julie Chambers, Cameron Basham + * + */ +import java.util.Scanner; public class Expense { - String source; - double amount; - int yearlyfrequency; //1 for 1 time or once a year, 12 for monthly or or 24 for biweekly + String source; + double amount; + int yearlyFrequency; //1 for 1 time or once a year, 12 for monthly or or 24 for biweekly + + boolean foundDigit = false; + boolean foundUpperCase = false; + boolean foundLowerCase = false; + boolean foundSymbol = false; + boolean foundLength = false; + public boolean foundMonthly = false; + public boolean foundYearly = false; + public boolean foundBiweekly = false; + + + //should add contructor(s) -} + + //setters + public void setAmount(double amount){ + /*README for (int i = 0; i <= amount; ++i) { + if (amount.isDigit()) { + foundDigit = true; + + } + }*/ + this.amount = amount; + } + public void setSource(String source) { + for (int i = 0; i < source.length(); ++i) { + + //checks if lowercase letters are present + if (source.charAt(i) >= 'a' && source.charAt(i) <= 'z') { + foundLowerCase = true; + } + + //checks if uppercase letters present + else if (source.charAt(i) >= 'A' && source.charAt(i) <= 'Z') { + foundUpperCase = true; + } + + //checks if there are any digits present + else if (Character.isDigit(source.charAt(i))) { + foundDigit = true; + } + + //verifies that the input is letters only + else if (foundLowerCase || foundUpperCase || foundDigit) { + this.source = source; + } + + else { + System.out.println("Source can only contain numbers, uppercase letters, or lowercase letters"); + } + } + + + + + + + + } + public void setYearlyFrequency(int yearlyFrequency) { + + //checking for monthly + if (yearlyFrequency == 12) { + foundMonthly = true; + } + + //checking for yearly + else if (yearlyFrequency == 1) { + foundYearly = true; + } + + //checking for biweekly + else if (yearlyFrequency == 24) { + foundBiweekly = true; + } + + //checking to make sure only 1, 12, or 24 is entered + else if (foundMonthly || foundYearly || foundBiweekly) { + this.yearlyFrequency = yearlyFrequency; + } + else { + System.out.println("You can only enter the numbers 1, 12, or 24 for your expense occurance."); + } + + } + + //getters + public double getAmount() { + return amount; + } + public String getSource() { + return source; + } + public int getYearlyFrequency() { + return yearlyFrequency; + } + + + + public void printExpense() { + System.out.println(amount +"--"+ source + "--" + yearlyFrequency); + } + + public String toString() { + return "Source: " + source + "Amount: " + amount + "Yearly Frequency: " + yearlyFrequency; + } + +} \ No newline at end of file diff --git a/src/ExpenseCalculator.java b/src/ExpenseCalculator.java new file mode 100644 index 0000000..120743b --- /dev/null +++ b/src/ExpenseCalculator.java @@ -0,0 +1,142 @@ + +/** + * This class is used to implement the Expenser interface + * @author SENG 210 - Joseph Castro, Julie Chambers, Cameron Basham + * + */ + + +public class ExpenseCalculator implements Expenser{ + + + public ExpenseCalculator (User u) { + userAtHand = u; + + } + + + public User userAtHand; + + + + @Override + public void addExpense(Expense Ex) { + userAtHand.Spending.add(Ex); + + } + + @Override + public void addMonthlyIncome(Wage W) { + userAtHand.Income.add(W); + // TODO Auto-generated method stub + + } + + @Override + public void PrintFullreport() { + + PrintExpensereport(); + PrintIncomereport(); + + + // TODO Auto-generated method stub + + } + + @Override + public void PrintExpensereport() { + System.out.println(userAtHand.Spending); + // TODO Auto-generated method stub + + } + + @Override + public void PrintIncomereport() { + System.out.println(userAtHand.Income); + // TODO Auto-generated method stub + + } + + @Override + public void PrintIncomereportbyTpe() { + // TODO Auto-generated method stub + + } + + @Override + public void PrintExpensebyType() { + // TODO Auto-generated method stub + + } + + @Override + public void exportReport(String reportTitle) { + // TODO Auto-generated method stub + + } + + @Override + public double convertForeignCurrency(String Currency_Name, double amount) { + for (Currency c : userAtHand.currencyRates) { + if (c.getName().equals(Currency_Name)) { + return amount * c.getRate(); + } + } + + // TODO Auto-generated method stub + return -1; + // return a error message exception + } + + public double convertForeignCurrency(String Currency_Name) { + return convertForeignCurrency (Currency_Name, userAtHand.balance); + //return null; + } + + @Override + public boolean loadExpenseFile(String filePath) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean loadIncomeFile(String filePath) { + // TODO Auto-generated method stub + return false; + } + + @Override + public int whenCanIBuy(String itemname, double price) { + updateMonthlySavings(); + int numberOfMonths = (int) (price / userAtHand.getSavings());; + return numberOfMonths; + } + + @Override + public void updateMonthlySavings() { + double totalMonthlyExpenses = 0; + for(Expense i : userAtHand.Spending) { + if (i.foundMonthly) { + totalMonthlyExpenses += i.getAmount(); + } + if (i.foundBiweekly) { + totalMonthlyExpenses += i.getAmount() * 2; + } + } + double totalMonthlyIncome = 0; + double totalIncome = 0; + + for(Wage i : userAtHand.Income) { + totalIncome += i.amount; + } + totalMonthlyIncome = totalIncome / 12; + + double finalSavings = totalMonthlyIncome - totalMonthlyExpenses; + userAtHand.setSavings(finalSavings); + + } + +} + + + diff --git a/src/Expenser.java b/src/Expenser.java index 115e8a0..6b4dec2 100644 --- a/src/Expenser.java +++ b/src/Expenser.java @@ -1,36 +1,42 @@ +/**This class is the interface that stores the methods and variables needed to complete the software. + * @author SENG 210 - Joseph Castro, Julie Chambers, Cameron Basham + */ import java.util.ArrayList; public interface Expenser { + + public User userAtHand= null; - // As a user I'd like to add a monthly expense so I can track and report my expenses - 3pts - public void addExpense (Expense Ex); - // As a user I'd like to add a monthly income so I can track and report my income all year - 3pts - public void addMonthlyIncome (Wage W); - //As a user I would like to view a detailed report of all expenses, income, and summary information - //summary information include : total income, total income for each type, total income for each month, total expense, total expense for each type, - //total savings (total income- total expenses) to date, if the total savings are less than zero it should be reported as total new debt. - public void PrintFullreport(); - //As a user I would like to view a detailed report of all expenses, and summary information for expenses - public void PrintExpensereport(); - //As a user I would like to view a detailed report of all income, and summary information for income - public void PrintIncomereport(); - //As a user I would like to view a detailed report of income of a certain type, and summary information for income - public void PrintIncomereportbyTpe(); - //As a user I would like to view a detailed report of expense of a certain type , and summary information for expenses - public void PrintExpensebyType(); - // As a user I would like to choose a report and export it as an external file (any type is fine preferences are csv or JSON) - public void exportReport(String reportTitle); - // As a user I would like to view my current balance in a different currency - //Bonus : try to use the same convert function to convert from foreign currency to USD - public Currency convertForeignCurrency(Currency C, double amount); - // As a user I would like to load multiple expenses from an external file all at once returning true if loaded successfully and false otherwise - public boolean loadExpenseFile(String filePath); - // As a user I would like to load multiple income from an external file all at once returning true if loaded successfully and false otherwise - public boolean loadIncomeFile(String filePath); - // As a user I would like to provide an item and a price and get an estimate in number of months needed to save up to buy this item. (based on current monthly saving. - public int whenCanIBuy(String itemname,double price); - // updates monthly savings based on latest added income and expenses. This is an internal function not called by the users. Bonus: what is the most efficient way to call it (when?)? - public void updateMonthlySavings(); + + + + public void addExpense (Expense Ex); // As a user I'd like to add a monthly expense so I can track and report my expenses - 3pts + + public void addMonthlyIncome (Wage W); // As a user I'd like to add a monthly income so I can track and report my income all year - 3pts + + public void PrintFullreport(); //As a user I would like to view a detailed report of all expenses, income, and summary information summary information include : total income, total income for each type, total income for each month, total expense, total expense for each type, total savings (total income- total expenses) to date, if the total savings are less than zero it should be reported as total new debt. + + public void PrintExpensereport(); //As a user I would like to view a detailed report of all expenses, and summary information for expenses + + public void PrintIncomereport(); //As a user I would like to view a detailed report of all income, and summary information for income + + public void PrintIncomereportbyTpe(); //As a user I would like to view a detailed report of income of a certain type, and summary information for income + + public void PrintExpensebyType(); //As a user I would like to view a detailed report of expense of a certain type , and summary information for expenses + + public void exportReport(String reportTitle); // As a user I would like to choose a report and export it as an external file (any type is fine preferences are csv or JSON) + + //public Currency convertForeignCurrency(Currency C, double amount); //As a user I would like to view my current balance in a different currency Bonus : try to use the same convert function to convert from foreign currency to USD + + public boolean loadExpenseFile(String filePath); //As a user I would like to load multiple expenses from an external file all at once returning true if loaded successfully and false otherwise + + public boolean loadIncomeFile(String filePath); // As a user I would like to load multiple income from an external file all at once returning true if loaded successfully and false otherwise + + public int whenCanIBuy(String itemname,double price);// As a user I would like to provide an item and a price and get an estimate in number of months needed to save up to buy this item. (based on current monthly saving. + + public void updateMonthlySavings(); // updates monthly savings based on latest added income and expenses. This is an internal function not called by the users. Bonus: what is the most efficient way to call it (when?)? + + double convertForeignCurrency(String Currency_Name, double amount); } diff --git a/src/LoginFrame.java b/src/LoginFrame.java new file mode 100644 index 0000000..6a5edaa --- /dev/null +++ b/src/LoginFrame.java @@ -0,0 +1,272 @@ +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.text.NumberFormat; +import java.util.Scanner; + +import javax.swing.JButton; +import javax.swing.JFormattedTextField; +import javax.swing.JFrame; +import javax.swing.JTextField; +import javax.swing.JLabel; +import javax.swing.JOptionPane; + +import java.awt.Insets; +import java.awt.GridLayout; +import java.awt.BorderLayout; +import javax.swing.BoxLayout; +import javax.swing.JRadioButton; +import javax.swing.JPanel; +import javax.swing.SwingConstants; +import javax.swing.LayoutStyle.ComponentPlacement; + +import javax.swing.JFrame; + +public class LoginFrame extends JFrame implements ActionListener { + ExpenseCalculator brain; + // initialize GUI components + JButton nextButton; + + // initialize variables + private String userName; + private String password; + private JTextField userNameField; + private JTextField passwordField; + // initialize GUI components + //JButton nextButton; + + + // boolean variables + boolean foundDigit = false; + boolean foundUpperCase = false; + boolean foundLowerCase = false; + boolean foundSymbol = false; + boolean foundLength = false; + + // getters + public String getUserName() { + return userName; + } + + public String getPassword() { + return password; + } + + public JTextField getUserNameField() { + return userNameField; + } + + public JTextField getPasswordField() { + return passwordField; + } + + // setters + public void setUserName(String userName) { + this.userName = userName; + } + + public void setPassword(String password) { + this.password = password; + } + + public void setUserNameField(JTextField userNameField) { + this.userNameField = userNameField; + + } + + public void setPasswordField(JTextField passwordField) { + this.passwordField = passwordField; + } + + public LoginFrame(ExpenseCalculator brain) { + this.brain=brain; + // create JFrame window + setTitle("Bank app"); + this.setSize(420, 360); + + // mainPanel + JPanel mainPanel = new JPanel(); + GridBagLayout gbl_mainPanel = new GridBagLayout(); + gbl_mainPanel.columnWidths = new int[] { 93, 50, 104, 56, 0 }; + gbl_mainPanel.rowHeights = new int[] { 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + gbl_mainPanel.columnWeights = new double[] { 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE }; + gbl_mainPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + Double.MIN_VALUE }; + mainPanel.setLayout(gbl_mainPanel); + getContentPane().add(mainPanel); + + // welcomeLabel + JLabel welcomeLabel = new JLabel("Welcome to Bank App!"); + welcomeLabel.setHorizontalAlignment(SwingConstants.TRAILING); + GridBagConstraints gbc_welcomeLabel = new GridBagConstraints(); + gbc_welcomeLabel.gridwidth = 2; + gbc_welcomeLabel.insets = new Insets(0, 0, 5, 5); + gbc_welcomeLabel.gridx = 1; + gbc_welcomeLabel.gridy = 1; + mainPanel.add(welcomeLabel, gbc_welcomeLabel); + + // userNameLabel + JLabel userNameLabel = new JLabel("Username:"); + GridBagConstraints gbc_userNameLabel = new GridBagConstraints(); + gbc_userNameLabel.anchor = GridBagConstraints.EAST; + gbc_userNameLabel.insets = new Insets(0, 0, 5, 5); + gbc_userNameLabel.gridx = 1; + gbc_userNameLabel.gridy = 3; + mainPanel.add(userNameLabel, gbc_userNameLabel); + + // userNameField + userNameField = new JTextField(); + GridBagConstraints gbc_userNameField = new GridBagConstraints(); + gbc_userNameField.insets = new Insets(0, 0, 5, 5); + gbc_userNameField.fill = GridBagConstraints.HORIZONTAL; + gbc_userNameField.gridx = 2; + gbc_userNameField.gridy = 3; + mainPanel.add(userNameField, gbc_userNameField); + userNameField.setColumns(10); + userName = userNameField.getText(); + + // passwordLabel + JLabel passwordLabel = new JLabel("Password:"); + GridBagConstraints gbc_passwordLabel = new GridBagConstraints(); + gbc_passwordLabel.anchor = GridBagConstraints.EAST; + gbc_passwordLabel.insets = new Insets(0, 0, 5, 5); + gbc_passwordLabel.gridx = 1; + gbc_passwordLabel.gridy = 4; + mainPanel.add(passwordLabel, gbc_passwordLabel); + + // passwordField + passwordField = new JTextField(); + GridBagConstraints gbc_passwordField = new GridBagConstraints(); + gbc_passwordField.insets = new Insets(0, 0, 5, 5); + gbc_passwordField.fill = GridBagConstraints.HORIZONTAL; + gbc_passwordField.gridx = 2; + gbc_passwordField.gridy = 4; + mainPanel.add(passwordField, gbc_passwordField); + passwordField.setColumns(10); + password = passwordField.getText(); + + // next button + nextButton = new JButton("Next"); + nextButton.setFocusable(false); + nextButton.addActionListener(this); + GridBagConstraints gbc_nextButton = new GridBagConstraints(); + gbc_nextButton.insets = new Insets(0, 0, 5, 5); + gbc_nextButton.gridx = 2; + gbc_nextButton.gridy = 6; + mainPanel.add(nextButton, gbc_nextButton); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.setVisible(true); + + } + + +/* @Override + public void actionPerformed(ActionEvent event) { + if(event.getSource() == nextButton) { + MenuFrame mFrame = new MenuFrame(); + userName = userNameField.getText(); + System.out.println(userName); + + password = passwordField.getText(); + System.out.println(password); + }} + public boolean Validate() throws IOException { + + // open file and starts verifying username and password against the text file + System.out.println("Opening file... "); // Opening file confidentialInfo.txt. + FileInputStream fileByteStream = new FileInputStream("checkLogin.txt"); // created a new fileInputStream + Scanner inFS = new Scanner(fileByteStream); + + System.out.println("Verifying your username and password."); + while (inFS.hasNext()) { + String verifyUsername = inFS.next(); + String verifyPassword = inFS.next(); + if (userName.equals(verifyUsername) && password.equals(verifyPassword)) { + + JOptionPane.showMessageDialog(this, "login success!"); + return true; + } + + } + // only when we are out of the loop, we are sure un/pwd not found + JOptionPane.showMessageDialog(this, "Username or password not found!"); + System.out.println("Username not found"); + // close checkLogin.txt file + System.out.println("Closing program..."); + fileByteStream.close(); + return false; + } + } + + } + */ + public boolean Validate() throws IOException { + + //open file and starts verifying username and password against the text file + System.out.println("Opening file... "); //Opening file confidentialInfo.txt. + FileInputStream fileByteStream = new FileInputStream("checkLogin.txt"); //created a new fileInputStream + Scanner inFS = new Scanner(fileByteStream); + + + System.out.println("Verifying your username and password."); + while (inFS.hasNext()) { + String verifyUsername = inFS.next(); + String verifyPassword = inFS.next(); + if (userName.equals(verifyUsername) && password.equals(verifyPassword)){ + + JOptionPane.showMessageDialog(this,"login Success!"); + return true; + } + + } + //only when we are out of the loop, we are sure un/pwd not found + JOptionPane.showMessageDialog(this,"Username or password not found!"); + System.out.println("Username not found"); + //close checkLogin.txt file + System.out.println("Closing program..."); + fileByteStream.close(); + return false; + } + + + @Override + public void actionPerformed(ActionEvent event) { + + userName = userNameField.getText(); + System.out.println(userName); + + password = passwordField.getText(); + System.out.println(password); + try { + if (Validate()) { + //String sucessLogin = null; + //sucessLogin = JOptionPane.showInputDialog(this,"Success1!."); + //TODOs login success message box + + // run the menuframe + //create object of the second frame and hide this frame + JOptionPane.showMessageDialog(this,"login Success!"); + new MenuFrame(brain).setVisible(true); + this.setVisible(false); + + //equivalent to --> MenuFrame mFrame = new MenuFrame(); + } + else { + String failLogin = null; + failLogin = JOptionPane.showInputDialog(failLogin,"Failed login. Try again."); + System.out.println(" failed login try again"); + } + } catch (IOException e) { + System.out.println(" login file exception"); + e.printStackTrace(); + } + } +} + + diff --git a/src/MenuFrame.java b/src/MenuFrame.java new file mode 100644 index 0000000..b901721 --- /dev/null +++ b/src/MenuFrame.java @@ -0,0 +1,159 @@ +import java.awt.GridBagLayout; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JLabel; +import javax.swing.JOptionPane; + +import java.awt.GridBagConstraints; +import java.awt.Insets; +import java.awt.BorderLayout; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import java.awt.Color; +import javax.swing.UIManager; + +public class MenuFrame extends JFrame implements ActionListener { + //initialize GUI components + JButton ExpenseReportButton; + JButton nextButton; + JButton addIncomeButton; + JButton addExpenseButton; + JButton reportsButton; + ExpenseCalculator brain; + + public MenuFrame(ExpenseCalculator brain) { + + this.brain=brain; + // create JFrame window + setTitle("Bank app"); + this.setSize(420, 360); + GridBagLayout gridBagLayout = new GridBagLayout(); + gridBagLayout.columnWidths = new int[]{406, 0}; + gridBagLayout.rowHeights = new int[]{23, 0, 0, 0, 0, 0}; + gridBagLayout.columnWeights = new double[]{0.0, Double.MIN_VALUE}; + gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; + getContentPane().setLayout(gridBagLayout); + + //mainPanel + JPanel mainPanel = new JPanel(); + GridBagConstraints gbc_mainPanel = new GridBagConstraints(); + gbc_mainPanel.insets = new Insets(0, 0, 5, 0); + gbc_mainPanel.anchor = GridBagConstraints.NORTH; + gbc_mainPanel.fill = GridBagConstraints.HORIZONTAL; + gbc_mainPanel.gridx = 0; + gbc_mainPanel.gridy = 0; + getContentPane().add(mainPanel, gbc_mainPanel); + + //welcome label + JLabel welcomeLabel = new JLabel("Welcome!"); + mainPanel.add(welcomeLabel); + + //Report Expense Button + ExpenseReportButton = new JButton("Print Expense Report"); + ExpenseReportButton.setBackground(UIManager.getColor("Button.disabledForeground")); + ExpenseReportButton.setForeground(UIManager.getColor("CheckBox.foreground")); + ExpenseReportButton.addActionListener(this); + GridBagConstraints gbc_ExpenseReportButton = new GridBagConstraints(); + gbc_ExpenseReportButton.insets = new Insets(0, 0, 5, 0); + gbc_ExpenseReportButton.gridx = 0; + gbc_ExpenseReportButton.gridy = 5; + getContentPane().add(ExpenseReportButton, gbc_ExpenseReportButton); + + //Add income button + addIncomeButton = new JButton("Add income"); + addIncomeButton.setBackground(UIManager.getColor("Button.disabledForeground")); + addIncomeButton.setForeground(UIManager.getColor("CheckBox.foreground")); + addIncomeButton.addActionListener(this); + GridBagConstraints gbc_addIncomeButton = new GridBagConstraints(); + gbc_addIncomeButton.insets = new Insets(0, 0, 5, 0); + gbc_addIncomeButton.gridx = 0; + gbc_addIncomeButton.gridy = 2; + getContentPane().add(addIncomeButton, gbc_addIncomeButton); + + //add expense button + addExpenseButton = new JButton("Add Expense"); + addExpenseButton.setBackground(UIManager.getColor("Button.darkShadow")); + addExpenseButton.addActionListener(this); + + GridBagConstraints gbc_addExpenseButton = new GridBagConstraints(); + gbc_addExpenseButton.insets = new Insets(0, 0, 5, 0); + gbc_addExpenseButton.gridx = 0; + gbc_addExpenseButton.gridy = 3; + getContentPane().add(addExpenseButton, gbc_addExpenseButton); + + reportsButton = new JButton("Reports"); + reportsButton.setBackground(UIManager.getColor("Button.disabledForeground")); + reportsButton.setForeground(UIManager.getColor("Button.disabledForeground")); + reportsButton.addActionListener(this); + + GridBagConstraints gbc_reportsButton = new GridBagConstraints(); + gbc_reportsButton.gridx = 0; + gbc_reportsButton.gridy = 4; + getContentPane().add(reportsButton, gbc_reportsButton); + + + + //create JFrame window +// JFrame mainMenu = new JFrame(); + setTitle("Bank app--Main Menu "); + + this.setSize(420, 360); + this.setVisible(true); +} + + @Override + public void actionPerformed(ActionEvent event) { + if(event.getSource() == addIncomeButton) { + JFrame incomeFrame = new JFrame(); + String incomeName = JOptionPane.showInputDialog(incomeFrame,"Enter Income details separated by space, source, amount,month"); + + //using split to read 3 values from 1 field, alternatively add a Jframe specific to add income and have 3 fields in it to read source, amount, month. + String [] incomeResults = incomeName.split(" "); + + Wage w= new Wage(); + w.source=incomeResults[0]; + w.amount= Double.parseDouble(incomeResults[1]); + w.month=incomeResults[2]; + + brain.addMonthlyIncome(w); + + System.out.println(incomeName); + } + if(event.getSource() == addExpenseButton) { + JFrame expenseFrame = new JFrame(); + String expenseName = JOptionPane.showInputDialog(expenseFrame,"Enter Expense details spearated by space, source, amount,yealry frequency 1 for once a year 12 for monthly"); + + String [] expenseResults = expenseName.split(" "); + + Expense e= new Expense(); + e.source=expenseResults[0]; + e.amount= Double.parseDouble(expenseResults[1]); + e.yearlyFrequency=Integer.parseInt(expenseResults[2]); + + + brain.addExpense(e); + + System.out.println(expenseName); + + } + if(event.getSource() == reportsButton) { + + //TODO add code to print all expenses or income etc etc in PrintFullreport + brain.PrintFullreport(); + } + + if(event.getSource() == ExpenseReportButton) { + brain.PrintExpensereport(); + } + + } + + //create JFrame window + //setTitle("Bank app--Main Menu "); + //this.setSize(420, 360); + + // mainPanel +// JPanel mainPanel = new JPanel(); +} diff --git a/src/User.java b/src/User.java index 8327a21..f5b4a6f 100644 --- a/src/User.java +++ b/src/User.java @@ -1,15 +1,61 @@ import java.util.ArrayList; public class User { - private ArrayList currencyRates; - private ArrayList Income; // user income sources that user can record or view or search by type or month - private ArrayList Spending; //user's expenses + public ArrayList currencyRates = new ArrayList(); + + + // Current Rates as of 6/68/2021 + private double Euro_rate = 0.84; + private double BritishPound_rate = 0.72; + private double IndianRupee_rate = 0.74; + private double AustralianDollar_rate = 1.32; + private double CanadianDollar_rate = 1.23; + + Currency Dollars = new Currency(1.0, "Dollars"); + Currency Euros = new Currency(Euro_rate, "Euros"); + Currency Pounds = new Currency(BritishPound_rate, "Pounds"); + Currency Rupees = new Currency(IndianRupee_rate, "Rupees"); + Currency AU_Dollars = new Currency(AustralianDollar_rate, "Australian Dollars"); + Currency CA_Dollars = new Currency(CanadianDollar_rate, "Canadian Dollars"); + + + public ArrayList Income = new ArrayList(); // user income sources that user can record or view or search by type or month + public ArrayList Spending = new ArrayList(); //user's expenses + + private double updatedsavings; + String username; String pwd; + //current total income - total double balance; // possible monthly savings, calculated using monthly income (most recent) assuming the data we have is for one year, and monthly and biweekly expenses, here you can assume yearly expenses that are recorded have already been paid. double monthlysavings; //should add constructor(s) + public User() { + currencyRates.add(Dollars); + currencyRates.add(Euros); + currencyRates.add(Pounds); + currencyRates.add(Rupees); + currencyRates.add(AU_Dollars); + currencyRates.add(CA_Dollars); + //add other Currency + this.updatedsavings = 0; + } + public void setSavings(double updatedsavings) { + this.updatedsavings = monthlysavings; + } + public double getSavings() { + return updatedsavings; + } + public void printExpenses() { + System.out.println(this.monthlysavings + " saved this month!"); + + for (Expense e : Spending) { + System.out.print(e); + } + } + + User(String username,String password){} } diff --git a/src/Wage.java b/src/Wage.java index 777f173..2d2779a 100644 --- a/src/Wage.java +++ b/src/Wage.java @@ -2,7 +2,43 @@ public class Wage { String source; double amount; - String Month; + String month; + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } + + public double getAmount() { + return amount; + } + + public void setAmount(double amount) { + this.amount = amount; + } + + public String getMonth() { + return month; + } + + public void setMonth(String month) { + this.month = month; + } + + public Wage(String source, double amount, String month) { + super(); + this.source = source; + this.amount = amount; + this.month = month; + } + + public Wage() { + super(); + // TODO Auto-generated constructor stub + } + - //should add contructor(s) }