Advertisement
cynthiarez

UDM (Unfinished)

Oct 1st, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. package arnel;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.io.FileReader;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7. import java.io.PrintWriter;
  8. import java.util.Scanner;
  9.  
  10. import javax.swing.JOptionPane;
  11.  
  12. public class JavaLab {
  13.  
  14. public static void main(String[] args) throws IOException {
  15.  
  16. PrintWriter outfile = new PrintWriter ("studsavings.txt");
  17.  
  18. double fsav1 = 0, fsav2 = 0, fsav3 = 0, average = 0;
  19. String fcourse=""; String fname;
  20. String name = JOptionPane.showInputDialog(null, "Enter your name ");
  21. welcome(name);
  22.  
  23. do {
  24.  
  25. rec_savings();
  26. }
  27.  
  28. while (JOptionPane.showConfirmDialog(null, "Input more entries?")==0);
  29.  
  30. Scanner infile = new Scanner (new FileReader("studsavings.txt"));
  31. infile.useDelimiter(":");
  32. PrintWriter studout = new PrintWriter ("studout.txt");
  33.  
  34. while (infile.hasNext()){
  35. fname = infile.next();
  36. fcourse = infile.next();
  37. fsav1 = infile.nextDouble();
  38. fsav2 = infile.nextDouble();
  39. fsav3 = infile.nextDouble();
  40.  
  41. infile.nextLine();
  42. average = cal_avg_savings(fsav1,fsav2,fsav3);
  43.  
  44. if (det_if_enuf(fcourse,average) == true){
  45.  
  46. outfile.println(fname+fcourse+":"+average);
  47. }
  48.  
  49. else if (det_if_enuf(fcourse,average) == false ) {
  50.  
  51. outfile.println(fname+":"+fcourse+":"+average+"SAVE PA MORE!");
  52. }
  53. }
  54. infile.close();
  55. outfile.close();
  56.  
  57.  
  58.  
  59.  
  60. }
  61.  
  62. public static void welcome (String name)
  63. {
  64.  
  65. JOptionPane.showMessageDialog(null, "Welcome " + name );
  66.  
  67. }
  68.  
  69. public static void rec_savings () throws IOException
  70. {
  71. PrintWriter outfile = new PrintWriter (new FileWriter("studsavings.txt", true));
  72. double sav1, sav2 ,sav3;
  73.  
  74. String name = JOptionPane.showInputDialog("Enter full name");
  75. String course = JOptionPane.showInputDialog("Enter course");
  76. sav1 = Integer.parseInt(JOptionPane.showInputDialog("Enter savings for first day"));
  77. sav2 = Integer.parseInt(JOptionPane.showInputDialog("Enter savings for second day"));
  78. sav3 = Integer.parseInt(JOptionPane.showInputDialog("Enter savings for third day"));
  79.  
  80. outfile.println(name+":"+course+":"+sav1+":"+sav2+":"+sav3);
  81. outfile.close();
  82.  
  83.  
  84. }
  85.  
  86. public static double cal_avg_savings (double x, double y , double z){
  87.  
  88. double average = (x+y+z/3);
  89.  
  90. return average;
  91. }
  92.  
  93. public static boolean det_if_enuf (String course, double avg){
  94.  
  95. if (course.equalsIgnoreCase("CCE") && (avg<=50))
  96.  
  97. return false;
  98.  
  99. else if (course.equalsIgnoreCase("CCE") && (avg > 50))
  100. return true;
  101.  
  102. else if (course.equalsIgnoreCase("HRM") && (avg <= 20))
  103. return false;
  104.  
  105. else if (course.equalsIgnoreCase("HRM") && (avg > 20))
  106. return true;
  107.  
  108. return true;
  109. }
  110.  
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement