Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. zad 1
  2.  
  3. class Account {
  4. final public int SAVING = 0;
  5. final public int CHEQUE = 1;
  6. final public int FIXED = 2; //Portuguese currency
  7. private int accountType;
  8. private double balance;
  9. public double getInterestRate(...) { // Some method;
  10. ...
  11. }
  12. public Account(int accountType) {
  13. this.accountType = accountType;
  14. }
  15. public double calcInterest() {
  16. switch (accountType) {
  17. case SAVING:
  18. return balance * getInterestRate();
  19. case CHEQUE:
  20. return 0;
  21. case FIXED:
  22. return balance * (getInterestRate() + 0.02);
  23. }
  24. }
  25. }
  26.  
  27. zad 2
  28.  
  29. class ParticipantsInDB {
  30. Connection conn;
  31. final String tableName = "participants";
  32. void addParticipant(Participant part) {
  33. PreparedStatement st = conn.prepareStatement("INSERT INTO " + tableName + "
  34. VALUES( ? , ? , ? , ? , ? )
  35. ");
  36. try {
  37. st.setString(1, part.getId());
  38. st.setString(2, part.getEFirstName());
  39. st.setString(3, part.getELastName());
  40. //...
  41. st.executeUpdate();
  42. } finally {
  43. st.close();
  44. }
  45. }
  46. void deleteAllParticipants() {
  47. PreparedStatement st = conn.prepareStatement("DELETE FROM " + tableName);
  48. try {
  49. st.executeUpdate();
  50. } finally {
  51. st.close();
  52. }
  53. }
  54. void deleteParticipant(String participantId) {
  55. PreparedStatement st = conn.prepareStatement("DELETE FROM " + tableName + "
  56. WHERE id = ? ");
  57. try {
  58. st.setString(1, participantId);
  59. st.executeUpdate();
  60. } finally {
  61. st.close();
  62. }
  63. }
  64. }
  65.  
  66. zad 3
  67. class Form1 extends JDialog {
  68. JComboBox comboBoxReportType;
  69. Form1() {
  70. comboBoxReportType = new JComboBox();
  71. comboBoxReportType.addItem("r1");
  72. comboBoxReportType.addItem("r2");
  73. ...
  74. comboBoxReportType.addItem("r31c");
  75. }
  76. void processReport1() {
  77. //print some fancy report...
  78. }
  79. void processReport2() {
  80. //print another totally different fancy report...
  81. }
  82. ...
  83. void processReport31c() {
  84. //print yet another totally different fancy report...
  85. }
  86. void printReport(String repNo) {
  87. if (repNo.equals("r1"))
  88. processReport1();
  89. else if (repNo.equals("r2"))
  90. processReport2();
  91. ...
  92. else if (repNo.equals("r31c"))
  93. processReport31c();
  94. }
  95. void onPrintClick() {
  96. printReport((String) comboBoxReportType.getSelectedItem());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement