Problem WinstonSalem State Universitys Office of Budget Mana
Problem: Winston-Salem State University’s Office of Budget Management has decided to review the possibility of giving its faculty raises for the 2010-2011 Academic Year. The percentage of raise each faculty member receives will be based on years of service and academic status (tenure/tenure track-1or non tenure track-2). See chart below to determine percentage raise.
Years of Service
Tenure/Tenure Track
Non-Tenure Track
25 or more
8%
4%
15-24
6%
3%
6-14
4%
2%
0-5
2%
1%
They have contracted you to prepare a report based on the information in the database (textfile) and project the cost to the University. The database (budget.txt) contains the following information:
-Name - String
-Years of Service - Integer
-Academic Status ( 1 – Tenure/Tenure-Track, 2 – Non-Tenure Track)
-Current Yearly Salary - Double
Sample Data:
Caldwell, E./25/1/117000
Secondly, they need you to prepare a report containing the following information:
1-Read and display the contents of the file.
2-Determine and display the name and percentage raise for each faculty member.
3-Compute and display the name and amount of raise each faculty member will receive.
4-Compute the new salary for each faculty member.
5-Display name, old salary, and new salary for each faculty member.
6-Display the total additional cost to the university if a raise is given for the 2010-2011 Academic Year.
here is the data file
CSUData.txt
Here is the sampleOutput
Name years of service statut Current yearly Salary
---------------------------------------------------------------------------------
Name Purcentage raise
-----------------------------------------------------------------------------------
Name Raise
----------------------------------------------------------------------------------
Name old salary new salary
--------------------------------------------------------------------------------
Total cost:
31780.0
| Years of Service | Tenure/Tenure Track | Non-Tenure Track | 
| 25 or more | 8% | 4% | 
| 15-24 | 6% | 3% | 
| 6-14 | 4% | 2% | 
| 0-5 | 2% | 1% | 
Solution
//Employee.java
 public class Employee
 {
   
    //instance variables
    private String name;
    private int years;
    private byte status;
    private double salary;
    private double percent;
   
   
    //Employee constructor
    public Employee(String name,
            int years, byte status,
            double salary)
    {
        this.name=name;
        this.years=years;
        this.status=status;
        this.salary=salary;
        percent=0;
    }
   
    public String getName(){
        return name;
    }
   
    public int getYears(){
        return years;
    }
   
    public byte getStatus(){
        return status;
    }
   
    public double getSalary(){
        return salary;
    }
   
    public void setPercent(double percent){
        this.percent=percent;
    }
   
    public double getPercent(){
        return percent;  
    }
   
   
    //Retunrs the string representation of the employee
    @Override
    public String toString() {      
        return String.format(\"%-20s%-10d%-10d%-8.2f\ \",
                name,years,status,salary);
    }
 }//end of the class Employee
