/* This program performs a yearly update on a salary file. It increments the number of years with the conpany by one and gives a raise of $100 dollars if the employee has worked with the company for more than 10 years, and $50 otherwise. The output is sent to a text file, and also shown on the screen. */ import java.util.Scanner; import java.text.DecimalFormat; import java.io.*; class SalaryUpdate { public static void main(String[] args) throws IOException { final int RAISE1 = 100; final int RAISE2 = 50; Scanner scan = new Scanner (System.in); String inputpath, outputpath; System.out.print ("Enter the pathname of the input file: "); inputpath = scan.nextLine(); System.out.print ("Enter the pathname of the output file: "); outputpath = scan.nextLine(); Scanner inputFile; inputFile = new Scanner(new File(inputpath)); PrintWriter outputFile; outputFile = new PrintWriter(new FileWriter(outputpath)); String name; double salary; int years; /* Read the first item of the first data group from the text file */ name = inputFile.nextLine(); /* The last data item in the text file is "nomore" to mark the end of the file. */ while (!(name.equals("nomore"))) { salary = inputFile.nextDouble(); years = inputFile.nextInt(); years++; if (years > 10) salary = salary + RAISE1; else salary = salary + RAISE2; /* Save the results in the output file. */ outputFile.println (name + "\t" + salary + "\t" + years); /* Show results on the screen. */ System.out.println (name + "\t" + salary + "\t" + years); /* Read the next name from the text file. */ inputFile.nextLine(); // get to next line to read next String name = inputFile.nextLine(); } inputFile.close(); outputFile.close(); } }