java - Making an array of SIZE = 10 employee objects -


this question has answer here:

is there guide me in right direction on how create array of these employees? array set constant size=10; here employee class , driver array tried. also, aware of output blank (employee name, id, etc) know how write far have not. "1" in class name "employee 1" there because had file saved under employee. new java can tell. thank you

   class employee1{    //variables  private  string name;  private double grosspay;     // constructor of class employee    public employee1(string empname)    {       name = empname;    }     //calculates gross pay , returns      public double weeklypay(double hoursworked, double hourlyrate)     {        double timeandhalf = (hourlyrate/2.0)+hourlyrate;      double dblovthours;      double dblovtpay;      double reghours;      double ovthours;      if (hoursworked <= 40)          {         grosspay = hoursworked*hourlyrate;         }          else if (hoursworked > 40 && hoursworked <= 60)         {         ovthours = hoursworked-40;          reghours = 40;         grosspay = (ovthours*timeandhalf) + (reghours*hourlyrate);         }          else if (hoursworked > 60)         {          ovthours = 20;           reghours = 40;          dblovthours = hoursworked - 60;          dblovtpay = hourlyrate * 2;          grosspay = (dblovtpay*dblovthours) + (timeandhalf * ovthours)       +(reghours * hourlyrate);         }             return grosspay;     }/////////////////////////////////////////////////       /* print employee details */    public string tostring()    {        return "employee report\n" + "name :" + "\nid number :"  + "\nhours worked" + "\nhourly rate : " +"\ngross pay: " + grosspay ;    }  } 

my driver class:

import java.util.scanner; public class employeedriver{  public static void main(string args[]){     // invoking methods each object created   final double hourlyratef = 10.25;   double hoursworkedf, wpay;    double grosspayf = 0.0;    scanner input = new scanner(system.in);    system.out.print("please enter number of hours work: ");    hoursworkedf = input.nextdouble();    //array not work //    employee1 emp = new employee1();   emp[0] = new employee ();     /* invoke weeklypay() method */   grosspayf=  emp.weeklypay(hoursworkedf,hourlyratef);    // invoke printemployee() method   system.out.println (emp.tostring());    } } 

what doing creating single object, not array. array this:

final int size = 10; employee1[] emp = new employee1[size]; 

then each member of array have instantiated this:

emp[0] = new employee1(); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -