SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 1 Day Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 29 Nov 2017 My Price 10.00

bufferreader can read the file in MainClass?

Here is my assignment. All I have left to do is in the main class have the bufferreader read the txt file. However, I do not know how to get the buffer to read it. Can you review my code so the bufferreader can read the file in MainClass?

  • /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package cmis242project1;

    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;

    /**
     *
     * @author tracyjenkins
     */
    public class Employee {
        String name;
        int salary;

        public Employee(String name, int salary) {
            this.name = name;
            this.salary = salary;
        }
       
        public int annualSalary()
        {
            return salary*12;
        }
       
        @Override
        public String toString()
        {
            return "Name : "+name+"  Salary : "+salary;
        }
    }
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package cmis242project1;

    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;

    /**
     *
     * @author tracyjenkins
     */
    /**The data from the executive class extends to the employee class listed above
     */
    public class Executive extends Employee{
        int stockPrice;

        public Executive(int stockPrice, String name, int salary) {
            super(name, salary);
            this.stockPrice = stockPrice;
        }
       

        @Override
        public int annualSalary()
        {
            int bonus=0;
            if(stockPrice>50)
            {
                bonus=30000;
            }
            return (12*salary+bonus);
        }/*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package cmis242project1;

    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;


    /**
     *
     * @author tracyjenkins
     */
    class MainClass {
        public static void main(String[] args) throws FileNotFoundException {
            BufferedReader file =new BufferedReader(new FileReader("data.txt"));
            Employee year14[]=new Employee[10];
            Employee year15[]=new Employee[10];
            int year14index=0,year15index=0;
            while(file.ready())
            {
                String detail=file.readLine();
                String yearS=detail.substring(0,4);
                detail=detail.substring(5,detail.length());
                int year=Integer.parseInt(yearS);
                String className=detail.substring(0,detail.indexOf(" "));
                detail=detail.substring(detail.indexOf(" ")+1,detail.length());
                String name=detail.substring(0,detail.indexOf(" "));
                detail=detail.substring(detail.indexOf(" ")+1,detail.length());
                if(className.equalsIgnoreCase("Employee"))
                {
                    int salary=Integer.parseInt(detail);
                    Employee e=new Employee(name, salary);
                    if(year==2014)
                    {
                        year14[year14index++]=e;
                    }
                    if(year==2015)
                    {
                        year15[year15index++]=e;
                    }
                }
                if(className.equalsIgnoreCase("Salesman"))
                {
                    int salary=Integer.parseInt(detail.substring(0,detail.indexOf(" ")));
                    detail=detail.substring(detail.indexOf(" ")+1,detail.length());  
                    int annualSale=Integer.parseInt(detail);
                    Salesman s=new Salesman(annualSale, name, salary);
                    if(year==2014)
                    {
                        year14[year14index++]=s;
                    }
                    if(year==2015)
                    {
                        year15[year15index++]=s;
                    }
                }
                if(className.equalsIgnoreCase("Executive"))
                {
                    int salary=Integer.parseInt(detail.substring(0,detail.indexOf(" ")));
                    detail=detail.substring(detail.indexOf(" ")+1,detail.length());  
                    int stockPrice=Integer.parseInt(detail);
                    Executive ex=new Executive(stockPrice, name, salary);
                    if(year==2014)
                    {
                        year14[year14index++]=ex;
                    }
                    if(year==2015)
                    {
                        year15[year15index++]=ex;
                    }
                }
            }
            System.out.println("Record for Year 2014");
            for(int i=0;i<year14index;i++)
            {
                System.out.print(year14[i]);
                System.out.println("  Annual Salary : "+year14[i].annualSalary());
            }
            System.out.println("\nRecord for Year 2015");
            for(int i=0;i<year15index;i++)
            {
                System.out.print(year15[i]);
                System.out.println("  Annual Salary : "+year15[i].annualSalary());
            }
            int totalSalary=0;
            for(int i=0;i<year14index;i++)
            {
                totalSalary+=year14[i].annualSalary();
            }
            System.out.println("\nAverage Salary For Year 2014 is : "+(totalSalary/year14index));
            totalSalary=0;
            for(int i=0;i<year15index;i++)
            {
                totalSalary+=year15[i].annualSalary();
            }
            System.out.println("\nAverage Salary For Year 2015 is : "+(totalSalary/year15index));
    }
    }
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package cmis242project1;

    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;

    /**
     *
     * @author tracyjenkins
     */
    /**The data from the salesman extends the employee class.
     */
    public class Salesman extends Employee{
     
        int annualSale;

        public Salesman(int annualSale, String name, int salary) {
            super(name, salary);
            this.annualSale = annualSale;
        }
       
        @Override
        public int annualSalary()
        {
            int commision=annualSale*2/100;
            if(commision>20000)
            {
                commision=20000;
            }
            return (salary*12+commision);
        }
       
        @Override
        public String toString()
        {
            return "Name : "+name+" Salary : "+salary+" Annual Sale : "+annualSale;
        }
       
    }


Attachments:

Answers

(5)
Status NEW Posted 29 Nov 2017 12:11 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)