SHARE
TWEET

Untitled

a guest Feb 20th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ca.prog1400;
  2.  
  3. import javax.swing.*;
  4. import java.util.ArrayList;
  5.  
  6.  
  7. public class Main {
  8.  
  9.     public static void main(String[] args) {
  10.  
  11.         boolean finish = true;
  12.         ArrayList<Student> students = new ArrayList<>();
  13.         ArrayList<Staff> staff = new ArrayList<>();
  14.  
  15.         do {
  16.             Object[] myOptions = {"Student", "Staff", "Finish"};
  17.             int result = JOptionPane.showOptionDialog(
  18.                     null,
  19.                     "Select Student or Staff.",
  20.                     "Accounting App",
  21.                     JOptionPane.DEFAULT_OPTION,
  22.                     JOptionPane.QUESTION_MESSAGE,
  23.                     null,
  24.                     myOptions, //student, staff, finish
  25.                     myOptions[0]
  26.             );
  27.  
  28.             if (result == 0) {
  29.                 String studentYear = JOptionPane.showInputDialog(
  30.                         "Enter a Student year (1-4)");
  31.                 String studentName = JOptionPane.showInputDialog(
  32.                         "Enter Student name");
  33.                 String studentAddress = JOptionPane.showInputDialog(
  34.                         "Enter student address");
  35.                 int yearOfStudy = Integer.parseInt((studentYear));
  36.  
  37.                 students.add(new Student(studentName, studentAddress, yearOfStudy));
  38.  
  39.  
  40.             } else if (result == 1) {
  41.                 String staffName = JOptionPane.showInputDialog(
  42.                         "Enter staff name");
  43.                 String staffAddress = JOptionPane.showInputDialog(
  44.                         "Enter staff address");
  45.                 String staffYear = JOptionPane.showInputDialog(
  46.                         "Enter years of service");
  47.                 int yearsOfService = Integer.parseInt((staffYear));
  48.                 staff.add(new Staff(staffName, staffAddress, yearsOfService));
  49.             } else {
  50.  
  51.                 finish = false;
  52.  
  53.             }
  54.         }
  55.         while (finish == true);
  56.  
  57.         String report = "";
  58.         double studentFee = 0;
  59.         double totalSalary = 0;
  60.  
  61.         //i have al values pushed into the array so now i need to work on the result
  62.         for (Student currentStudent: students) {
  63.             report += currentStudent.toString() + "/n";
  64.             studentFee += currentStudent.incomingFees();
  65.  
  66.  
  67.         }
  68.         for (Staff currentStaff :staff) {
  69.             report += currentStaff.toString() + "/n";
  70.             totalSalary += currentStaff.outgoingFees();
  71.  
  72.         }
  73.         double totalFee = studentFee + totalSalary;
  74.  
  75.         report += "\n\n\nResults:" +
  76.                 String.format("\nOutgoing: $%.2f", studentFee) +
  77.                 String.format("\nIncoming: $%.2f", totalSalary) +
  78.                 String.format("\nTotal: $%.2f", totalFee);
  79.  
  80.  
  81.         JOptionPane.showMessageDialog(null, report,
  82.                 "Message",
  83.                 JOptionPane.INFORMATION_MESSAGE);
  84.     }
  85. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top