--------------------------------------------------------------------------------------------------------------------
//WinstionSalemStats.java
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.util.Scanner;
 public class WinstionSalemStats {
public static void main(String[] args) {
       String fileName=\"CSUData.txt\";
        Scanner filereader=null;
        String name;
        int years;
        byte status;
        double salary;
        final int size=19;
        Employee[] emps=new Employee[size];
       try
        {
            //create an instance of Scanner class to read file
            filereader=new Scanner(new File(fileName));
            int index=0;
            //read until end of file
            while(filereader.hasNextLine())
            {
                //read data
                String line=filereader.nextLine();
                String[] parts=line.split(\"\\\\.\");
                name=parts[0];
                String part2=parts[1];
                String[] data=part2.split(\"\\\\/\");
                years=Integer.parseInt(data[1]);
                status=Byte.parseByte(data[2]);
                salary=Double.parseDouble(data[3]);
                //Create an employee object
                emps[index]=new Employee(name, years, status, salary);
                //increment index
                index++;
}
       } catch (FileNotFoundException e)
        {
            System.out.println(\"File Not Found\");
        }
       System.out.printf(\"%-20s%-10s%-10s%-8s\ \",
                \"Name\",\"Years\",\"Staus\",\"Salary\");
        System.out.println(\"--------------------------------------------------\");
         for (int i = 0; i < emps.length; i++)
        {
            System.out.print(emps[i]);
        }
       
        //set percentage of each employee based on status
        for (int i = 0; i < emps.length; i++)
        {
            if(emps[i].getStatus()==1)
            {
                if(emps[i].getYears()<=5)
                {
                    emps[i].setPercent(0.08);
                }
                else if(emps[i].getYears()>5 && emps[i].getYears()<=14)
                {
                    emps[i].setPercent(0.04);
                }
                else if(emps[i].getYears()>15 && emps[i].getYears()<=24)
                {
                    emps[i].setPercent(0.06);
                }
                if(emps[i].getYears()>=25)
                {
                    emps[i].setPercent(0.08);
                }
            }
            else
            {
                if(emps[i].getYears()<=5)
                {
                    emps[i].setPercent(0.01);
                }
                else if(emps[i].getYears()>5 && emps[i].getYears()<=14)
                {
                    emps[i].setPercent(0.02);
                }
                else if(emps[i].getYears()>15 && emps[i].getYears()<=24)
                {
                    emps[i].setPercent(0.03);
                }
                if(emps[i].getYears()>=25)
                {
                    emps[i].setPercent(0.04);
                }
            }
       }
       
        //print name and percentage raise
        System.out.printf(\"%-20s%-15s\ \",\"Name\",\"PercentRaise\");
        System.out.printf(\"--------------------------------------\ \");
         for (int i = 0; i < emps.length; i++)
        {
            System.out.printf(\"%-20s%-5.2f\ \",emps[i].getName(),
                    emps[i].getPercent());
        }
       
        double totalCost=0;
       
        System.out.printf(\"%-20s%-15s%-15s\ \",\"Name\",\"old salary\",
                \"new salary\");
        System.out.printf(\"-----------------------------------------------\ \");
         //print name old salary and new salary
        for (int i = 0; i < emps.length; i++)
        {
            double oldsalary=emps[i].getSalary();
            double newsalary=emps[i].getSalary()+emps[i].getSalary()*emps[i].getPercent();
             System.out.printf(\"%-20s%-15.2f%-15.2f\ \",emps[i].getName()
                    ,oldsalary,
                    newsalary);          
            totalCost+=(newsalary-oldsalary);          
        }
       
        //print total cost
        System.out.printf(\"Total cost : %10.2f\",totalCost);
       
    }
 }
--------------------------------------------------------------------------------------------------------------------
CSUData.txt
Caldwell,E./25/1/117000
 Matlock B./5/2/32000
 Fletcher J./17/2/64000
 Matlock, M./35/2/45000
 Bajwa, J./22/1/10000
 Flinstone, F./10/2/25000
 Rubble, B./2/1/50000
 Keaton, W./7/1/55000
 Graham, M./2/1/50000
 Barkly, J./0/2/25000
 Madison, K./12/1/40000
 Posten, F./10/1/65000
 Browne, J./15/1/40000
 Black, B./2/1/50000
 Patton, C./2/1/50000
 Lofton, C./2/1/50000
 Batton, P./6/1/37000
 Duck, D./2/2/15000
 Washington, D./5/1/80000
--------------------------------------------------------------------------------------------------------------------
Sample Output:
 Name                Years     Staus     Salary
 --------------------------------------------------
 Caldwell,E          25        1         117000.00
 Matlock B           5         2         32000.00
 Fletcher J          17        2         64000.00
 Matlock, M          35        2         45000.00
 Bajwa, J            22        1         10000.00
 Flinstone, F        10        2         25000.00
 Rubble, B           2         1         50000.00
 Keaton, W           7         1         55000.00
 Graham, M           2         1         50000.00
 Barkly, J           0         2         25000.00
 Madison, K          12        1         40000.00
 Posten, F           10        1         65000.00
 Browne, J           15        1         40000.00
 Black, B            2         1         50000.00
 Patton, C           2         1         50000.00
 Lofton, C           2         1         50000.00
 Batton, P           6         1         37000.00
 Duck, D             2         2         15000.00
 Washington, D       5         1         80000.00
 Name                PercentRaise
 --------------------------------------
 Caldwell,E          0.08
 Matlock B           0.01
 Fletcher J          0.03
 Matlock, M          0.04
 Bajwa, J            0.06
 Flinstone, F        0.02
 Rubble, B           0.08
 Keaton, W           0.04
 Graham, M           0.08
 Barkly, J           0.01
 Madison, K          0.04
 Posten, F           0.04
 Browne, J           0.00
 Black, B            0.08
 Patton, C           0.08
 Lofton, C           0.08
 Batton, P           0.04
 Duck, D             0.01
 Washington, D       0.08
 Name                old salary     new salary   
 -----------------------------------------------
 Caldwell,E          117000.00      126360.00    
 Matlock B           32000.00       32320.00     
 Fletcher J          64000.00       65920.00     
 Matlock, M          45000.00       46800.00     
 Bajwa, J            10000.00       10600.00     
 Flinstone, F        25000.00       25500.00     
 Rubble, B           50000.00       54000.00     
 Keaton, W           55000.00       57200.00     
 Graham, M           50000.00       54000.00     
 Barkly, J           25000.00       25250.00     
 Madison, K          40000.00       41600.00     
 Posten, F           65000.00       67600.00     
 Browne, J           40000.00       40000.00     
 Black, B            50000.00       54000.00     
 Patton, C           50000.00       54000.00     
 Lofton, C           50000.00       54000.00     
 Batton, P           37000.00       38480.00     
 Duck, D             15000.00       15150.00     
 Washington, D       80000.00       86400.00     
 Total cost :   49180.00







