3 Replies - 290 Views - Last Post: 15 November 2012 - 03:08 PM Rate Topic: -----

#1 bedrockhorror  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 56
  • Joined: 22-October 09

Display percentage raise

Posted 15 November 2012 - 09:46 AM

Trying to work on this assignment and I'm trying to display the percentage raise for each faculty and their name. This is what I have so far. I've attached all the files that I received.


They have contracted you to prepare a report based on the information in the database (CSUData.txt) and project the cost to the University. The database (CSUData.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

Secondly, they need you to prepare a report containing the following information:

2.Determine and display the name and percentage raise for each faculty member.


I know i have to determine first how much percentage raise each faculty member are getting by looking at how many year of services they had and their academic status. I was doing something like this:

public void getPercent(String[] name, double[] yearsc,double [] statusr, double[] yearlySalaryst)
    {
        for (int index = 0; index < sc.length; index++)
        {   System.out.println(" Faculty members and their percentage of raise ");
            if (year[index] <= 5 && status[index] == 1)
                status[index] = 2;
            if (year[index] <= 5 && status[index] == 2)
                [index] = 1;
            if (year[index] <= 14 && status[index] ==1)
                status[index] = 4;
            if (year[index] <= 14 && status[index] ==2)
                status[index] = 2;
            if (year[index] <= 24 && status[index] == 1)
                status[index] = 6;
            if (year[index] <= 24 && status[index]== 2)
                status[index] = 3;
            if (year[index] >= 25 && status[index] == 1)
                status[index] = 8;
            if (year[index] >= 25 && status[index] ==2)
                status[index] = 4;
                
            System.out.print(name[index] + ", " + r[index]+"%");
            }
        }



Assignment5.Java File

public class Assignment5
{
   private String name; 
   private double year; 
   private double status; 
   private double yearlySalary; 
   private int[] percentages=new int [19];
   
   public Assignment5 (String n, double y, double s, double ys)
   {
       name = n;
       year = y;
       status = s;
       yearlySalary = ys;
       
   }
   
   public String getName()
   {
       return name;
   }
   
   public double getYear()
   {
       return year;
   }
   
   public double getStatus()
   {
       return status;
   }
   
   public double getYearlySalary()
   {
       return yearlySalary;
   }
   
   public void setPercentage (String name)
   {
       int percentage;
       double year= getYear();
       if (year > 25)
           percentage=8;
       else if (year > 15)
           percentage=6;
       else if (year > 6)
           percentage=4;
       else 
           percentage=2;
       //percentages[name]=percentage;     
   }

   //public int getPercentage (int id)
   //{
       //return percentages[name];
   //}
    
   public String toString()
   {      
     String str = "";
     str += name + "\t  ";
     str += year + "\t      ";
     str += status + "\t\t";
     str += yearlySalary + "\t\t";
     
     return str;
   }
}



Assignment5Demo.Java

import java.util.Scanner; 
import java.util.ArrayList; 
import java.util.StringTokenizer; 
import java.io.*; 

public class Assignment5Demo
{
    public static void main(String[] args) throws IOException
    {
        String data;
        ArrayList<Assignment5> courses = new ArrayList<Assignment5>();

        //read info from a file
        File inputFile = new File("CSUData.txt");
        Scanner input = new Scanner(inputFile);
       
        while(input.hasNext())
        {
            //read first line
            data = input.nextLine();
                
            StringTokenizer token = new StringTokenizer(data,"/");
                
            //get name
            String name = token.nextToken();
            
            //get the years of service
            double year = Double.parseDouble(token.nextToken());
            
            // get the academic status
            double status = Double.parseDouble(token.nextToken());  
             
            // get the current yearly salary
            double yearlySalary = Double.parseDouble(token.nextToken());
            
            Assignment5 Temp = new Assignment5 (name, year, status, yearlySalary);
            courses.add(Temp);
            }

        input.close();
       
        //display the contents of the file
        System.out.println("*Contents of the file");
        System.out.println();
        System.out.println("  Name         Years of    Academic      Current");
        System.out.println("               Services     Status    Yearly Salary");
         
        for( int i = 0; i < courses.size(); i++)
        {
            //Display the course's
            System.out.println(courses.get(i));
        }

    }
    
}



The CSUDate.txt file that has the information

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


Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Display percentage raise

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Display percentage raise

Posted 15 November 2012 - 10:41 AM

this is a lot of if && which are really difficult to read
also I am not sure right now if year[i] = 4 you enter in the all the If <= 4 and <= 14 and...
you sure it is wat you want or rather

if(year[index] <= 4) {
    if(status[index] == 1)
      ...
    else
      ...
} else if(year[index] <= 14) {
    if(status[index] == 1)


Was This Post Helpful? 0
  • +
  • -

#3 bedrockhorror  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 56
  • Joined: 22-October 09

Re: Display percentage raise

Posted 15 November 2012 - 02:42 PM

Thanks for the reply pbl, and thanks for the suggestion. It helped and made it look better and read easier.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Display percentage raise

Posted 15 November 2012 - 03:08 PM

does it work better now that you do not go into all these if() more than once ?
If not post your updated code
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1