Advertisement
Guest User

Untitled

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