0% found this document useful (0 votes)
46 views

Student Number: 231444416 Surname: BOTENDE Subject Code: OOP216D Campus: Soshanguve South Group: D

The document contains a student's assignment submission for an object-oriented programming course. It includes a UML class diagram, source code for a ParishDonation class, screenshots of a donation GUI, and source code for the GUI class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Student Number: 231444416 Surname: BOTENDE Subject Code: OOP216D Campus: Soshanguve South Group: D

The document contains a student's assignment submission for an object-oriented programming course. It includes a UML class diagram, source code for a ParishDonation class, screenshots of a donation GUI, and source code for the GUI class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Student Number: 231444416

Surname: BOTENDE
Subject Code: OOP216D
Campus: SOSHANGUVE SOUTH
Group: D

Part 1:
Enter your UML class diagram in the space below.

botende.mmk
-parishionerName : String
-parishAccNo : String
-amountToDonate : double
+ParishDonation()
+ParishDonation(parishionerName,parishAccNo,amountToDonate)
+setParishionerName(String) : void
+setParishAccNo(String) : void
+setAmountToDonate(double) : void
+getParishionerName() : String
+getParishAccNo() : String
+getAmountToDonate() : double
+determineTotalAmount(double) : double

Paste the source code of your concrete class in the space below:
package botende.mmk;

import java.io.Serializable;
import javax.swing.JOptionPane;

/**
*
* @author lp
*/
public class ParishDonation implements Serializable {
private String parishionerName;
private String parishAccNo;
private double amountToDonate;

public ParishDonation() {
}

public ParishDonation(String parishionerName, String parishAccNo, double amountToDonate) {


this.parishionerName = parishionerName;
this.parishAccNo = parishAccNo;
this.amountToDonate = amountToDonate;
}

public String getParishionerName() {


return parishionerName;
}

public void setParishionerName(String parishionerName) {


this.parishionerName = parishionerName;
}

public String getParishAccNo() {


return parishAccNo;
}

public void setParishAccNo(String parishAccNo) {


this.parishAccNo = parishAccNo;
}

public double getAmountToDonate() {


return amountToDonate;
}

public void setAmountToDonate(double amountToDonate) {


this.amountToDonate = amountToDonate;
}

public double determineTotalAmount(double total){


total=total+amountToDonate;

return total;
}
}

Part 2:
Make a screenshot of your GUI and paste it in the space below:

When pressing the “Enter” button : ↓↓


When pressing “Review” button : ↓↓

When pressing the “Send” button : ↓↓


When a second person makes the donation and press “enter” ; this is how all data are displayed in
the text area : ↓↓

Paste the source code of the GUI class in the space below:

package botende.mmk;
import javax.swing.JOptionPane;
import java.util.*;
import java.io.*;
/**
*
* @author lp
*/
public class DonationGUI extends javax.swing.JFrame {
ArrayList<ParishDonation> donations;
/**
* Creates new form DonationGUI
*/
public DonationGUI() {
initComponents();
donations=new ArrayList<ParishDonation>();
populateArrayList();
}
public void populateArrayList(){
try{
FileInputStream theFile=new FileInputStream("Donations.txt");
ObjectInputStream inputFile=new ObjectInputStream(theFile);

boolean endOfTheFile=false;

while(!endOfTheFile){
try{
donations.add((ParishDonation)inputFile.readObject());
}
catch(EOFException e){
endOfTheFile=true;
}
catch(Exception f){
JOptionPane.showMessageDialog(null, f.getMessage());
}
}

inputFile.close();
}
catch(IOException e){
JOptionPane.showMessageDialog(null, e.getMessage());

}
}

public void saveDonationsToFile(){

try{
FileOutputStream file= new FileOutputStream("Donations.txt");
ObjectOutputStream outputFile=new ObjectOutputStream(file);

for(int i=0;i<donations.size();i++){
outputFile.writeObject(donations.get(i));
}

outputFile.close();

JOptionPane.showMessageDialog(null,"Amount successfully sent to the parish bank


account");
this.dispose();
}
catch(IOException e){
JOptionPane.showMessageDialog(null, e.getMessage());

}
}

public void saveDonationsToFileDetails(){


try{
FileOutputStream file=new FileOutputStream("Donations.txt");
ObjectOutputStream outputFile=new ObjectOutputStream(file);

for(int i=0; i<donations.size(); i++){


outputFile.writeObject(donations.get(i));
}
JOptionPane.showMessageDialog(null, "Name: "+jTextField1.getText()+ "\n"+"Amount:
R"+jTextField2.getText()+
"\n"+"Account number: "+jTextField3.getText());
}
catch(IOException e){
JOptionPane.showMessageDialog(null, e.getMessage());
}
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jLabel1 = new javax.swing.JLabel();


jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setFont(new java.awt.Font("Segoe UI", 3, 18)); // NOI18N


jLabel1.setText("To make a donation to the parish, enter the following data :");

jLabel2.setFont(new java.awt.Font("Segoe UI Semibold", 0, 14)); // NOI18N


jLabel2.setText("Parishioner name:");

jLabel3.setFont(new java.awt.Font("Segoe UI Semibold", 0, 14)); // NOI18N


jLabel3.setText("Amount you want to donate:");

jLabel4.setFont(new java.awt.Font("Segoe UI Semibold", 0, 14)); // NOI18N


jLabel4.setText("Parish bank account number:");

jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField2ActionPerformed(evt);
}
});

jTextField3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField3ActionPerformed(evt);
}
});

jButton1.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N


jButton1.setText("Send");
jButton1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(102, 153, 255), 3,
true));
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jButton2.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N


jButton2.setText("Review");
jButton2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(102, 153, 255), 3,
true));
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jButton3.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N


jButton3.setText("Enter");
jButton3.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(51, 153, 255), 3,
true));
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());


getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 293,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 293,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 293,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(277, 277, 277))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(170, 170, 170)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGap(229, 229, 229)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 60,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 87,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 82,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 293,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(195, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(17, 17, 17)
.addComponent(jLabel1)
.addGap(42, 42, 42)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addGap(13, 13, 13)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel4)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(54, 54, 54)
.addComponent(jButton3))
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 123,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 67,
Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jButton1))
.addGap(31, 31, 31))
);

pack();
}// </editor-fold>

private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
if(jTextField1.getText().isEmpty() || jTextField2.getText().isEmpty() ||
jTextField3.getText().isEmpty()){

JOptionPane.showMessageDialog(null, "Please complete all field!");


}
else{
String name=jTextField1.getText().trim();
String amount=jTextField2.getText().trim();
String parishAccountNo=jTextField3.getText().trim();

ParishDonation donation= new


ParishDonation(name,parishAccountNo,Double.parseDouble(amount));

donations.add(donation);

saveDonationsToFile();
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
saveDonationsToFileDetails();
}

private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
String input1=jTextField1.getText();
String input2=jTextField2.getText();
String input3=jTextField3.getText();

jTextArea1.append(input1+"\n"+"R"+input2+"\n"+input3+"\n");
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(DonationGUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(DonationGUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(DonationGUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(DonationGUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new DonationGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
// End of variables declaration
}

Content of your text file used in the application:

¬í sr botende.mmk.ParishDonation°Îˆ*uç D amountToDonateL
parishAccNot Ljava/lang/String;L parishionerNameq ~ xp@•@ t 12346655t Mariesq ~ @( t
111111t mmsq ~ @•@ t 12345566t Marie

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy