Problem JAVA Why does my program seem perfect but when it ru

Problem (JAVA): Why does my program seem perfect but when it runs the program prints nothing that it should from the driver? Included is the output, instructions, and all of my code.

// DRIVER.java

import java.io.File;
import java.util.Scanner;

public class Driver {
  
   @SuppressWarnings(\"null\")
   public static void main(String[] args) {
      
           Employee employees = null;

           Scanner scanner = null;
         
           try {
             
             
             
               Employee[] employees2014 = new Employee[10];
               Employee[] employees2015 = new Employee[10];
             
               int empCount14 = 0;
               int empCount15 = 0;

               int year;
               scanner = new Scanner(new File(\"employee.txt\"));
               while (scanner.hasNext()) {
                   String line = scanner.nextLine();
                   String lineArr[] = line.split(\" \");
                   year = Integer.parseInt(lineArr[0]);
                   if (year == 2014) {
                     
                       if (lineArr[1].equals(\"Employee\")) {
                           employees2014[empCount14++] = new Employee(
                                   lineArr[2],
                                   Double.parseDouble(lineArr[3]),
                                   ((Employee)employees).getAnnualSalary()
                                   );
                       }
                     
                       else if (lineArr[1].equals(\"Salesman\")) {
                           employees2014[empCount14++] = new Salesman(
                                   lineArr[2],
                                   Double.parseDouble(lineArr[3]),
                                   Double.parseDouble(lineArr[4]),
                                   (Double) null
                                   );
                       }
                     
                       else {
                           employees2014[empCount14++] = new Executive(
                                   lineArr[2],
                                   Double.parseDouble(lineArr[3]),
                                   ((Employee)employees).getAnnualSalary(),
                                   (Double) null,
                                   Double.parseDouble(lineArr[4])
                                   );

                       }

                   }
                 
                   else {
                     
                       if (lineArr[1].equals(\"Employee\")) {
                           employees2015[empCount15++] = new Employee(
                                   lineArr[2],
                                   Double.parseDouble(lineArr[3]),
                                   ((Employee)employees).getAnnualSalary()
                                   );
                       }
                     
                       else if (lineArr[1].equals(\"Salesman\")) {
                           employees2015[empCount15++] = new Salesman(
                                   lineArr[2],
                                   Double.parseDouble(lineArr[3]),
                                   Double.parseDouble(lineArr[4]),
                                   (Double) null
                                   );
                       }
                     
                       else {
                           employees2015[empCount15++] = new Executive(
                                   lineArr[2],
                                   Double.parseDouble(lineArr[3]),
                                   ((Employee)employees).getAnnualSalary(),
                                   (Double) null,
                                   Double.parseDouble(lineArr[4])
                                   );
                       }

                   }
                   // System.out.println(line);

               }

               System.out.println(\"2014 Employee Report:\");

               for (int i = 0; i < empCount14; i++) {

                   System.out.println(employees2014[i]);

               }

               System.out.println(\"2015 Employee Report:\");

               for (int i = 0; i < empCount15; i++) {
                   System.out.println(employees2015[i]);
               }
           } catch (Exception e) {
               // TODO: handle exception
           } finally {


           }
       }
  

}//END

// EMPLOYEE.java

public class Employee {
  
   protected double annualSalary = 0;
   private double monthlySalary = 0;
   private String nameEmp = null;
  
   Salesman salesmen;
   Executive executives;
  
  
   public Employee(String nameEmp, double monthlySalary, double annualSalary) {
       this.nameEmp = nameEmp;
       this.annualSalary = annualSalary;
       this.monthlySalary = monthlySalary;
   }

   public void setName(String nameEmp) {
       this.nameEmp = nameEmp;
   }
  
   public void setSalary(double monthlySalary) {
       this.monthlySalary = monthlySalary;
   }
  
   public void setAnnualSalary(double annualSalary) {
       this.annualSalary = annualSalary;
   }
  
   public String getName() {
       return this.nameEmp;
   }
  
   public double getMonthlySalary() {
       return this.monthlySalary;
   }
  
   public double getAnnualSalary() {
       return this.annualSalary;
   }
  
   public double getAnnualSalary(double salary) {
       this.annualSalary = monthlySalary * 12;
       return this.annualSalary;
   }
  
   public String toString() {
       String str = \"Name of Employee: \" + this.nameEmp +\" \ Monthly Salary of Employee: \"+ this.monthlySalary;
       return str;
   }

}//END

// EXECUTIVE.java

public class Executive extends Employee{
  
   private double bonus = 0;
   private double stockPrice = 0;
  
  
   Executive(String nameEmp, double monthlySalary, double annualSalary, double bonus, double stockPrice) {
       super(nameEmp, annualSalary, monthlySalary);
       this.stockPrice = stockPrice;
       this.bonus = bonus;  
   }
  
   public void setStockPrice(double stockPrice) {
       this.stockPrice = stockPrice;
   }
  
   public void setBonusEx(double bonus) {
       this.bonus = bonus;
   }
  
   public double getStockPrice() {
       return stockPrice;
   }
  
   public double getBonusEx() {
       return this.bonus;
   }
  
   public double getAnnualSalaryEx(double monthlySalary) {
       if(stockPrice > 50) {
           bonus = 30000;
          }
       this.annualSalary = (monthlySalary * 12) + bonus ;
       return this.annualSalary;
   }
  
   public String toString(String nameEmp, double monthlySalary, double annualSalary) {
       String str = \"Name of Employee: \" + nameEmp +\" \ Monthly Salary of Employee: \" + monthlySalary +
               \"\ Company Stock Price: \" + stockPrice;
       return str;
        }

}//End

// SALESMAN.java

public class Salesman extends Employee{
  

   private double commission = 0;

  
   Salesman(String nameEmp, double monthlySalary, double annualSalary, double commission) {
       super(nameEmp, annualSalary, monthlySalary);
       this.commission = commission;
   }

   public void setCommission(double commission) {
       this.commission = commission;
   }
  
   public double getCommission() {
       return this.commission;
   }
  
   public double getAnnualSalarySa(double monthlySalary) {
       if(commission>=1000000) {
           commission = 1000000;
          }
       this.annualSalary = (monthlySalary * 12) + (commission * 0.02) ;
       return this.annualSalary;
   }
  
   public String toString(String nameEmp, double monthlySalary, double annualSalary) {
       String str = \"Name of Employee: \" + nameEmp +\" \ Monthly Salary of Employee: \" + monthlySalary +
               \"\ Annual Salary of Employee: \" + annualSalary;
       return str;
       }

}

Solution

You are sending parameter during run time through command prompt but in program the file might not contain any thing so the outputis nothing

Problem (JAVA): Why does my program seem perfect but when it runs the program prints nothing that it should from the driver? Included is the output, instruction
Problem (JAVA): Why does my program seem perfect but when it runs the program prints nothing that it should from the driver? Included is the output, instruction
Problem (JAVA): Why does my program seem perfect but when it runs the program prints nothing that it should from the driver? Included is the output, instruction
Problem (JAVA): Why does my program seem perfect but when it runs the program prints nothing that it should from the driver? Included is the output, instruction
Problem (JAVA): Why does my program seem perfect but when it runs the program prints nothing that it should from the driver? Included is the output, instruction

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site