Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.nio.file.StandardOpenOption;
- import java.util.NoSuchElementException;
- import java.util.Scanner;
- public class Main
- {
- private Scanner input;
- private double payWithRaise;
- public static void main(String[] args)
- {
- developerInfo();
- Main myObject = new Main();
- myObject.openFile();
- myObject.readRecords();
- }
- public void openFile()
- {
- try
- {
- input = new Scanner(Paths.get("Program6.txt"));
- }
- catch (IOException ioException)
- {
- System.err.println("Error opening file. Terminating.");
- System.exit(1);
- }
- }
- // Read records from the file
- public double readRecords()
- {
- try
- {
- while (input.hasNext()) // while there is more to read
- {
- // read line by
- double currentPay = input.nextDouble();
- double payWithRaise = calculateRaise(currentPay);
- // display record contents
- System.out.printf("%10.2f%n", input.nextDouble());
- return payWithRaise;
- }
- }
- catch (NoSuchElementException elementException)
- {
- System.err.println("File improperly formed. Terminating.");
- }
- catch (IllegalStateException stateException)
- {
- System.err.println("Error reading from file. Terminating.");
- }
- }
- private double calculateRaise(double currentPay)
- {
- // receives pay rates and calculates which raise is necessary then assigns that rate to payWithRaise
- double payWithRaise = 0.00;
- if (currentPay > 70000)
- payWithRaise = currentPay + (currentPay * .04);
- else if (currentPay > 50000)
- payWithRaise = currentPay + (currentPay * .07);
- else
- payWithRaise = currentPay + (currentPay * 5.5);
- //System.out.println (currentPay);
- return payWithRaise;
- }
- public void recordWriter(double payWithRaise) throws IOException {
- //System.out.println (payWithRaise);
- //Files.write(Paths.get("./Program6-out.txt"), payWithRaise.getBytes;
- //Files.write(Paths.get("./Program6-out.txt"), payWithRaise.getBytes);
- //Files.write("Program6-out.txt"), Double.toString(payWithRaise), StandardOpenOption.APPEND);
- Files.write(Paths.get("Program6-out.txt"), Double.toString(payWithRaise).getBytes(), StandardOpenOption.APPEND);
- }
- public static void developerInfo()
- {
- System.out.println ("Name: Jon Elliott");
- System.out.println ("Course: ITSE 2321 Object-Oriented Programming");
- System.out.println ("Program: Four \n");
- } // End of developerInfo
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement