SHARE
TWEET

Untitled

a guest Oct 21st, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import java.io.IOException;
  4. import java.nio.file.Files;
  5. import java.nio.file.Paths;
  6. import java.nio.file.StandardOpenOption;
  7. import java.util.NoSuchElementException;
  8. import java.util.Scanner;
  9.  
  10. public class Main
  11. {
  12.  
  13.     private Scanner input;
  14.  
  15.     public static void main(String[] args)
  16.     {
  17.         developerInfo();
  18.         Main myObject = new Main();
  19.  
  20.         myObject.openFile();
  21.         myObject.readRecords();
  22.  
  23.     }
  24.  
  25.  
  26.     public void openFile()
  27.     {
  28.         try
  29.         {
  30.             input = new Scanner(Paths.get("Program6.txt"));
  31.         }
  32.         catch (IOException ioException)
  33.         {
  34.             System.err.println("Error opening file. Terminating.");
  35.             System.exit(1);
  36.         }
  37.     }
  38.  
  39.  
  40.     // Read records from the file
  41.     private void readRecords()
  42.     {
  43.         try
  44.         {
  45.             while (input.hasNext()) // while there is more to read
  46.             {
  47.                 double currentPay = input.nextDouble();
  48.                 double payWithRaise = calculateRaise(currentPay);
  49.                 // display record contents
  50.                 System.out.printf("%10.2f%n", input.nextDouble());
  51.             }
  52.         }
  53.         catch (NoSuchElementException elementException)
  54.         {
  55.             System.err.println("File improperly formed. Terminating.");
  56.         }
  57.         catch (IllegalStateException stateException)
  58.         {
  59.             System.err.println("Error reading from file. Terminating.");
  60.         }
  61.     }
  62.  
  63.     private double calculateRaise(double currentPay)
  64.     {
  65.         // receives pay rates and calculates which raise is necessary then assigns that rate to payWithRaise
  66.         double payWithRaise = 0.00;
  67.         if (currentPay > 70000)
  68.             payWithRaise = currentPay + (currentPay * .04);
  69.         else if (currentPay > 50000)
  70.             payWithRaise = currentPay + (currentPay * .07);
  71.         else
  72.             payWithRaise = currentPay + (currentPay * 5.5);
  73.  
  74.         //System.out.println (currentPay);
  75.         return payWithRaise;
  76.     }
  77.  
  78.     public void recordWriter(double payWithRaise) throws IOException {
  79.        //System.out.println (payWithRaise);
  80.         //Files.write(Paths.get("./Program6-out.txt"), payWithRaise.getBytes;
  81.         //Files.write(Paths.get("./Program6-out.txt"), payWithRaise.getBytes);
  82.         //Files.write("Program6-out.txt"), Double.toString(payWithRaise), StandardOpenOption.APPEND);
  83.         Files.write(Paths.get("Program6-out.txt"),("%10.2f%n", Double.toString(payWithRaise).getBytes(), StandardOpenOption.APPEND);
  84.     }
  85.  
  86.     public static void developerInfo()
  87.     {
  88.         System.out.println ("Name:    Jon Elliott");
  89.         System.out.println ("Course:  ITSE 2321 Object-Oriented Programming");
  90.         System.out.println ("Program: Four \n");
  91.  
  92.     } // End of developerInfo
  93.  
  94. }
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