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: 313 Weeks Ago, 5 Days 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 12 Jan 2018 My Price 10.00

Executive.java, and finally MainMethod.java

Could someone please review my code?  I am getting the following error: Exception in thread "main" java.lang.NumberFormatException: For input string: "��2 "

I have 4 classes plus a text file.  The EmployeeClass is the super class, followed by Salesman.java, Executive.java, and finally MainMethod.java.  Also attached is a word document with the project instructions.  Thanks in advanced.

  • /**
     * File: EmployeeClass.java
     * Purpose: Employee Class, which contains the employee's name,
     * and monthly salary (in dollars).
     */
    public class EmployeeClass {

        // Instance variables
        private String employeeName;
        private int salary;

        // Default constructor to
        // initialize name and salary
        public EmployeeClass(String employeeName, int salary) {
            this.employeeName = employeeName;
            this.salary = salary;
        }

        // annualSalary method
        public int annualSalary() {
            return salary * 12;
        }

        // toString method
        public String toString() {
            String str = "Employee Name: " + employeeName + "Monthly Salary: " + salary;
            return str;
        }

        //Added later
        public int getSalary() {
            return salary;
        }
        public String getEmployeeName() {
            return employeeName;
        }
    }
    /**
     * File: Executive.java
     * Purpose: A subclass of EmployeeClass.java
     */
    public class Executive extends EmployeeClass{

        // Instance variable
        public int stockPrice;

        // Setter method for stockPrice
        public void setStockPrice() {
            this.stockPrice = stockPrice;
        }

        // Default constructor
        public Executive(String employeeName, int salary, int stockPrice) {
            super (employeeName, salary);
        }

        // Overridden annualSalary method
        public int annualSalary() {
            int bonus = 30000;
            if (stockPrice > 50) {
                return (getSalary() * 12 + bonus);
            } else {
                return (getSalary() * 12);
            }
        }

        // Overridden toString method
        public String toString() {
            return "\tEmployee Name: " + getEmployeeName() + "\tMonthly Salary: " + getSalary() +
                    "\tStock Price: " + stockPrice;
        }
    }import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;

    /**
     * File: MainMethod.java
     * Purpose: Main method
     */
    public class MainMethod {
        public static void main(String[] args) {
            // variables


            try {
                BufferedReader file = new BufferedReader(new FileReader("employee.txt"));
                EmployeeClass year14[] = new EmployeeClass[10];
                EmployeeClass year15[] = new EmployeeClass[10];
                int year14index = 0, year15index = 0;

                while(file.ready()) {
                    String line = file.readLine();
                    String years = line.substring(0, 4);
                    int year = Integer.parseInt(years);
                    line = line.substring(5, line.length());
                    String className = line.substring(0, line.indexOf("\t"));
                    line = line.substring(line.indexOf("\t")+1, line.length());
                    String employeeName = line.substring(0, line.indexOf("\t"));
                    line = line.substring(line.indexOf("\t")+1, line.length());

                    if (className.equalsIgnoreCase("Employee")) {
                        int salary = Integer.parseInt(line.trim());
                        EmployeeClass e = new EmployeeClass(employeeName, salary);
                        if (year == 2014) {
                            year14[year14index++] = e;
                        }
                        if (year == 2015) {
                            year15[year15index++] = e;
                        }
                    }
                    if (className.equalsIgnoreCase("Salesman")) {
                        int salary = Integer.parseInt(line.substring(0, line.indexOf("\t")));
                        line = line.substring(line.indexOf("\t")+1, line.length());
                        int annualSales = Integer.parseInt(line);
                        Salesman s = new Salesman(employeeName, salary, annualSales);
                        if (year == 2014) {
                            year14[year14index++] = s;
                        }
                        if (year == 2015) {
                            year15[year15index++] = s;
                        }
                    }
                    if (className.equalsIgnoreCase("Executive")) {
                        int salary = Integer.parseInt(line.substring(0, line.indexOf("\t")));
                        line = line.substring(line.indexOf("\t")+1, line.length());
                        int stockPrice = Integer.parseInt(line);
                        Executive ex = new Executive(employeeName, salary, stockPrice);
                        if (year == 2014) {
                            year14[year14index++] = ex;
                        }
                        if (year == 2015) {
                            year15[year15index++] = ex;
                        }
                    }
                }
                // Print 2014 results
                System.out.println("2014 Employee Records");
                for (int i = 0; i < year14index; i++) {
                    System.out.print(year14[i]);
                    System.out.println("\tAnnual Salary: " + year14[i].annualSalary());
                }
                int totalSalary = 0;
                for (int i = 0; i < year14index; i++) {
                    totalSalary += year14[i].annualSalary();
                }
                System.out.println("\n2014 Average Salary: " + (totalSalary/year14index));

                // Print 2015 Results
                System.out.println("2015 Employee Records");
                for (int i = 0; i < year15index; i++) {
                    System.out.print(year15index);
                    System.out.println("\tAnnual Salary: " + year15[i].annualSalary());
                }
                totalSalary = 0;
                for (int i = 0; i < year15index; i++) {
                    totalSalary += year15[i].annualSalary();
                }
                System.out.println("\n2015 Average Salary: " + (totalSalary/year15index));
            }
            catch (IOException e) {
                System.out.println("File not found.");
            }
        }
    }/**
     * File: Salesman.java
     * Purpose: Subclass of EmployeeClass.java
     */
    public class Salesman extends EmployeeClass {

        // Instance variable
        private int annualSales;


        // Default constructor
        public Salesman(String employeeName, int salary, int annualSales) {
            super (employeeName, salary);
            this.annualSales = annualSales;
        }

        // Overridden annualSalary method
        public int annualSalary() {
            int commision = annualSales * 2/100;
            if(commision>20000) {
                commision = 20000;
            }
            return (getSalary() * 12 + commision);
        }

        // Overridden toString method
        public String toString() {
            return "\tEmployee Name: " + getEmployeeName() + "\tMonthly Salary: " + getSalary() +
                    "\tAnnual Sales: " + annualSales;
        }
    }



Attachments:

Answers

(5)
Status NEW Posted 12 Jan 2018 02:01 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)