Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package arnel;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.Scanner;
- import javax.swing.JOptionPane;
- public class JavaLab {
- public static void main(String[] args) throws IOException {
- PrintWriter outfile = new PrintWriter ("studsavings.txt");
- double fsav1 = 0, fsav2 = 0, fsav3 = 0, average = 0;
- String fcourse=""; String fname;
- String name = JOptionPane.showInputDialog(null, "Enter your name ");
- welcome(name);
- do {
- rec_savings();
- }
- while (JOptionPane.showConfirmDialog(null, "Input more entries?")==0);
- Scanner infile = new Scanner (new FileReader("studsavings.txt"));
- infile.useDelimiter(":");
- PrintWriter studout = new PrintWriter ("studout.txt");
- while (infile.hasNext()){
- fname = infile.next();
- fcourse = infile.next();
- fsav1 = infile.nextDouble();
- fsav2 = infile.nextDouble();
- fsav3 = infile.nextDouble();
- infile.nextLine();
- average = cal_avg_savings(fsav1,fsav2,fsav3);
- if (det_if_enuf(fcourse,average) == true){
- outfile.println(fname+fcourse+":"+average);
- }
- else if (det_if_enuf(fcourse,average) == false ) {
- outfile.println(fname+":"+fcourse+":"+average+"SAVE PA MORE!");
- }
- }
- infile.close();
- outfile.close();
- }
- public static void welcome (String name)
- {
- JOptionPane.showMessageDialog(null, "Welcome " + name );
- }
- public static void rec_savings () throws IOException
- {
- PrintWriter outfile = new PrintWriter (new FileWriter("studsavings.txt", true));
- double sav1, sav2 ,sav3;
- String name = JOptionPane.showInputDialog("Enter full name");
- String course = JOptionPane.showInputDialog("Enter course");
- sav1 = Integer.parseInt(JOptionPane.showInputDialog("Enter savings for first day"));
- sav2 = Integer.parseInt(JOptionPane.showInputDialog("Enter savings for second day"));
- sav3 = Integer.parseInt(JOptionPane.showInputDialog("Enter savings for third day"));
- outfile.println(name+":"+course+":"+sav1+":"+sav2+":"+sav3);
- outfile.close();
- }
- public static double cal_avg_savings (double x, double y , double z){
- double average = (x+y+z/3);
- return average;
- }
- public static boolean det_if_enuf (String course, double avg){
- if (course.equalsIgnoreCase("CCE") && (avg<=50))
- return false;
- else if (course.equalsIgnoreCase("CCE") && (avg > 50))
- return true;
- else if (course.equalsIgnoreCase("HRM") && (avg <= 20))
- return false;
- else if (course.equalsIgnoreCase("HRM") && (avg > 20))
- return true;
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement