Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ca.prog1400;
- import javax.swing.*;
- import java.util.ArrayList;
- public class Main {
- public static void main(String[] args) {
- boolean finish = true;
- ArrayList<Student> students = new ArrayList<>();
- ArrayList<Staff> staff = new ArrayList<>();
- do {
- Object[] myOptions = {"Student", "Staff", "Finish"};
- int result = JOptionPane.showOptionDialog(
- null,
- "Select Student or Staff.",
- "Accounting App",
- JOptionPane.DEFAULT_OPTION,
- JOptionPane.QUESTION_MESSAGE,
- null,
- myOptions, //student, staff, finish
- myOptions[0]
- );
- if (result == 0) {
- String studentYear = JOptionPane.showInputDialog(
- "Enter a Student year (1-4)");
- String studentName = JOptionPane.showInputDialog(
- "Enter Student name");
- String studentAddress = JOptionPane.showInputDialog(
- "Enter student address");
- int yearOfStudy = Integer.parseInt((studentYear));
- students.add(new Student(studentName, studentAddress, yearOfStudy));
- } else if (result == 1) {
- String staffName = JOptionPane.showInputDialog(
- "Enter staff name");
- String staffAddress = JOptionPane.showInputDialog(
- "Enter staff address");
- String staffYear = JOptionPane.showInputDialog(
- "Enter years of service");
- int yearsOfService = Integer.parseInt((staffYear));
- staff.add(new Staff(staffName, staffAddress, yearsOfService));
- } else {
- finish = false;
- }
- }
- while (finish == true);
- String report = "";
- double studentFee = 0;
- double totalSalary = 0;
- //i have al values pushed into the array so now i need to work on the result
- for (Student currentStudent: students) {
- report += currentStudent.toString() + "/n";
- studentFee += currentStudent.incomingFees();
- }
- for (Staff currentStaff :staff) {
- report += currentStaff.toString() + "/n";
- totalSalary += currentStaff.outgoingFees();
- }
- double totalFee = studentFee + totalSalary;
- report += "\n\n\nResults:" +
- String.format("\nOutgoing: $%.2f", studentFee) +
- String.format("\nIncoming: $%.2f", totalSalary) +
- String.format("\nTotal: $%.2f", totalFee);
- JOptionPane.showMessageDialog(null, report,
- "Message",
- JOptionPane.INFORMATION_MESSAGE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement