Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.ArrayList;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JDialog;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
- import java.awt.Container;
- import java.awt.Font;
- import java.awt.GridLayout;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- public class Porownanie extends JPanel implements ActionListener {
- private int p;
- private String odset = null;
- ArrayList<Double> ListaOprocentowania = new ArrayList<Double>();
- double proc;
- JDialog dialog = new JDialog();
- JLabel pusty = new JLabel();
- JLabel pusty1= new JLabel();
- JLabel pusty2 = new JLabel();
- JLabel pusty3 = new JLabel();
- JLabel pusty4 = new JLabel();
- JLabel pusty5 = new JLabel();
- JLabel pusty6 = new JLabel();
- JLabel pusty7 = new JLabel();
- JFrame frame = new JFrame();
- JLabel tekst = new JLabel("Wybierz lokate: ");
- JLabel wprowadzKwote = new JLabel("Wprowadź kwotę:");
- static JTextField JTFwprowadzKwote1 = new JTextField();
- double dbZmienna;
- JButton oblicz = new JButton("Oblicz");
- JButton oblicz2 = new JButton("Oblicz2");
- JButton oblicz3 = new JButton("Oblicz3");
- JButton oblicz4 = new JButton("Oblicz4");
- JButton oblicz5 = new JButton("Oblicz5");
- JLabel odst = new JLabel("Odsetki:");
- public static JTextField odsetki = new JTextField();
- public static JTextField odsetki2 = new JTextField();
- public static JTextField odsetki3 = new JTextField();
- public static JTextField odsetki4 = new JTextField();
- public static JTextField odsetki5 = new JTextField();
- JLabel stanKonta = new JLabel("Na koniec:");
- public static JTextArea stanKonta1 = new JTextArea();
- public static JTextArea stanKonta2 = new JTextArea();
- public static JTextArea stanKonta3 = new JTextArea();
- public static JTextArea stanKonta4 = new JTextArea();
- public static JTextArea stanKonta5 = new JTextArea();
- JButton wybieram1 = new JButton("Wybieram lokate banku numer 1");
- JButton wybieram2 = new JButton("Wybieram lokate banku numer 2");
- JButton wybieram3 = new JButton("Wybieram lokate banku numer 3");
- JButton wybieram4 = new JButton("Wybieram lokate banku numer 4");
- JButton wybieram5 = new JButton("Wybieram lokate banku numer 5");
- JLabel coDoPlikuZapisane = new JLabel();
- JLabel wpisz = new JLabel("Wprowadź kwotę: ");
- JLabel koniec = new JLabel("Stan konta na koniec lokaty: ");
- public Porownanie() {
- try {
- BufferedReader br = new BufferedReader(new FileReader(
- "bin/BazaOfertBankowOprocentowanie.txt"));
- String linia = null;
- while ((linia = br.readLine()) != null) {
- proc = Double.parseDouble(linia);
- ListaOprocentowania.add(proc);
- }
- } catch (Exception e1) {
- System.err.println("Wystapil blad przy wczytywaniu danych"+e1);
- e1.printStackTrace();
- }
- oblicz.addActionListener(this); oblicz2.addActionListener(this);oblicz3.addActionListener(this);oblicz4.addActionListener(this);oblicz5.addActionListener(this);
- wybieram1.addActionListener(this);
- wybieram2.addActionListener(this);
- wybieram3.addActionListener(this);
- wybieram4.addActionListener(this);
- wybieram5.addActionListener(this);
- // dodane wierszami (6 w linii), puste są po to zeby ładnie wyglądało
- add(wprowadzKwote); add(JTFwprowadzKwote1);add(pusty1);add(pusty2);add(pusty3);
- add(pusty4);add(pusty5);add(oblicz);add(oblicz2);add(oblicz3);add(oblicz4);add(oblicz5);
- add(odst);add(odsetki);add(odsetki2);add(odsetki3);add(odsetki4);add(odsetki5);
- add(stanKonta); add(stanKonta1);add(stanKonta2);add(stanKonta3);add(stanKonta4);add(stanKonta5);
- add(pusty);add(wybieram1);add(wybieram2);add(wybieram3);add(wybieram4);add(wybieram5);
- add(coDoPlikuZapisane);
- Dimension preferredSize = getPreferredSize();
- preferredSize.height = 50;
- preferredSize.width = 140;
- wprowadzKwote.setPreferredSize(preferredSize);
- JTFwprowadzKwote1.setPreferredSize(preferredSize);
- oblicz.setPreferredSize(preferredSize);
- oblicz2.setPreferredSize(preferredSize);
- oblicz3.setPreferredSize(preferredSize);
- oblicz4.setPreferredSize(preferredSize);
- oblicz5.setPreferredSize(preferredSize);
- pusty1.setPreferredSize(preferredSize);
- pusty2.setPreferredSize(preferredSize);
- pusty3.setPreferredSize(preferredSize);
- pusty4.setPreferredSize(preferredSize);
- pusty5.setPreferredSize(preferredSize);
- odst.setPreferredSize(preferredSize);
- odsetki.setPreferredSize(preferredSize);
- odsetki2.setPreferredSize(preferredSize);
- odsetki3.setPreferredSize(preferredSize);
- odsetki4.setPreferredSize(preferredSize);
- odsetki5.setPreferredSize(preferredSize);
- stanKonta.setPreferredSize(preferredSize);
- stanKonta1.setPreferredSize(preferredSize);
- stanKonta2.setPreferredSize(preferredSize);
- stanKonta3.setPreferredSize(preferredSize);
- stanKonta4.setPreferredSize(preferredSize);
- stanKonta5.setPreferredSize(preferredSize);
- pusty.setPreferredSize(preferredSize);
- wybieram1.setSize(200, 50);
- wybieram2.setSize(200, 50);
- wybieram3.setSize(200, 50);
- wybieram4.setSize(200, 50);
- wybieram5.setSize(200, 50);
- }
- public void actionPerformed(ActionEvent e) {
- Double ods = (double) 0;
- Double k = (double) 0;
- Double i=(double) 0;
- String numStr = JTFwprowadzKwote1.getText();
- int num = Integer.parseInt(numStr);
- String n;
- String kwotaPoczatkowa;
- if (e.getSource() == oblicz) {
- while(true)
- {
- if(numStr==null)
- break; // if you press cancel it will exit
- try {
- num=Integer.parseInt(numStr);
- break;
- } catch(NumberFormatException ex)
- {
- JOptionPane.showMessageDialog(frame, "Podałeś złą wartość w polu 'Wprowadź kwotę'");
- }
- }
- stanKonta1.setText("");
- kwotaPoczatkowa =JTFwprowadzKwote1.getText();
- p = Integer.parseInt(kwotaPoczatkowa);
- i= (double) (ListaOprocentowania.get(1)/ ListaOprocentowania.get(0)); //ListaOprocentowania.get(1) to 0.05
- k = (double) (p*(1 + ListaOprocentowania.get(0)* i)) ; //ListaOprocentowania.get(0) to 3 lata
- n = Double.toString(k);
- stanKonta1.append(n);
- ods = (Double) (p * ListaOprocentowania.get(1));
- dbZmienna=Math.round(ods*100)/100;
- odset =Double.toString(dbZmienna);
- odsetki.setText(odset);
- } else if (e.getSource() == oblicz2) {
- stanKonta2.setText("");
- kwotaPoczatkowa = JTFwprowadzKwote1.getText();
- p = Integer.parseInt(kwotaPoczatkowa);
- i= (double) (ListaOprocentowania.get(2));
- double z = (double) (p*(1+i));
- double k2=(double) (z*(1+i));
- k=(double) (k2*(1+i));
- dbZmienna=Math.round(k*100)/100;
- n = Double.toString(dbZmienna);
- stanKonta2.append(n);
- double zmienna111 = (double) (dbZmienna-p);
- //dbZmienna = (double) (p*0.02);
- odset =Double.toString(zmienna111);
- odsetki2.setText(odset);
- } else if (e.getSource() == oblicz3) {
- stanKonta3.setText("");
- kwotaPoczatkowa = JTFwprowadzKwote1.getText();
- p = Integer.parseInt(kwotaPoczatkowa);
- double opro1 = (double) (p + p * ListaOprocentowania.get(3));
- double opro2 = (double) (opro1 + opro1 * ListaOprocentowania.get(4));
- double opro3 = (double) (opro2 + opro2 * ListaOprocentowania.get(5));
- double opro4 = (double) (opro3 + opro3 * ListaOprocentowania.get(6));
- double opro5 = (double) (opro4 + opro4 * ListaOprocentowania.get(7));
- //double opro6 = (double) (opro5 + opro5 * ListaOprocentowania.get(8));
- k = (double) (opro5 + opro5 * ListaOprocentowania.get(8));
- dbZmienna=Math.round(k*100)/100;
- n = Double.toString(dbZmienna);
- stanKonta3.append(n);
- double zmienna2 = (double) dbZmienna-p;
- //dbZmienna = (double)k-p;
- odset =Double.toString(zmienna2);
- odsetki3.setText(odset);
- }else if (e.getSource() == oblicz4) {
- stanKonta4.setText("");
- kwotaPoczatkowa = JTFwprowadzKwote1.getText();
- p = Integer.parseInt(kwotaPoczatkowa);
- if (p <= ListaOprocentowania.get(10)) {
- double oproc1 = (double) (p + p * ListaOprocentowania.get(11));
- k = (double) (oproc1 + oproc1 * ListaOprocentowania.get(11));
- } else {
- double oproc2 = (double) (p + p * ListaOprocentowania.get(12));
- k = (double) (oproc2 + oproc2 * ListaOprocentowania.get(12));
- }
- dbZmienna = Math.round(k*100)/100;
- n = Double.toString(dbZmienna);
- stanKonta4.append(n);
- double kw = (double) dbZmienna-p;
- odset = Double.toString(kw);
- odsetki4.setText(odset);
- }else if (e.getSource() == oblicz5) {
- stanKonta5.setText("");
- kwotaPoczatkowa = JTFwprowadzKwote1.getText();
- p = Integer.parseInt(kwotaPoczatkowa);
- double kwotaK = p;
- for (int a = 1; a <= ListaOprocentowania.get(0)*12; a++) { //ListaOprocentowania.get(0)*12 zamiana lat na miesiące
- kwotaK = (double) (kwotaK + kwotaK * ListaOprocentowania.get(13));
- }
- k=kwotaK;
- dbZmienna = Math.round(k*100)/100;
- n = Double.toString(dbZmienna);
- stanKonta5.append(n);
- ods = (double) (dbZmienna-p);
- odset =Double.toString(ods);
- odsetki5.setText(odset);
- }
- if (e.getSource() == wybieram1) {
- FileWriter plik = null;
- try {
- plik = new FileWriter(
- "bin/NajlepszaLokata.txt");
- BufferedWriter bwrt = new BufferedWriter(plik);
- bwrt.write("Wpłacona kwota: " + p);
- bwrt.newLine();
- bwrt.newLine();
- bwrt.write("Wybrana lokata: Lokata numer 1");
- bwrt.close();
- } catch (IOException e1) {
- e1.printStackTrace();
- } finally {
- if (plik != null) {
- try {
- plik.close();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- }
- }
- coDoPlikuZapisane.setText("Wybrana lokata została zapisana do pliku.");
- } else if (e.getSource() == wybieram2) {
- FileWriter plik = null;
- try {
- plik = new FileWriter( "bin/NajlepszaLokata2.txt" );
- BufferedWriter bwrt = new BufferedWriter(plik);
- bwrt.write("Wpłacona kwota: " + p);
- bwrt.newLine();
- bwrt.newLine();
- bwrt.write("Wybrana lokata: Lokata numer 2");
- bwrt.close();
- } catch (IOException e1) {
- e1.printStackTrace();
- } finally {
- if (plik != null) {
- try {
- plik.close();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- }
- }
- coDoPlikuZapisane.setText("Wybrana lokata została zapisana do pliku.");
- }else if (e.getSource() == wybieram3) {
- FileWriter plik = null;
- try {
- plik = new FileWriter(
- "bin/NajlepszaLokata3.txt");
- BufferedWriter bwrt = new BufferedWriter(plik);
- bwrt.write("Wpłacona kwota: " + p);
- bwrt.newLine();
- bwrt.newLine();
- bwrt.write("Wybrana lokata: Lokata numer 3");
- bwrt.close();
- } catch (IOException e1) {
- e1.printStackTrace();
- } finally {
- if (plik != null) {
- try {
- plik.close();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- }
- }
- coDoPlikuZapisane.setText("Wybrana lokata została zapisana do pliku.");
- }else if (e.getSource() == wybieram4) {
- FileWriter plik = null;
- try {
- plik = new FileWriter(
- "bin/NajlepszaLokata4.txt" );
- BufferedWriter bwrt = new BufferedWriter(plik);
- bwrt.write("Wpłacona kwota: " + p+", odestki w tej lokacie wynoszą: "+ odset);
- bwrt.newLine();
- bwrt.write("Saldo konta na koniec lokaty: " + p+odset);
- bwrt.newLine();
- bwrt.write("Wybrana lokata: Lokata numer 4");
- bwrt.close();
- } catch (IOException e1) {
- e1.printStackTrace();
- } finally {
- if (plik != null) {
- try {
- plik.close();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- }
- }
- coDoPlikuZapisane.setText("Wybrana lokata została zapisana do pliku.");
- }else if (e.getSource() == wybieram5) {
- FileWriter plik = null;
- try {
- plik = new FileWriter(
- "bin/NajlepszaLokata5.txt");
- BufferedWriter bwrt = new BufferedWriter(plik);
- bwrt.write("Wpłacona kwota: " + p);
- bwrt.newLine();
- bwrt.newLine();
- bwrt.write("Wybrana lokata: Lokata numer 5 ");
- bwrt.close();
- } catch (IOException e1) {
- e1.printStackTrace();
- } finally {
- if (plik != null) {
- try {
- plik.close();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- }
- }
- coDoPlikuZapisane.setText("Wybrana lokata została zapisana do pliku.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement